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 "ui/gfx/geometry/size.h"
24 struct SurfaceSequence
;
26 class CompositorFrame
;
28 class SolidColorLayer
;
30 class DelegatedFrameProvider
;
31 class DelegatedFrameResourceCollection
;
32 class DelegatedRendererLayer
;
37 class WebPluginContainer
;
46 struct FrameHostMsg_CompositorFrameSwappedACK_Params
;
47 struct FrameHostMsg_BuffersSwappedACK_Params
;
48 struct FrameHostMsg_ReclaimCompositorResources_Params
;
53 class BrowserPluginManager
;
54 class RenderFrameProxy
;
56 class CONTENT_EXPORT ChildFrameCompositingHelper
57 : public base::RefCounted
<ChildFrameCompositingHelper
>,
58 public cc::DelegatedFrameResourceCollectionClient
{
60 static ChildFrameCompositingHelper
* CreateForBrowserPlugin(
61 const base::WeakPtr
<BrowserPlugin
>& browser_plugin
);
62 static ChildFrameCompositingHelper
* CreateForRenderFrameProxy(
63 RenderFrameProxy
* render_frame_proxy
);
65 void DidCommitCompositorFrame();
66 void EnableCompositing(bool);
67 void OnContainerDestroy();
68 void OnCompositorFrameSwapped(scoped_ptr
<cc::CompositorFrame
> frame
,
70 uint32 output_surface_id
,
72 base::SharedMemoryHandle handle
);
73 void OnSetSurface(const cc::SurfaceId
& surface_id
,
74 const gfx::Size
& frame_size
,
76 const cc::SurfaceSequence
& sequence
);
77 void UpdateVisibility(bool);
78 void ChildFrameGone();
80 // cc::DelegatedFrameProviderClient implementation.
81 void UnusedResourcesAreAvailable() override
;
82 void SetContentsOpaque(bool);
85 // Friend RefCounted so that the dtor can be non-public.
86 friend class base::RefCounted
<ChildFrameCompositingHelper
>;
89 ChildFrameCompositingHelper(
90 const base::WeakPtr
<BrowserPlugin
>& browser_plugin
,
91 blink::WebFrame
* frame
,
92 RenderFrameProxy
* render_frame_proxy
,
95 virtual ~ChildFrameCompositingHelper();
97 BrowserPluginManager
* GetBrowserPluginManager();
98 blink::WebPluginContainer
* GetContainer();
101 void SendCompositorFrameSwappedACKToBrowser(
102 FrameHostMsg_CompositorFrameSwappedACK_Params
& params
);
103 void SendReclaimCompositorResourcesToBrowser(
104 FrameHostMsg_ReclaimCompositorResources_Params
& params
);
105 void CheckSizeAndAdjustLayerProperties(const gfx::Size
& new_size
,
106 float device_scale_factor
,
108 void SendReturnedDelegatedResources();
109 static void SatisfyCallback(base::WeakPtr
<ChildFrameCompositingHelper
> helper
,
110 cc::SurfaceSequence sequence
);
111 static void RequireCallback(base::WeakPtr
<ChildFrameCompositingHelper
> helper
,
113 cc::SurfaceSequence sequence
);
115 base::WeakPtr
<ChildFrameCompositingHelper
> GetWeakPtr() {
116 return weak_factory_
.GetWeakPtr();
119 int host_routing_id_
;
121 uint32 last_output_surface_id_
;
126 gfx::Size buffer_size_
;
128 // The lifetime of this weak pointer should be greater than the lifetime of
129 // other member objects, as they may access this pointer during their
131 base::WeakPtr
<BrowserPlugin
> browser_plugin_
;
132 RenderFrameProxy
* render_frame_proxy_
;
134 scoped_refptr
<cc::DelegatedFrameResourceCollection
> resource_collection_
;
135 scoped_refptr
<cc::DelegatedFrameProvider
> frame_provider_
;
137 // For cc::Surface support.
138 scoped_refptr
<cc::SurfaceLayer
> surface_layer_
;
140 scoped_refptr
<cc::SolidColorLayer
> background_layer_
;
141 scoped_refptr
<cc::DelegatedRendererLayer
> delegated_layer_
;
142 scoped_ptr
<blink::WebLayer
> web_layer_
;
143 blink::WebFrame
* frame_
;
145 base::WeakPtrFactory
<ChildFrameCompositingHelper
> weak_factory_
;
147 DISALLOW_COPY_AND_ASSIGN(ChildFrameCompositingHelper
);
150 } // namespace content
152 #endif // CONTENT_RENDERER_CHILD_FRAME_COMPOSITING_HELPER_H_