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.
5 #ifndef CONTENT_RENDERER_CHILD_FRAME_COMPOSITING_HELPER_H_
6 #define CONTENT_RENDERER_CHILD_FRAME_COMPOSITING_HELPER_H_
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"
24 class CompositorFrame
;
25 class CopyOutputResult
;
27 class SolidColorLayer
;
29 class DelegatedFrameProvider
;
30 class DelegatedFrameResourceCollection
;
31 class DelegatedRendererLayer
;
36 class WebPluginContainer
;
45 struct FrameHostMsg_CompositorFrameSwappedACK_Params
;
46 struct FrameHostMsg_BuffersSwappedACK_Params
;
47 struct FrameHostMsg_ReclaimCompositorResources_Params
;
52 class BrowserPluginManager
;
53 class RenderFrameImpl
;
55 class CONTENT_EXPORT ChildFrameCompositingHelper
56 : public base::RefCounted
<ChildFrameCompositingHelper
>,
57 public cc::DelegatedFrameResourceCollectionClient
{
59 static ChildFrameCompositingHelper
* CreateCompositingHelperForBrowserPlugin(
60 const base::WeakPtr
<BrowserPlugin
>& browser_plugin
);
61 static ChildFrameCompositingHelper
* CreateCompositingHelperForRenderFrame(
62 blink::WebFrame
* frame
,
63 RenderFrameImpl
* render_frame
,
66 void CopyFromCompositingSurface(int request_id
,
67 gfx::Rect source_rect
,
69 void DidCommitCompositorFrame();
70 void EnableCompositing(bool);
71 void OnContainerDestroy();
72 void OnBuffersSwapped(const gfx::Size
& size
,
73 const gpu::Mailbox
& mailbox
,
76 float device_scale_factor
);
77 void OnCompositorFrameSwapped(scoped_ptr
<cc::CompositorFrame
> frame
,
79 uint32 output_surface_id
,
81 base::SharedMemoryHandle handle
);
82 void UpdateVisibility(bool);
83 void ChildFrameGone();
85 // cc::DelegatedFrameProviderClient implementation.
86 virtual void UnusedResourcesAreAvailable() OVERRIDE
;
87 void SetContentsOpaque(bool);
90 // Friend RefCounted so that the dtor can be non-public.
91 friend class base::RefCounted
<ChildFrameCompositingHelper
>;
94 ChildFrameCompositingHelper(
95 const base::WeakPtr
<BrowserPlugin
>& browser_plugin
,
96 blink::WebFrame
* frame
,
97 RenderFrameImpl
* render_frame
,
100 enum SwapBuffersType
{
101 TEXTURE_IMAGE_TRANSPORT
,
103 SOFTWARE_COMPOSITOR_FRAME
,
105 struct SwapBuffersInfo
{
109 SwapBuffersType type
;
112 uint32 output_surface_id
;
114 unsigned software_frame_id
;
115 base::SharedMemory
* shared_memory
;
117 virtual ~ChildFrameCompositingHelper();
119 BrowserPluginManager
* GetBrowserPluginManager();
120 blink::WebPluginContainer
* GetContainer();
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
,
132 void OnBuffersSwappedPrivate(const SwapBuffersInfo
& mailbox
,
134 float device_scale_factor
);
135 void MailboxReleased(SwapBuffersInfo mailbox
,
138 void SendReturnedDelegatedResources();
139 void CopyFromCompositingSurfaceHasResult(
142 scoped_ptr
<cc::CopyOutputResult
> result
);
144 int host_routing_id_
;
146 uint32 last_output_surface_id_
;
148 bool last_mailbox_valid_
;
150 bool software_ack_pending_
;
152 std::vector
<unsigned> unacked_software_frames_
;
154 gfx::Size buffer_size_
;
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
159 base::WeakPtr
<BrowserPlugin
> browser_plugin_
;
160 RenderFrameImpl
* render_frame_
;
162 scoped_refptr
<cc::DelegatedFrameResourceCollection
> resource_collection_
;
163 scoped_refptr
<cc::DelegatedFrameProvider
> frame_provider_
;
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_
;
171 DISALLOW_COPY_AND_ASSIGN(ChildFrameCompositingHelper
);
174 } // namespace content
176 #endif // CONTENT_RENDERER_CHILD_FRAME_COMPOSITING_HELPER_H_