Roll src/third_party/WebKit d10c917:a1123a1 (svn 198729:198730)
[chromium-blink-merge.git] / content / renderer / child_frame_compositing_helper.h
bloba6fb0f0340259d08210b6d29d2fca06db9e872b2
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_
8 #include <string>
9 #include <vector>
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"
18 namespace base {
19 class SharedMemory;
22 namespace cc {
23 struct SurfaceId;
24 struct SurfaceSequence;
26 class CompositorFrame;
27 class Layer;
28 class SolidColorLayer;
29 class SurfaceLayer;
30 class DelegatedFrameProvider;
31 class DelegatedFrameResourceCollection;
32 class DelegatedRendererLayer;
35 namespace blink {
36 class WebFrame;
37 class WebPluginContainer;
38 class WebLayer;
41 namespace gfx {
42 class Rect;
43 class Size;
46 struct FrameHostMsg_CompositorFrameSwappedACK_Params;
47 struct FrameHostMsg_BuffersSwappedACK_Params;
48 struct FrameHostMsg_ReclaimCompositorResources_Params;
50 namespace content {
52 class BrowserPlugin;
53 class BrowserPluginManager;
54 class RenderFrameProxy;
55 class ThreadSafeSender;
57 class CONTENT_EXPORT ChildFrameCompositingHelper
58 : public base::RefCounted<ChildFrameCompositingHelper>,
59 public cc::DelegatedFrameResourceCollectionClient {
60 public:
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,
70 int route_id,
71 uint32 output_surface_id,
72 int host_id,
73 base::SharedMemoryHandle handle);
74 void OnSetSurface(const cc::SurfaceId& surface_id,
75 const gfx::Size& frame_size,
76 float scale_factor,
77 const cc::SurfaceSequence& sequence);
78 void UpdateVisibility(bool);
79 void ChildFrameGone();
81 // cc::DelegatedFrameProviderClient implementation.
82 void UnusedResourcesAreAvailable() override;
83 void SetContentsOpaque(bool);
85 protected:
86 // Friend RefCounted so that the dtor can be non-public.
87 friend class base::RefCounted<ChildFrameCompositingHelper>;
89 private:
90 ChildFrameCompositingHelper(
91 const base::WeakPtr<BrowserPlugin>& browser_plugin,
92 blink::WebFrame* frame,
93 RenderFrameProxy* render_frame_proxy,
94 int host_routing_id);
96 virtual ~ChildFrameCompositingHelper();
98 BrowserPluginManager* GetBrowserPluginManager();
99 blink::WebPluginContainer* GetContainer();
100 int GetInstanceID();
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,
108 cc::Layer* layer);
109 void SendReturnedDelegatedResources();
110 static void SatisfyCallback(scoped_refptr<ThreadSafeSender> sender,
111 int host_routing_id,
112 cc::SurfaceSequence sequence);
113 static void RequireCallback(scoped_refptr<ThreadSafeSender> sender,
114 int host_routing_id,
115 cc::SurfaceId id,
116 cc::SurfaceSequence sequence);
117 static void RequireCallbackBrowserPlugin(
118 scoped_refptr<ThreadSafeSender> sender,
119 int host_routing_id,
120 int browser_plugin_instance_id,
121 cc::SurfaceId id,
122 cc::SurfaceSequence sequence);
124 int host_routing_id_;
125 int last_route_id_;
126 uint32 last_output_surface_id_;
127 int last_host_id_;
128 bool ack_pending_;
129 bool opaque_;
131 gfx::Size buffer_size_;
133 // The lifetime of this weak pointer should be greater than the lifetime of
134 // other member objects, as they may access this pointer during their
135 // destruction.
136 base::WeakPtr<BrowserPlugin> browser_plugin_;
137 RenderFrameProxy* render_frame_proxy_;
139 scoped_refptr<cc::DelegatedFrameResourceCollection> resource_collection_;
140 scoped_refptr<cc::DelegatedFrameProvider> frame_provider_;
142 // For cc::Surface support.
143 scoped_refptr<cc::SurfaceLayer> surface_layer_;
145 scoped_refptr<cc::SolidColorLayer> background_layer_;
146 scoped_refptr<cc::DelegatedRendererLayer> delegated_layer_;
147 scoped_ptr<blink::WebLayer> web_layer_;
148 blink::WebFrame* frame_;
150 DISALLOW_COPY_AND_ASSIGN(ChildFrameCompositingHelper);
153 } // namespace content
155 #endif // CONTENT_RENDERER_CHILD_FRAME_COMPOSITING_HELPER_H_