OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "content/renderer/render_widget_fullscreen_pepper.h" | 5 #include "content/renderer/render_widget_fullscreen_pepper.h" |
6 | 6 |
7 #include "base/message_loop.h" | 7 #include "base/message_loop.h" |
8 #include "content/common/view_messages.h" | 8 #include "content/common/view_messages.h" |
9 #include "content/renderer/gpu/gpu_channel_host.h" | 9 #include "content/renderer/gpu/gpu_channel_host.h" |
10 #include "content/renderer/pepper_platform_context_3d_impl.h" | 10 #include "content/renderer/pepper_platform_context_3d_impl.h" |
(...skipping 17 matching lines...) Expand all Loading... | |
28 using WebKit::WebTextDirection; | 28 using WebKit::WebTextDirection; |
29 using WebKit::WebTextInputType; | 29 using WebKit::WebTextInputType; |
30 using WebKit::WebVector; | 30 using WebKit::WebVector; |
31 using WebKit::WebWidget; | 31 using WebKit::WebWidget; |
32 | 32 |
33 namespace { | 33 namespace { |
34 | 34 |
35 // WebWidget that simply wraps the pepper plugin. | 35 // WebWidget that simply wraps the pepper plugin. |
36 class PepperWidget : public WebWidget { | 36 class PepperWidget : public WebWidget { |
37 public: | 37 public: |
38 PepperWidget(webkit::ppapi::PluginInstance* plugin, | 38 explicit PepperWidget(RenderWidgetFullscreenPepper* widget) |
39 RenderWidgetFullscreenPepper* widget) | 39 : widget_(widget) { |
40 : plugin_(plugin), | |
41 widget_(widget) { | |
42 } | 40 } |
43 | 41 |
44 virtual ~PepperWidget() {} | 42 virtual ~PepperWidget() {} |
45 | 43 |
46 // WebWidget API | 44 // WebWidget API |
47 virtual void close() { | 45 virtual void close() { |
48 delete this; | 46 delete this; |
49 } | 47 } |
50 | 48 |
51 virtual WebSize size() { | 49 virtual WebSize size() { |
52 return size_; | 50 return size_; |
53 } | 51 } |
54 | 52 |
55 virtual void willStartLiveResize() { | 53 virtual void willStartLiveResize() { |
56 } | 54 } |
57 | 55 |
58 virtual void resize(const WebSize& size) { | 56 virtual void resize(const WebSize& size) { |
57 if (!widget_->plugin()) | |
58 return; | |
59 | |
59 size_ = size; | 60 size_ = size; |
60 WebRect plugin_rect(0, 0, size_.width, size_.height); | 61 WebRect plugin_rect(0, 0, size_.width, size_.height); |
61 plugin_->ViewChanged(plugin_rect, plugin_rect); | 62 widget_->plugin()->ViewChanged(plugin_rect, plugin_rect); |
62 widget_->Invalidate(); | 63 widget_->Invalidate(); |
63 } | 64 } |
64 | 65 |
65 virtual void willEndLiveResize() { | 66 virtual void willEndLiveResize() { |
66 } | 67 } |
67 | 68 |
68 virtual void animate(double frameBeginTime) { | 69 virtual void animate(double frameBeginTime) { |
69 } | 70 } |
70 | 71 |
71 virtual void layout() { | 72 virtual void layout() { |
72 } | 73 } |
73 | 74 |
74 virtual void paint(WebCanvas* canvas, const WebRect& rect) { | 75 virtual void paint(WebCanvas* canvas, const WebRect& rect) { |
76 if (!widget_->plugin()) | |
77 return; | |
78 | |
75 WebRect plugin_rect(0, 0, size_.width, size_.height); | 79 WebRect plugin_rect(0, 0, size_.width, size_.height); |
76 plugin_->Paint(canvas, plugin_rect, rect); | 80 widget_->plugin()->Paint(canvas, plugin_rect, rect); |
77 } | 81 } |
78 | 82 |
79 virtual void composite(bool finish) { | 83 virtual void composite(bool finish) { |
84 if (!widget_->plugin()) | |
85 return; | |
86 | |
80 RendererGLContext* context = widget_->context(); | 87 RendererGLContext* context = widget_->context(); |
81 DCHECK(context); | 88 DCHECK(context); |
82 gpu::gles2::GLES2Implementation* gl = context->GetImplementation(); | 89 gpu::gles2::GLES2Implementation* gl = context->GetImplementation(); |
83 unsigned int texture = plugin_->GetBackingTextureId(); | 90 unsigned int texture = widget_->plugin()->GetBackingTextureId(); |
84 gl->BindTexture(GL_TEXTURE_2D, texture); | 91 gl->BindTexture(GL_TEXTURE_2D, texture); |
85 gl->DrawArrays(GL_TRIANGLES, 0, 3); | 92 gl->DrawArrays(GL_TRIANGLES, 0, 3); |
86 widget_->SwapBuffers(); | 93 widget_->SwapBuffers(); |
87 } | 94 } |
88 | 95 |
89 virtual void themeChanged() { | 96 virtual void themeChanged() { |
90 NOTIMPLEMENTED(); | 97 NOTIMPLEMENTED(); |
91 } | 98 } |
92 | 99 |
93 virtual bool handleInputEvent(const WebInputEvent& event) { | 100 virtual bool handleInputEvent(const WebInputEvent& event) { |
101 if (!widget_->plugin()) | |
102 return false; | |
103 | |
94 // This cursor info is ignored, we always set the cursor directly from | 104 // This cursor info is ignored, we always set the cursor directly from |
95 // RenderWidgetFullscreenPepper::DidChangeCursor. | 105 // RenderWidgetFullscreenPepper::DidChangeCursor. |
96 WebCursorInfo cursor; | 106 WebCursorInfo cursor; |
97 bool result = plugin_->HandleInputEvent(event, &cursor); | 107 bool result = widget_->plugin()->HandleInputEvent(event, &cursor); |
98 | 108 |
99 // For normal web pages, WebViewImpl does input event translations and | 109 // For normal web pages, WebViewImpl does input event translations and |
100 // generates context menu events. Since we don't have a WebView, we need to | 110 // generates context menu events. Since we don't have a WebView, we need to |
101 // do the necessary translation ourselves. | 111 // do the necessary translation ourselves. |
102 if (WebInputEvent::isMouseEventType(event.type)) { | 112 if (WebInputEvent::isMouseEventType(event.type)) { |
103 const WebMouseEvent& mouse_event = | 113 const WebMouseEvent& mouse_event = |
104 reinterpret_cast<const WebMouseEvent&>(event); | 114 reinterpret_cast<const WebMouseEvent&>(event); |
105 bool send_context_menu_event = false; | 115 bool send_context_menu_event = false; |
106 // On Mac/Linux, we handle it on mouse down. | 116 // On Mac/Linux, we handle it on mouse down. |
107 // On Windows, we handle it on mouse up. | 117 // On Windows, we handle it on mouse up. |
108 #if defined(OS_WIN) | 118 #if defined(OS_WIN) |
109 send_context_menu_event = | 119 send_context_menu_event = |
110 mouse_event.type == WebInputEvent::MouseUp && | 120 mouse_event.type == WebInputEvent::MouseUp && |
111 mouse_event.button == WebMouseEvent::ButtonRight; | 121 mouse_event.button == WebMouseEvent::ButtonRight; |
112 #elif defined(OS_MACOSX) | 122 #elif defined(OS_MACOSX) |
113 send_context_menu_event = | 123 send_context_menu_event = |
114 mouse_event.type == WebInputEvent::MouseDown && | 124 mouse_event.type == WebInputEvent::MouseDown && |
115 (mouse_event.button == WebMouseEvent::ButtonRight || | 125 (mouse_event.button == WebMouseEvent::ButtonRight || |
116 (mouse_event.button == WebMouseEvent::ButtonLeft && | 126 (mouse_event.button == WebMouseEvent::ButtonLeft && |
117 mouse_event.modifiers & WebMouseEvent::ControlKey)); | 127 mouse_event.modifiers & WebMouseEvent::ControlKey)); |
118 #else | 128 #else |
119 send_context_menu_event = | 129 send_context_menu_event = |
120 mouse_event.type == WebInputEvent::MouseDown && | 130 mouse_event.type == WebInputEvent::MouseDown && |
121 mouse_event.button == WebMouseEvent::ButtonRight; | 131 mouse_event.button == WebMouseEvent::ButtonRight; |
122 #endif | 132 #endif |
123 if (send_context_menu_event) { | 133 if (send_context_menu_event) { |
124 WebMouseEvent context_menu_event(mouse_event); | 134 WebMouseEvent context_menu_event(mouse_event); |
125 context_menu_event.type = WebInputEvent::ContextMenu; | 135 context_menu_event.type = WebInputEvent::ContextMenu; |
126 plugin_->HandleInputEvent(context_menu_event, &cursor); | 136 widget_->plugin()->HandleInputEvent(context_menu_event, &cursor); |
127 } | 137 } |
128 } | 138 } |
129 return result; | 139 return result; |
130 } | 140 } |
131 | 141 |
132 virtual void mouseCaptureLost() { | 142 virtual void mouseCaptureLost() { |
133 NOTIMPLEMENTED(); | 143 NOTIMPLEMENTED(); |
134 } | 144 } |
135 | 145 |
136 virtual void setFocus(bool focus) { | 146 virtual void setFocus(bool focus) { |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
171 } | 181 } |
172 | 182 |
173 virtual bool caretOrSelectionRange(size_t* location, size_t* length) { | 183 virtual bool caretOrSelectionRange(size_t* location, size_t* length) { |
174 return false; | 184 return false; |
175 } | 185 } |
176 | 186 |
177 virtual void setTextDirection(WebTextDirection) { | 187 virtual void setTextDirection(WebTextDirection) { |
178 } | 188 } |
179 | 189 |
180 virtual bool isAcceleratedCompositingActive() const { | 190 virtual bool isAcceleratedCompositingActive() const { |
181 return widget_->context() && (plugin_->GetBackingTextureId() != 0); | 191 return widget_->context() && widget_->plugin() && |
192 (widget_->plugin()->GetBackingTextureId() != 0); | |
piman
2011/10/07 22:36:22
nit: indentation (4 spaces).
yzshen1
2011/10/07 22:48:14
Done.
| |
182 } | 193 } |
183 | 194 |
184 private: | 195 private: |
185 scoped_refptr<webkit::ppapi::PluginInstance> plugin_; | |
186 RenderWidgetFullscreenPepper* widget_; | 196 RenderWidgetFullscreenPepper* widget_; |
187 WebSize size_; | 197 WebSize size_; |
188 | 198 |
189 DISALLOW_COPY_AND_ASSIGN(PepperWidget); | 199 DISALLOW_COPY_AND_ASSIGN(PepperWidget); |
190 }; | 200 }; |
191 | 201 |
192 void DestroyContext(RendererGLContext* context, GLuint program, GLuint buffer) { | 202 void DestroyContext(RendererGLContext* context, GLuint program, GLuint buffer) { |
193 DCHECK(context); | 203 DCHECK(context); |
194 gpu::gles2::GLES2Implementation* gl = context->GetImplementation(); | 204 gpu::gles2::GLES2Implementation* gl = context->GetImplementation(); |
195 if (program) | 205 if (program) |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
314 const gfx::Rect& resizer_rect) { | 324 const gfx::Rect& resizer_rect) { |
315 if (context_) { | 325 if (context_) { |
316 gpu::gles2::GLES2Implementation* gl = context_->GetImplementation(); | 326 gpu::gles2::GLES2Implementation* gl = context_->GetImplementation(); |
317 gl->ResizeCHROMIUM(size.width(), size.height()); | 327 gl->ResizeCHROMIUM(size.width(), size.height()); |
318 gl->Viewport(0, 0, size.width(), size.height()); | 328 gl->Viewport(0, 0, size.width(), size.height()); |
319 } | 329 } |
320 RenderWidget::OnResize(size, resizer_rect); | 330 RenderWidget::OnResize(size, resizer_rect); |
321 } | 331 } |
322 | 332 |
323 WebWidget* RenderWidgetFullscreenPepper::CreateWebWidget() { | 333 WebWidget* RenderWidgetFullscreenPepper::CreateWebWidget() { |
324 return new PepperWidget(plugin_, this); | 334 return new PepperWidget(this); |
325 } | 335 } |
326 | 336 |
327 bool RenderWidgetFullscreenPepper::SupportsAsynchronousSwapBuffers() { | 337 bool RenderWidgetFullscreenPepper::SupportsAsynchronousSwapBuffers() { |
328 return context_ != NULL; | 338 return context_ != NULL; |
329 } | 339 } |
330 | 340 |
331 void RenderWidgetFullscreenPepper::CreateContext() { | 341 void RenderWidgetFullscreenPepper::CreateContext() { |
332 DCHECK(!context_); | 342 DCHECK(!context_); |
333 RenderThreadImpl* render_thread = RenderThreadImpl::current(); | 343 RenderThreadImpl* render_thread = RenderThreadImpl::current(); |
334 GpuChannelHost* host = render_thread->EstablishGpuChannelSync( | 344 GpuChannelHost* host = render_thread->EstablishGpuChannelSync( |
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
491 context_ = NULL; | 501 context_ = NULL; |
492 program_ = 0; | 502 program_ = 0; |
493 buffer_ = 0; | 503 buffer_ = 0; |
494 OnSwapBuffersAborted(); | 504 OnSwapBuffersAborted(); |
495 CheckCompositing(); | 505 CheckCompositing(); |
496 } | 506 } |
497 | 507 |
498 void RenderWidgetFullscreenPepper::OnSwapBuffersCompleteByRendererGLContext() { | 508 void RenderWidgetFullscreenPepper::OnSwapBuffersCompleteByRendererGLContext() { |
499 OnSwapBuffersComplete(); | 509 OnSwapBuffersComplete(); |
500 } | 510 } |
OLD | NEW |