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 RenderFrameProxy
;
55 class CONTENT_EXPORT ChildFrameCompositingHelper
56 : public base::RefCounted
<ChildFrameCompositingHelper
>,
57 public cc::DelegatedFrameResourceCollectionClient
{
59 static ChildFrameCompositingHelper
* CreateForBrowserPlugin(
60 const base::WeakPtr
<BrowserPlugin
>& browser_plugin
);
61 static ChildFrameCompositingHelper
* CreateForRenderFrameProxy(
62 RenderFrameProxy
* render_frame_proxy
);
64 void CopyFromCompositingSurface(int request_id
,
65 gfx::Rect source_rect
,
67 void DidCommitCompositorFrame();
68 void EnableCompositing(bool);
69 void OnContainerDestroy();
70 void OnBuffersSwapped(const gfx::Size
& size
,
71 const gpu::Mailbox
& mailbox
,
74 float device_scale_factor
);
75 void OnCompositorFrameSwapped(scoped_ptr
<cc::CompositorFrame
> frame
,
77 uint32 output_surface_id
,
79 base::SharedMemoryHandle handle
);
80 void UpdateVisibility(bool);
81 void ChildFrameGone();
83 // cc::DelegatedFrameProviderClient implementation.
84 virtual void UnusedResourcesAreAvailable() OVERRIDE
;
85 void SetContentsOpaque(bool);
88 // Friend RefCounted so that the dtor can be non-public.
89 friend class base::RefCounted
<ChildFrameCompositingHelper
>;
92 ChildFrameCompositingHelper(
93 const base::WeakPtr
<BrowserPlugin
>& browser_plugin
,
94 blink::WebFrame
* frame
,
95 RenderFrameProxy
* render_frame_proxy
,
98 enum SwapBuffersType
{
99 TEXTURE_IMAGE_TRANSPORT
,
101 SOFTWARE_COMPOSITOR_FRAME
,
103 struct SwapBuffersInfo
{
107 SwapBuffersType type
;
110 uint32 output_surface_id
;
112 unsigned software_frame_id
;
113 base::SharedMemory
* shared_memory
;
115 virtual ~ChildFrameCompositingHelper();
117 BrowserPluginManager
* GetBrowserPluginManager();
118 blink::WebPluginContainer
* GetContainer();
121 void SendCompositorFrameSwappedACKToBrowser(
122 FrameHostMsg_CompositorFrameSwappedACK_Params
& params
);
123 void SendBuffersSwappedACKToBrowser(
124 FrameHostMsg_BuffersSwappedACK_Params
& params
);
125 void SendReclaimCompositorResourcesToBrowser(
126 FrameHostMsg_ReclaimCompositorResources_Params
& params
);
127 void CheckSizeAndAdjustLayerProperties(const gfx::Size
& new_size
,
128 float device_scale_factor
,
130 void OnBuffersSwappedPrivate(const SwapBuffersInfo
& mailbox
,
132 float device_scale_factor
);
133 void MailboxReleased(SwapBuffersInfo mailbox
,
136 void SendReturnedDelegatedResources();
137 void CopyFromCompositingSurfaceHasResult(
140 scoped_ptr
<cc::CopyOutputResult
> result
);
142 int host_routing_id_
;
144 uint32 last_output_surface_id_
;
146 bool last_mailbox_valid_
;
148 bool software_ack_pending_
;
150 std::vector
<unsigned> unacked_software_frames_
;
152 gfx::Size buffer_size_
;
154 // The lifetime of this weak pointer should be greater than the lifetime of
155 // other member objects, as they may access this pointer during their
157 base::WeakPtr
<BrowserPlugin
> browser_plugin_
;
158 RenderFrameProxy
* render_frame_proxy_
;
160 scoped_refptr
<cc::DelegatedFrameResourceCollection
> resource_collection_
;
161 scoped_refptr
<cc::DelegatedFrameProvider
> frame_provider_
;
163 scoped_refptr
<cc::SolidColorLayer
> background_layer_
;
164 scoped_refptr
<cc::TextureLayer
> texture_layer_
;
165 scoped_refptr
<cc::DelegatedRendererLayer
> delegated_layer_
;
166 scoped_ptr
<blink::WebLayer
> web_layer_
;
167 blink::WebFrame
* frame_
;
169 DISALLOW_COPY_AND_ASSIGN(ChildFrameCompositingHelper
);
172 } // namespace content
174 #endif // CONTENT_RENDERER_CHILD_FRAME_COMPOSITING_HELPER_H_