• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.
4 
5 #ifndef CONTENT_RENDERER_CHILD_FRAME_COMPOSITING_HELPER_H_
6 #define CONTENT_RENDERER_CHILD_FRAME_COMPOSITING_HELPER_H_
7 
8 #include <string>
9 #include <vector>
10 
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/size.h"
17 
18 namespace base {
19 class SharedMemory;
20 }
21 
22 namespace cc {
23 class CompositorFrame;
24 class CopyOutputResult;
25 class Layer;
26 class SolidColorLayer;
27 class DelegatedFrameProvider;
28 class DelegatedFrameResourceCollection;
29 class DelegatedRendererLayer;
30 }
31 
32 namespace blink {
33 class WebFrame;
34 class WebPluginContainer;
35 class WebLayer;
36 }
37 
38 namespace gfx {
39 class Rect;
40 class Size;
41 }
42 
43 struct FrameHostMsg_CompositorFrameSwappedACK_Params;
44 struct FrameHostMsg_BuffersSwappedACK_Params;
45 struct FrameHostMsg_ReclaimCompositorResources_Params;
46 
47 namespace content {
48 
49 class BrowserPlugin;
50 class BrowserPluginManager;
51 class RenderFrameProxy;
52 
53 class CONTENT_EXPORT ChildFrameCompositingHelper
54     : public base::RefCounted<ChildFrameCompositingHelper>,
55       public cc::DelegatedFrameResourceCollectionClient {
56  public:
57   static ChildFrameCompositingHelper* CreateForBrowserPlugin(
58       const base::WeakPtr<BrowserPlugin>& browser_plugin);
59   static ChildFrameCompositingHelper* CreateForRenderFrameProxy(
60       RenderFrameProxy* render_frame_proxy);
61 
62   void CopyFromCompositingSurface(int request_id,
63                                   gfx::Rect source_rect,
64                                   gfx::Size dest_size);
65   void DidCommitCompositorFrame();
66   void EnableCompositing(bool);
67   void OnContainerDestroy();
68   void OnCompositorFrameSwapped(scoped_ptr<cc::CompositorFrame> frame,
69                                 int route_id,
70                                 uint32 output_surface_id,
71                                 int host_id,
72                                 base::SharedMemoryHandle handle);
73   void UpdateVisibility(bool);
74   void ChildFrameGone();
75 
76   // cc::DelegatedFrameProviderClient implementation.
77   virtual void UnusedResourcesAreAvailable() OVERRIDE;
78   void SetContentsOpaque(bool);
79 
80  protected:
81   // Friend RefCounted so that the dtor can be non-public.
82   friend class base::RefCounted<ChildFrameCompositingHelper>;
83 
84  private:
85   ChildFrameCompositingHelper(
86       const base::WeakPtr<BrowserPlugin>& browser_plugin,
87       blink::WebFrame* frame,
88       RenderFrameProxy* render_frame_proxy,
89       int host_routing_id);
90 
91   virtual ~ChildFrameCompositingHelper();
92 
93   BrowserPluginManager* GetBrowserPluginManager();
94   blink::WebPluginContainer* GetContainer();
95   int GetInstanceID();
96 
97   void SendCompositorFrameSwappedACKToBrowser(
98       FrameHostMsg_CompositorFrameSwappedACK_Params& params);
99   void SendReclaimCompositorResourcesToBrowser(
100       FrameHostMsg_ReclaimCompositorResources_Params& params);
101   void CheckSizeAndAdjustLayerProperties(const gfx::Size& new_size,
102                                          float device_scale_factor,
103                                          cc::Layer* layer);
104   void SendReturnedDelegatedResources();
105   void CopyFromCompositingSurfaceHasResult(
106       int request_id,
107       gfx::Size dest_size,
108       scoped_ptr<cc::CopyOutputResult> result);
109 
110   int host_routing_id_;
111   int last_route_id_;
112   uint32 last_output_surface_id_;
113   int last_host_id_;
114   bool ack_pending_;
115   bool opaque_;
116 
117   gfx::Size buffer_size_;
118 
119   // The lifetime of this weak pointer should be greater than the lifetime of
120   // other member objects, as they may access this pointer during their
121   // destruction.
122   base::WeakPtr<BrowserPlugin> browser_plugin_;
123   RenderFrameProxy* render_frame_proxy_;
124 
125   scoped_refptr<cc::DelegatedFrameResourceCollection> resource_collection_;
126   scoped_refptr<cc::DelegatedFrameProvider> frame_provider_;
127 
128   scoped_refptr<cc::SolidColorLayer> background_layer_;
129   scoped_refptr<cc::DelegatedRendererLayer> delegated_layer_;
130   scoped_ptr<blink::WebLayer> web_layer_;
131   blink::WebFrame* frame_;
132 
133   DISALLOW_COPY_AND_ASSIGN(ChildFrameCompositingHelper);
134 };
135 
136 }  // namespace content
137 
138 #endif  // CONTENT_RENDERER_CHILD_FRAME_COMPOSITING_HELPER_H_
139