OLD | NEW |
| (Empty) |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include <windows.h> | |
6 | |
7 #include "chrome/plugin/command_buffer_stub.h" | |
8 | |
9 namespace { | |
10 const wchar_t* kPreviousWndProcProperty = L"CommandBufferStubPrevWndProc"; | |
11 const wchar_t* kCommandBufferStubProperty = L"CommandBufferStub"; | |
12 | |
13 // Message handler for the GPU plugin's child window. Used to intercept | |
14 // WM_PAINT events and forward repaint notifications to the client. | |
15 LRESULT WINAPI WndProc(HWND handle, | |
16 UINT message, | |
17 WPARAM w_param, | |
18 LPARAM l_param) { | |
19 WNDPROC previous_wnd_proc = reinterpret_cast<WNDPROC>( | |
20 ::GetProp(handle, kPreviousWndProcProperty)); | |
21 CommandBufferStub* stub = reinterpret_cast<CommandBufferStub*>( | |
22 ::GetProp(handle, kCommandBufferStubProperty)); | |
23 | |
24 switch (message) { | |
25 case WM_ERASEBKGND: | |
26 // Do not clear background. Avoids flickering. | |
27 return 1; | |
28 case WM_PAINT: | |
29 // Validate the whole window to prevent another WM_PAINT message. | |
30 ValidateRect(handle, NULL); | |
31 | |
32 // Notify client that the window is invalid and needs to be repainted. | |
33 stub->NotifyRepaint(); | |
34 | |
35 return 1; | |
36 default: | |
37 return CallWindowProc(previous_wnd_proc, | |
38 handle, | |
39 message, | |
40 w_param, | |
41 l_param); | |
42 } | |
43 } | |
44 } // namespace anonymous | |
45 | |
46 bool CommandBufferStub::InitializePlatformSpecific() { | |
47 // Subclass window. | |
48 WNDPROC previous_wnd_proc = reinterpret_cast<WNDPROC>( | |
49 ::GetWindowLongPtr(window_, GWLP_WNDPROC)); | |
50 ::SetProp(window_, | |
51 kPreviousWndProcProperty, | |
52 reinterpret_cast<HANDLE>(previous_wnd_proc)); | |
53 ::SetWindowLongPtr(window_, | |
54 GWLP_WNDPROC, | |
55 reinterpret_cast<LONG_PTR>(WndProc)); | |
56 | |
57 // Record pointer to this in window. | |
58 ::SetProp(window_, | |
59 kCommandBufferStubProperty, | |
60 reinterpret_cast<HANDLE>(this)); | |
61 | |
62 return true; | |
63 } | |
64 | |
65 void CommandBufferStub::DestroyPlatformSpecific() { | |
66 // Restore window. | |
67 WNDPROC previous_wnd_proc = reinterpret_cast<WNDPROC>( | |
68 ::GetProp(window_, kPreviousWndProcProperty)); | |
69 ::SetWindowLongPtr(window_, GWLP_WNDPROC, reinterpret_cast<LONG_PTR>( | |
70 previous_wnd_proc)); | |
71 ::RemoveProp(window_, kPreviousWndProcProperty); | |
72 ::RemoveProp(window_, kCommandBufferStubProperty); | |
73 } | |
OLD | NEW |