Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(357)

Side by Side Diff: mojo/services/native_viewport/native_viewport_win.cc

Issue 59383011: Factor common code into native_viewport_controller.cc (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix windows build Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "mojo/services/native_viewport/native_viewport.h" 5 #include "mojo/services/native_viewport/native_viewport.h"
6 6
7 #include "base/bind.h"
8 #include "gpu/command_buffer/client/gl_in_process_context.h"
9 #include "gpu/command_buffer/client/gles2_implementation.h"
10 #include "ui/events/event.h" 7 #include "ui/events/event.h"
11 #include "ui/gfx/win/window_impl.h" 8 #include "ui/gfx/win/window_impl.h"
12 9
13 namespace mojo { 10 namespace mojo {
14 namespace services { 11 namespace services {
15 12
16 class NativeViewportWin : public gfx::WindowImpl, 13 class NativeViewportWin : public gfx::WindowImpl,
17 public NativeViewport { 14 public NativeViewport {
18 public: 15 public:
19 explicit NativeViewportWin(NativeViewportDelegate* delegate) 16 explicit NativeViewportWin(NativeViewportDelegate* delegate)
20 : delegate_(delegate) { 17 : delegate_(delegate) {
21 Init(NULL, gfx::Rect(10, 10, 500, 500)); 18 Init(NULL, gfx::Rect(10, 10, 500, 500));
22 ShowWindow(hwnd(), SW_SHOWNORMAL); 19 ShowWindow(hwnd(), SW_SHOWNORMAL);
23 SetWindowText(hwnd(), L"native_viewport::NativeViewportWin!"); 20 SetWindowText(hwnd(), L"native_viewport::NativeViewportWin!");
24 } 21 }
25 virtual ~NativeViewportWin() { 22 virtual ~NativeViewportWin() {
26 if (IsWindow(hwnd())) 23 if (IsWindow(hwnd()))
27 DestroyWindow(hwnd()); 24 DestroyWindow(hwnd());
28 } 25 }
29 26
30 private: 27 private:
31 // Overridden from NativeViewport: 28 // Overridden from NativeViewport:
29 virtual gfx::Size GetSize() OVERRIDE {
30 RECT cr;
31 GetClientRect(hwnd(), &cr);
32 return gfx::Size(cr.right - cr.left, cr.bottom - cr.top);
33 }
32 virtual void Close() OVERRIDE { 34 virtual void Close() OVERRIDE {
33 DestroyWindow(hwnd()); 35 DestroyWindow(hwnd());
34 } 36 }
35 37
36 BEGIN_MSG_MAP_EX(NativeViewportWin) 38 BEGIN_MSG_MAP_EX(NativeViewportWin)
37 MESSAGE_RANGE_HANDLER_EX(WM_MOUSEFIRST, WM_MOUSELAST, OnMouseRange) 39 MESSAGE_RANGE_HANDLER_EX(WM_MOUSEFIRST, WM_MOUSELAST, OnMouseRange)
38 40
39 MSG_WM_CREATE(OnCreate) 41 MSG_WM_CREATE(OnCreate)
40 MSG_WM_PAINT(OnPaint) 42 MSG_WM_PAINT(OnPaint)
41 MSG_WM_SIZE(OnSize) 43 MSG_WM_SIZE(OnSize)
42 MSG_WM_DESTROY(OnDestroy) 44 MSG_WM_DESTROY(OnDestroy)
43 END_MSG_MAP() 45 END_MSG_MAP()
44 46
45 LRESULT OnMouseRange(UINT message, WPARAM w_param, LPARAM l_param) { 47 LRESULT OnMouseRange(UINT message, WPARAM w_param, LPARAM l_param) {
46 MSG msg = { hwnd(), message, w_param, l_param, 0, 48 MSG msg = { hwnd(), message, w_param, l_param, 0,
47 { GET_X_LPARAM(l_param), GET_Y_LPARAM(l_param) } }; 49 { GET_X_LPARAM(l_param), GET_Y_LPARAM(l_param) } };
48 ui::MouseEvent event(msg); 50 ui::MouseEvent event(msg);
49 bool handled = delegate_->OnEvent(&event); 51 bool handled = delegate_->OnEvent(&event);
50 SetMsgHandled(handled); 52 SetMsgHandled(handled);
51 return 0; 53 return 0;
52 } 54 }
53 LRESULT OnCreate(CREATESTRUCT* create_struct) { 55 LRESULT OnCreate(CREATESTRUCT* create_struct) {
54 RECT cr; 56 delegate_->OnAcceleratedWidgetAvailable(hwnd());
55 GetClientRect(hwnd(), &cr);
56 gpu::GLInProcessContextAttribs attribs;
57 gl_context_.reset(gpu::GLInProcessContext::CreateContext(
58 false, hwnd(), gfx::Size(cr.right - cr.left, cr.bottom - cr.top),
59 false, attribs, gfx::PreferDiscreteGpu));
60 gl_context_->SetContextLostCallback(base::Bind(
61 &NativeViewportWin::OnGLContextLost, base::Unretained(this)));
62
63 delegate_->OnGLContextAvailable(gl_context_->GetImplementation());
64 return 0; 57 return 0;
65 } 58 }
66 void OnPaint(HDC) { 59 void OnPaint(HDC) {
67 RECT cr; 60 RECT cr;
68 GetClientRect(hwnd(), &cr); 61 GetClientRect(hwnd(), &cr);
69 62
70 PAINTSTRUCT ps; 63 PAINTSTRUCT ps;
71 HDC dc = BeginPaint(hwnd(), &ps); 64 HDC dc = BeginPaint(hwnd(), &ps);
72 HBRUSH red_brush = CreateSolidBrush(RGB(255, 0, 0)); 65 HBRUSH red_brush = CreateSolidBrush(RGB(255, 0, 0));
73 HGDIOBJ old_object = SelectObject(dc, red_brush); 66 HGDIOBJ old_object = SelectObject(dc, red_brush);
74 Rectangle(dc, cr.left, cr.top, cr.right, cr.bottom); 67 Rectangle(dc, cr.left, cr.top, cr.right, cr.bottom);
75 SelectObject(dc, old_object); 68 SelectObject(dc, old_object);
76 DeleteObject(red_brush); 69 DeleteObject(red_brush);
77 EndPaint(hwnd(), &ps); 70 EndPaint(hwnd(), &ps);
78 } 71 }
79 void OnSize(UINT param, const CSize& size) { 72 void OnSize(UINT param, const CSize& size) {
80 delegate_->OnResized(gfx::Size(size.cx, size.cy)); 73 delegate_->OnResized(gfx::Size(size.cx, size.cy));
81 } 74 }
82 void OnDestroy() { 75 void OnDestroy() {
83 delegate_->OnDestroyed(); 76 delegate_->OnDestroyed();
84 } 77 }
85 78
86 void OnGLContextLost() {
87 gl_context_.reset();
88 delegate_->OnGLContextLost();
89 }
90
91 NativeViewportDelegate* delegate_; 79 NativeViewportDelegate* delegate_;
92 scoped_ptr<gpu::GLInProcessContext> gl_context_;
93 80
94 DISALLOW_COPY_AND_ASSIGN(NativeViewportWin); 81 DISALLOW_COPY_AND_ASSIGN(NativeViewportWin);
95 }; 82 };
96 83
97 // static 84 // static
98 scoped_ptr<NativeViewport> NativeViewport::Create( 85 scoped_ptr<NativeViewport> NativeViewport::Create(
99 shell::Context* context, 86 shell::Context* context,
100 NativeViewportDelegate* delegate) { 87 NativeViewportDelegate* delegate) {
101 return scoped_ptr<NativeViewport>(new NativeViewportWin(delegate)).Pass(); 88 return scoped_ptr<NativeViewport>(new NativeViewportWin(delegate)).Pass();
102 } 89 }
103 90
104 } // namespace services 91 } // namespace services
105 } // namespace mojo 92 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/services/native_viewport/native_viewport_stub.cc ('k') | mojo/services/native_viewport/native_viewport_x11.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698