OLD | NEW |
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 : NativeViewport(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: |
(...skipping 15 matching lines...) Expand all Loading... |
46 MSG msg = { hwnd(), message, w_param, l_param, 0, | 43 MSG msg = { hwnd(), message, w_param, l_param, 0, |
47 { GET_X_LPARAM(l_param), GET_Y_LPARAM(l_param) } }; | 44 { GET_X_LPARAM(l_param), GET_Y_LPARAM(l_param) } }; |
48 ui::MouseEvent event(msg); | 45 ui::MouseEvent event(msg); |
49 bool handled = delegate_->OnEvent(&event); | 46 bool handled = delegate_->OnEvent(&event); |
50 SetMsgHandled(handled); | 47 SetMsgHandled(handled); |
51 return 0; | 48 return 0; |
52 } | 49 } |
53 LRESULT OnCreate(CREATESTRUCT* create_struct) { | 50 LRESULT OnCreate(CREATESTRUCT* create_struct) { |
54 RECT cr; | 51 RECT cr; |
55 GetClientRect(hwnd(), &cr); | 52 GetClientRect(hwnd(), &cr); |
56 gpu::GLInProcessContextAttribs attribs; | 53 bounds_ = gfx::Rect(cr); |
57 gl_context_.reset(gpu::GLInProcessContext::CreateContext( | 54 widget_ = hwnd(); |
58 false, hwnd(), gfx::Size(cr.right - cr.left, cr.bottom - cr.top), | 55 OnAcceleratedWidgetAvailable(); |
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; | 56 return 0; |
65 } | 57 } |
66 void OnPaint(HDC) { | 58 void OnPaint(HDC) { |
67 RECT cr; | 59 RECT cr; |
68 GetClientRect(hwnd(), &cr); | 60 GetClientRect(hwnd(), &cr); |
69 | 61 |
70 PAINTSTRUCT ps; | 62 PAINTSTRUCT ps; |
71 HDC dc = BeginPaint(hwnd(), &ps); | 63 HDC dc = BeginPaint(hwnd(), &ps); |
72 HBRUSH red_brush = CreateSolidBrush(RGB(255, 0, 0)); | 64 HBRUSH red_brush = CreateSolidBrush(RGB(255, 0, 0)); |
73 HGDIOBJ old_object = SelectObject(dc, red_brush); | 65 HGDIOBJ old_object = SelectObject(dc, red_brush); |
74 Rectangle(dc, cr.left, cr.top, cr.right, cr.bottom); | 66 Rectangle(dc, cr.left, cr.top, cr.right, cr.bottom); |
75 SelectObject(dc, old_object); | 67 SelectObject(dc, old_object); |
76 DeleteObject(red_brush); | 68 DeleteObject(red_brush); |
77 EndPaint(hwnd(), &ps); | 69 EndPaint(hwnd(), &ps); |
78 } | 70 } |
79 void OnSize(UINT param, const CSize& size) { | 71 void OnSize(UINT param, const CSize& size) { |
80 delegate_->OnResized(gfx::Size(size.cx, size.cy)); | 72 delegate_->OnResized(gfx::Size(size.cx, size.cy)); |
81 } | 73 } |
82 void OnDestroy() { | 74 void OnDestroy() { |
83 delegate_->OnDestroyed(); | 75 delegate_->OnDestroyed(); |
84 } | 76 } |
85 | 77 |
86 void OnGLContextLost() { | |
87 gl_context_.reset(); | |
88 delegate_->OnGLContextLost(); | |
89 } | |
90 | |
91 NativeViewportDelegate* delegate_; | |
92 scoped_ptr<gpu::GLInProcessContext> gl_context_; | |
93 | |
94 DISALLOW_COPY_AND_ASSIGN(NativeViewportWin); | 78 DISALLOW_COPY_AND_ASSIGN(NativeViewportWin); |
95 }; | 79 }; |
96 | 80 |
97 // static | 81 // static |
98 scoped_ptr<NativeViewport> NativeViewport::Create( | 82 scoped_ptr<NativeViewport> NativeViewport::Create( |
99 shell::Context* context, | 83 shell::Context* context, |
100 NativeViewportDelegate* delegate) { | 84 NativeViewportDelegate* delegate) { |
101 return scoped_ptr<NativeViewport>(new NativeViewportWin(delegate)).Pass(); | 85 return scoped_ptr<NativeViewport>(new NativeViewportWin(delegate)).Pass(); |
102 } | 86 } |
103 | 87 |
104 } // namespace services | 88 } // namespace services |
105 } // namespace mojo | 89 } // namespace mojo |
OLD | NEW |