1 // Copyright 2014 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_CHILD_FRAME_COMPOSITING_HELPER_H_ 6 #define CONTENT_RENDERER_CHILD_FRAME_COMPOSITING_HELPER_H_ 7 8 #include <string> 9 #include <vector> 10 11 #include "base/memory/ref_counted.h" 12 #include "base/memory/scoped_ptr.h" 13 #include "base/memory/shared_memory.h" 14 #include "cc/layers/delegated_frame_resource_collection.h" 15 #include "content/common/content_export.h" 16 #include "gpu/command_buffer/common/mailbox.h" 17 #include "ui/gfx/size.h" 18 19 namespace base { 20 class SharedMemory; 21 } 22 23 namespace cc { 24 class CompositorFrame; 25 class CopyOutputResult; 26 class Layer; 27 class SolidColorLayer; 28 class TextureLayer; 29 class DelegatedFrameProvider; 30 class DelegatedFrameResourceCollection; 31 class DelegatedRendererLayer; 32 } 33 34 namespace blink { 35 class WebFrame; 36 class WebPluginContainer; 37 class WebLayer; 38 } 39 40 namespace gfx { 41 class Rect; 42 class Size; 43 } 44 45 struct FrameHostMsg_CompositorFrameSwappedACK_Params; 46 struct FrameHostMsg_BuffersSwappedACK_Params; 47 struct FrameHostMsg_ReclaimCompositorResources_Params; 48 49 namespace content { 50 51 class BrowserPlugin; 52 class BrowserPluginManager; 53 class RenderFrameProxy; 54 55 class CONTENT_EXPORT ChildFrameCompositingHelper 56 : public base::RefCounted<ChildFrameCompositingHelper>, 57 public cc::DelegatedFrameResourceCollectionClient { 58 public: 59 static ChildFrameCompositingHelper* CreateCompositingHelperForBrowserPlugin( 60 const base::WeakPtr<BrowserPlugin>& browser_plugin); 61 static ChildFrameCompositingHelper* CreateCompositingHelperForRenderFrame( 62 blink::WebFrame* frame, 63 RenderFrameProxy* render_frame_proxy, 64 int host_routing_id); 65 66 void CopyFromCompositingSurface(int request_id, 67 gfx::Rect source_rect, 68 gfx::Size dest_size); 69 void DidCommitCompositorFrame(); 70 void EnableCompositing(bool); 71 void OnContainerDestroy(); 72 void OnBuffersSwapped(const gfx::Size& size, 73 const gpu::Mailbox& mailbox, 74 int gpu_route_id, 75 int gpu_host_id, 76 float device_scale_factor); 77 void OnCompositorFrameSwapped(scoped_ptr<cc::CompositorFrame> frame, 78 int route_id, 79 uint32 output_surface_id, 80 int host_id, 81 base::SharedMemoryHandle handle); 82 void UpdateVisibility(bool); 83 void ChildFrameGone(); 84 85 // cc::DelegatedFrameProviderClient implementation. 86 virtual void UnusedResourcesAreAvailable() OVERRIDE; 87 void SetContentsOpaque(bool); 88 89 protected: 90 // Friend RefCounted so that the dtor can be non-public. 91 friend class base::RefCounted<ChildFrameCompositingHelper>; 92 93 private: 94 ChildFrameCompositingHelper( 95 const base::WeakPtr<BrowserPlugin>& browser_plugin, 96 blink::WebFrame* frame, 97 RenderFrameProxy* render_frame_proxy, 98 int host_routing_id); 99 100 enum SwapBuffersType { 101 TEXTURE_IMAGE_TRANSPORT, 102 GL_COMPOSITOR_FRAME, 103 SOFTWARE_COMPOSITOR_FRAME, 104 }; 105 struct SwapBuffersInfo { 106 SwapBuffersInfo(); 107 108 gpu::Mailbox name; 109 SwapBuffersType type; 110 gfx::Size size; 111 int route_id; 112 uint32 output_surface_id; 113 int host_id; 114 unsigned software_frame_id; 115 base::SharedMemory* shared_memory; 116 }; 117 virtual ~ChildFrameCompositingHelper(); 118 119 BrowserPluginManager* GetBrowserPluginManager(); 120 blink::WebPluginContainer* GetContainer(); 121 int GetInstanceID(); 122 123 void SendCompositorFrameSwappedACKToBrowser( 124 FrameHostMsg_CompositorFrameSwappedACK_Params& params); 125 void SendBuffersSwappedACKToBrowser( 126 FrameHostMsg_BuffersSwappedACK_Params& params); 127 void SendReclaimCompositorResourcesToBrowser( 128 FrameHostMsg_ReclaimCompositorResources_Params& params); 129 void CheckSizeAndAdjustLayerProperties(const gfx::Size& new_size, 130 float device_scale_factor, 131 cc::Layer* layer); 132 void OnBuffersSwappedPrivate(const SwapBuffersInfo& mailbox, 133 unsigned sync_point, 134 float device_scale_factor); 135 void MailboxReleased(SwapBuffersInfo mailbox, 136 unsigned sync_point, 137 bool lost_resource); 138 void SendReturnedDelegatedResources(); 139 void CopyFromCompositingSurfaceHasResult( 140 int request_id, 141 gfx::Size dest_size, 142 scoped_ptr<cc::CopyOutputResult> result); 143 144 int host_routing_id_; 145 int last_route_id_; 146 uint32 last_output_surface_id_; 147 int last_host_id_; 148 bool last_mailbox_valid_; 149 bool ack_pending_; 150 bool software_ack_pending_; 151 bool opaque_; 152 std::vector<unsigned> unacked_software_frames_; 153 154 gfx::Size buffer_size_; 155 156 // The lifetime of this weak pointer should be greater than the lifetime of 157 // other member objects, as they may access this pointer during their 158 // destruction. 159 base::WeakPtr<BrowserPlugin> browser_plugin_; 160 RenderFrameProxy* render_frame_proxy_; 161 162 scoped_refptr<cc::DelegatedFrameResourceCollection> resource_collection_; 163 scoped_refptr<cc::DelegatedFrameProvider> frame_provider_; 164 165 scoped_refptr<cc::SolidColorLayer> background_layer_; 166 scoped_refptr<cc::TextureLayer> texture_layer_; 167 scoped_refptr<cc::DelegatedRendererLayer> delegated_layer_; 168 scoped_ptr<blink::WebLayer> web_layer_; 169 blink::WebFrame* frame_; 170 171 DISALLOW_COPY_AND_ASSIGN(ChildFrameCompositingHelper); 172 }; 173 174 } // namespace content 175 176 #endif // CONTENT_RENDERER_CHILD_FRAME_COMPOSITING_HELPER_H_ 177