render_widget_fullscreen_pepper.h revision 5821806d5e7f356e8fa4b058a389a808ea183019
1// Copyright (c) 2012 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#ifndef CONTENT_RENDERER_RENDER_WIDGET_FULLSCREEN_PEPPER_H_ 6#define CONTENT_RENDERER_RENDER_WIDGET_FULLSCREEN_PEPPER_H_ 7 8#include "base/memory/scoped_ptr.h" 9#include "base/memory/weak_ptr.h" 10#include "content/common/gpu/client/webgraphicscontext3d_command_buffer_impl.h" 11#include "content/renderer/mouse_lock_dispatcher.h" 12#include "content/renderer/pepper/pepper_parent_context_provider.h" 13#include "content/renderer/render_widget_fullscreen.h" 14#include "third_party/WebKit/Source/Platform/chromium/public/WebGraphicsContext3D.h" 15#include "third_party/WebKit/Source/WebKit/chromium/public/WebWidget.h" 16#include "webkit/plugins/ppapi/fullscreen_container.h" 17 18namespace webkit { 19namespace ppapi { 20 21class PluginInstance; 22 23} // namespace ppapi 24} // namespace webkit 25 26namespace content { 27class WebGraphicsContext3DCommandBufferImpl; 28 29// A RenderWidget that hosts a fullscreen pepper plugin. This provides a 30// FullscreenContainer that the plugin instance can callback into to e.g. 31// invalidate rects. 32class RenderWidgetFullscreenPepper : 33 public RenderWidgetFullscreen, 34 public webkit::ppapi::FullscreenContainer, 35 public PepperParentContextProvider, 36 public WebGraphicsContext3DSwapBuffersClient { 37 public: 38 static RenderWidgetFullscreenPepper* Create( 39 int32 opener_id, 40 webkit::ppapi::PluginInstance* plugin, 41 const GURL& active_url, 42 const WebKit::WebScreenInfo& screen_info); 43 44 // WebGraphicscontext3DSwapBuffersClient implementation 45 virtual void OnViewContextSwapBuffersPosted() OVERRIDE; 46 virtual void OnViewContextSwapBuffersComplete() OVERRIDE; 47 virtual void OnViewContextSwapBuffersAborted() OVERRIDE; 48 49 // pepper::FullscreenContainer API. 50 virtual void Invalidate() OVERRIDE; 51 virtual void InvalidateRect(const WebKit::WebRect& rect) OVERRIDE; 52 virtual void ScrollRect(int dx, int dy, const WebKit::WebRect& rect) OVERRIDE; 53 virtual void Destroy() OVERRIDE; 54 virtual void DidChangeCursor(const WebKit::WebCursorInfo& cursor) OVERRIDE; 55 virtual webkit::ppapi::PluginDelegate::PlatformContext3D* 56 CreateContext3D() OVERRIDE; 57 virtual void ReparentContext( 58 webkit::ppapi::PluginDelegate::PlatformContext3D*) OVERRIDE; 59 60 // IPC::Listener implementation. This overrides the implementation 61 // in RenderWidgetFullscreen. 62 virtual bool OnMessageReceived(const IPC::Message& msg) OVERRIDE; 63 64 WebGraphicsContext3DCommandBufferImpl* context() const { return context_; } 65 void SwapBuffers(); 66 67 // Could be NULL when this widget is closing. 68 webkit::ppapi::PluginInstance* plugin() const { return plugin_; } 69 70 MouseLockDispatcher* mouse_lock_dispatcher() const { 71 return mouse_lock_dispatcher_.get(); 72 } 73 74 protected: 75 RenderWidgetFullscreenPepper(webkit::ppapi::PluginInstance* plugin, 76 const GURL& active_url, 77 const WebKit::WebScreenInfo& screen_info); 78 virtual ~RenderWidgetFullscreenPepper(); 79 80 // RenderWidget API. 81 virtual void WillInitiatePaint() OVERRIDE; 82 virtual void DidInitiatePaint() OVERRIDE; 83 virtual void DidFlushPaint() OVERRIDE; 84 virtual void Close() OVERRIDE; 85 virtual webkit::ppapi::PluginInstance* GetBitmapForOptimizedPluginPaint( 86 const gfx::Rect& paint_bounds, 87 TransportDIB** dib, 88 gfx::Rect* location, 89 gfx::Rect* clip, 90 float* scale_factor) OVERRIDE; 91 virtual void OnResize(const gfx::Size& new_size, 92 const gfx::Rect& resizer_rect, 93 bool is_fullscreen) OVERRIDE; 94 95 // RenderWidgetFullscreen API. 96 virtual WebKit::WebWidget* CreateWebWidget() OVERRIDE; 97 98 // RenderWidget overrides. 99 virtual bool SupportsAsynchronousSwapBuffers() OVERRIDE; 100 101 private: 102 // Creates the GL context for compositing. 103 void CreateContext(); 104 105 // Initialize the GL states and resources for compositing. 106 bool InitContext(); 107 108 // Checks (and returns) whether accelerated compositing should be on or off, 109 // and notify the browser. 110 bool CheckCompositing(); 111 112 // Implementation of PepperParentContextProvider. 113 virtual WebGraphicsContext3DCommandBufferImpl* 114 GetParentContextForPlatformContext3D() OVERRIDE; 115 116 // URL that is responsible for this widget, passed to ggl::CreateViewContext. 117 GURL active_url_; 118 119 // The plugin instance this widget wraps. 120 webkit::ppapi::PluginInstance* plugin_; 121 122 // GL context for compositing. 123 WebGraphicsContext3DCommandBufferImpl* context_; 124 unsigned int buffer_; 125 unsigned int program_; 126 127 base::WeakPtrFactory<RenderWidgetFullscreenPepper> weak_ptr_factory_; 128 129 scoped_ptr<MouseLockDispatcher> mouse_lock_dispatcher_; 130 131 DISALLOW_COPY_AND_ASSIGN(RenderWidgetFullscreenPepper); 132}; 133 134} // namespace content 135 136#endif // CONTENT_RENDERER_RENDER_WIDGET_FULLSCREEN_PEPPER_H_ 137