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
;
55 class ThreadSafeSender
;
57 class CONTENT_EXPORT ChildFrameCompositingHelper
58 : public base::RefCounted
<ChildFrameCompositingHelper
>,
59 public cc::DelegatedFrameResourceCollectionClient
{
61 static ChildFrameCompositingHelper
* CreateForBrowserPlugin(
62 const base::WeakPtr
<BrowserPlugin
>& browser_plugin
);
63 static ChildFrameCompositingHelper
* CreateForRenderFrameProxy(
64 RenderFrameProxy
* render_frame_proxy
);
66 void DidCommitCompositorFrame();
67 void EnableCompositing(bool);
68 void OnContainerDestroy();
69 void OnCompositorFrameSwapped(scoped_ptr
<cc::CompositorFrame
> frame
,
71 uint32 output_surface_id
,
73 base::SharedMemoryHandle handle
);
74 void OnSetSurface(const cc::SurfaceId
& surface_id
,
75 const gfx::Size
& frame_size
,
77 const cc::SurfaceSequence
& sequence
);
78 void UpdateVisibility(bool);
79 void ChildFrameGone();
81 // cc::DelegatedFrameProviderClient implementation.
82 void UnusedResourcesAreAvailable() override
;
83 void SetContentsOpaque(bool);
86 // Friend RefCounted so that the dtor can be non-public.
87 friend class base::RefCounted
<ChildFrameCompositingHelper
>;
90 ChildFrameCompositingHelper(
91 const base::WeakPtr
<BrowserPlugin
>& browser_plugin
,
92 blink::WebFrame
* frame
,
93 RenderFrameProxy
* render_frame_proxy
,
96 virtual ~ChildFrameCompositingHelper();
98 BrowserPluginManager
* GetBrowserPluginManager();
99 blink::WebPluginContainer
* GetContainer();
102 void SendCompositorFrameSwappedACKToBrowser(
103 FrameHostMsg_CompositorFrameSwappedACK_Params
& params
);
104 void SendReclaimCompositorResourcesToBrowser(
105 FrameHostMsg_ReclaimCompositorResources_Params
& params
);
106 void CheckSizeAndAdjustLayerProperties(const gfx::Size
& new_size
,
107 float device_scale_factor
,
109 void SendReturnedDelegatedResources();
110 static void SatisfyCallback(scoped_refptr
<ThreadSafeSender
> sender
,
112 cc::SurfaceSequence sequence
);
113 static void SatisfyCallbackBrowserPlugin(
114 scoped_refptr
<ThreadSafeSender
> sender
,
116 int browser_plugin_instance_id
,
117 cc::SurfaceSequence sequence
);
118 static void RequireCallback(scoped_refptr
<ThreadSafeSender
> sender
,
121 cc::SurfaceSequence sequence
);
122 static void RequireCallbackBrowserPlugin(
123 scoped_refptr
<ThreadSafeSender
> sender
,
125 int browser_plugin_instance_id
,
127 cc::SurfaceSequence sequence
);
129 int host_routing_id_
;
131 uint32 last_output_surface_id_
;
136 gfx::Size buffer_size_
;
138 // The lifetime of this weak pointer should be greater than the lifetime of
139 // other member objects, as they may access this pointer during their
141 base::WeakPtr
<BrowserPlugin
> browser_plugin_
;
142 RenderFrameProxy
* render_frame_proxy_
;
144 scoped_refptr
<cc::DelegatedFrameResourceCollection
> resource_collection_
;
145 scoped_refptr
<cc::DelegatedFrameProvider
> frame_provider_
;
147 // For cc::Surface support.
148 scoped_refptr
<cc::SurfaceLayer
> surface_layer_
;
150 scoped_refptr
<cc::SolidColorLayer
> background_layer_
;
151 scoped_refptr
<cc::DelegatedRendererLayer
> delegated_layer_
;
152 scoped_ptr
<blink::WebLayer
> web_layer_
;
153 blink::WebFrame
* frame_
;
155 DISALLOW_COPY_AND_ASSIGN(ChildFrameCompositingHelper
);
158 } // namespace content
160 #endif // CONTENT_RENDERER_CHILD_FRAME_COMPOSITING_HELPER_H_