Updating trunk VERSION from 2139.0 to 2140.0
[chromium-blink-merge.git] / content / renderer / child_frame_compositing_helper.h
blob5ecf9a82326729f6c7e991d339fe998cba9b5508
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 "gpu/command_buffer/common/mailbox.h"
17 #include "ui/gfx/size.h"
19 namespace base {
20 class SharedMemory;
23 namespace cc {
24 class CompositorFrame;
25 class CopyOutputResult;
26 class Layer;
27 class SolidColorLayer;
28 class TextureLayer;
29 class DelegatedFrameProvider;
30 class DelegatedFrameResourceCollection;
31 class DelegatedRendererLayer;
34 namespace blink {
35 class WebFrame;
36 class WebPluginContainer;
37 class WebLayer;
40 namespace gfx {
41 class Rect;
42 class Size;
45 struct FrameHostMsg_CompositorFrameSwappedACK_Params;
46 struct FrameHostMsg_BuffersSwappedACK_Params;
47 struct FrameHostMsg_ReclaimCompositorResources_Params;
49 namespace content {
51 class BrowserPlugin;
52 class BrowserPluginManager;
53 class RenderFrameProxy;
55 class CONTENT_EXPORT ChildFrameCompositingHelper
56 : public base::RefCounted<ChildFrameCompositingHelper>,
57 public cc::DelegatedFrameResourceCollectionClient {
58 public:
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,
66 gfx::Size dest_size);
67 void DidCommitCompositorFrame();
68 void EnableCompositing(bool);
69 void OnContainerDestroy();
70 void OnBuffersSwapped(const gfx::Size& size,
71 const gpu::Mailbox& mailbox,
72 int gpu_route_id,
73 int gpu_host_id,
74 float device_scale_factor);
75 void OnCompositorFrameSwapped(scoped_ptr<cc::CompositorFrame> frame,
76 int route_id,
77 uint32 output_surface_id,
78 int host_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);
87 protected:
88 // Friend RefCounted so that the dtor can be non-public.
89 friend class base::RefCounted<ChildFrameCompositingHelper>;
91 private:
92 ChildFrameCompositingHelper(
93 const base::WeakPtr<BrowserPlugin>& browser_plugin,
94 blink::WebFrame* frame,
95 RenderFrameProxy* render_frame_proxy,
96 int host_routing_id);
98 enum SwapBuffersType {
99 TEXTURE_IMAGE_TRANSPORT,
100 GL_COMPOSITOR_FRAME,
101 SOFTWARE_COMPOSITOR_FRAME,
103 struct SwapBuffersInfo {
104 SwapBuffersInfo();
106 gpu::Mailbox name;
107 SwapBuffersType type;
108 gfx::Size size;
109 int route_id;
110 uint32 output_surface_id;
111 int host_id;
112 unsigned software_frame_id;
113 base::SharedMemory* shared_memory;
115 virtual ~ChildFrameCompositingHelper();
117 BrowserPluginManager* GetBrowserPluginManager();
118 blink::WebPluginContainer* GetContainer();
119 int GetInstanceID();
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,
129 cc::Layer* layer);
130 void OnBuffersSwappedPrivate(const SwapBuffersInfo& mailbox,
131 unsigned sync_point,
132 float device_scale_factor);
133 void MailboxReleased(SwapBuffersInfo mailbox,
134 unsigned sync_point,
135 bool lost_resource);
136 void SendReturnedDelegatedResources();
137 void CopyFromCompositingSurfaceHasResult(
138 int request_id,
139 gfx::Size dest_size,
140 scoped_ptr<cc::CopyOutputResult> result);
142 int host_routing_id_;
143 int last_route_id_;
144 uint32 last_output_surface_id_;
145 int last_host_id_;
146 bool last_mailbox_valid_;
147 bool ack_pending_;
148 bool software_ack_pending_;
149 bool opaque_;
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
156 // destruction.
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_