// Copyright (c) 2010 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #include #include "chrome/plugin/command_buffer_stub.h" namespace { const wchar_t* kPreviousWndProcProperty = L"CommandBufferStubPrevWndProc"; const wchar_t* kCommandBufferStubProperty = L"CommandBufferStub"; // Message handler for the GPU plugin's child window. Used to intercept // WM_PAINT events and forward repaint notifications to the client. LRESULT WINAPI WndProc(HWND handle, UINT message, WPARAM w_param, LPARAM l_param) { WNDPROC previous_wnd_proc = reinterpret_cast( ::GetProp(handle, kPreviousWndProcProperty)); CommandBufferStub* stub = reinterpret_cast( ::GetProp(handle, kCommandBufferStubProperty)); switch (message) { case WM_ERASEBKGND: // Do not clear background. Avoids flickering. return 1; case WM_PAINT: // Validate the whole window to prevent another WM_PAINT message. ValidateRect(handle, NULL); // Notify client that the window is invalid and needs to be repainted. stub->NotifyRepaint(); return 1; default: return CallWindowProc(previous_wnd_proc, handle, message, w_param, l_param); } } } // namespace anonymous bool CommandBufferStub::InitializePlatformSpecific() { // Subclass window. WNDPROC previous_wnd_proc = reinterpret_cast( ::GetWindowLongPtr(window_, GWLP_WNDPROC)); ::SetProp(window_, kPreviousWndProcProperty, reinterpret_cast(previous_wnd_proc)); ::SetWindowLongPtr(window_, GWLP_WNDPROC, reinterpret_cast(WndProc)); // Record pointer to this in window. ::SetProp(window_, kCommandBufferStubProperty, reinterpret_cast(this)); return true; } void CommandBufferStub::DestroyPlatformSpecific() { // Restore window. WNDPROC previous_wnd_proc = reinterpret_cast( ::GetProp(window_, kPreviousWndProcProperty)); ::SetWindowLongPtr(window_, GWLP_WNDPROC, reinterpret_cast( previous_wnd_proc)); ::RemoveProp(window_, kPreviousWndProcProperty); ::RemoveProp(window_, kCommandBufferStubProperty); }