[email protected] | bffc830 | 2014-01-23 20:52:16 | [diff] [blame] | 1 | // Copyright 2014 The Chromium Authors. All rights reserved. |
[email protected] | 0f21e858 | 2013-01-11 11:06:56 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
[email protected] | bffc830 | 2014-01-23 20:52:16 | [diff] [blame] | 5 | #ifndef CONTENT_RENDERER_CHILD_FRAME_COMPOSITING_HELPER_H_ |
| 6 | #define CONTENT_RENDERER_CHILD_FRAME_COMPOSITING_HELPER_H_ |
[email protected] | 0f21e858 | 2013-01-11 11:06:56 | [diff] [blame] | 7 | |
| 8 | #include <string> |
[email protected] | 9afdaef | 2013-09-26 07:24:37 | [diff] [blame] | 9 | #include <vector> |
[email protected] | 0f21e858 | 2013-01-11 11:06:56 | [diff] [blame] | 10 | |
| 11 | #include "base/memory/ref_counted.h" |
| 12 | #include "base/memory/scoped_ptr.h" |
[email protected] | b0030b7 | 2013-11-15 20:35:53 | [diff] [blame] | 13 | #include "cc/layers/delegated_frame_resource_collection.h" |
[email protected] | 0f21e858 | 2013-01-11 11:06:56 | [diff] [blame] | 14 | #include "content/common/content_export.h" |
[email protected] | c049b2e | 2013-06-11 04:39:30 | [diff] [blame] | 15 | #include "gpu/command_buffer/common/mailbox.h" |
[email protected] | 0f21e858 | 2013-01-11 11:06:56 | [diff] [blame] | 16 | #include "ui/gfx/size.h" |
| 17 | |
[email protected] | 9f39c20 | 2013-06-18 16:06:42 | [diff] [blame] | 18 | namespace base { |
| 19 | class SharedMemory; |
| 20 | } |
| 21 | |
[email protected] | 0f21e858 | 2013-01-11 11:06:56 | [diff] [blame] | 22 | namespace cc { |
[email protected] | f5b4b0f | 2013-04-02 18:16:28 | [diff] [blame] | 23 | class CompositorFrame; |
[email protected] | 73405fb | 2013-12-11 04:59:37 | [diff] [blame] | 24 | class CopyOutputResult; |
[email protected] | f5b4b0f | 2013-04-02 18:16:28 | [diff] [blame] | 25 | class Layer; |
[email protected] | 396fbb7 | 2013-01-23 02:33:43 | [diff] [blame] | 26 | class SolidColorLayer; |
[email protected] | 0f21e858 | 2013-01-11 11:06:56 | [diff] [blame] | 27 | class TextureLayer; |
[email protected] | 09f6738 | 2013-10-09 21:03:45 | [diff] [blame] | 28 | class DelegatedFrameProvider; |
| 29 | class DelegatedFrameResourceCollection; |
[email protected] | f5b4b0f | 2013-04-02 18:16:28 | [diff] [blame] | 30 | class DelegatedRendererLayer; |
[email protected] | 0f21e858 | 2013-01-11 11:06:56 | [diff] [blame] | 31 | } |
| 32 | |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 33 | namespace blink { |
[email protected] | bffc830 | 2014-01-23 20:52:16 | [diff] [blame] | 34 | class WebFrame; |
[email protected] | 0f21e858 | 2013-01-11 11:06:56 | [diff] [blame] | 35 | class WebPluginContainer; |
| 36 | class WebLayer; |
| 37 | } |
| 38 | |
[email protected] | 73405fb | 2013-12-11 04:59:37 | [diff] [blame] | 39 | namespace gfx { |
| 40 | class Rect; |
| 41 | class Size; |
| 42 | } |
| 43 | |
[email protected] | bffc830 | 2014-01-23 20:52:16 | [diff] [blame] | 44 | struct FrameHostMsg_CompositorFrameSwappedACK_Params; |
| 45 | struct FrameHostMsg_BuffersSwappedACK_Params; |
| 46 | struct FrameHostMsg_ReclaimCompositorResources_Params; |
| 47 | |
[email protected] | 0f21e858 | 2013-01-11 11:06:56 | [diff] [blame] | 48 | namespace content { |
| 49 | |
[email protected] | 94224ba6 | 2014-02-04 00:25:24 | [diff] [blame] | 50 | class BrowserPlugin; |
[email protected] | 0d25cb6 | 2013-01-21 15:42:21 | [diff] [blame] | 51 | class BrowserPluginManager; |
[email protected] | bffc830 | 2014-01-23 20:52:16 | [diff] [blame] | 52 | class RenderFrameImpl; |
[email protected] | 0d25cb6 | 2013-01-21 15:42:21 | [diff] [blame] | 53 | |
[email protected] | bffc830 | 2014-01-23 20:52:16 | [diff] [blame] | 54 | class CONTENT_EXPORT ChildFrameCompositingHelper |
| 55 | : public base::RefCounted<ChildFrameCompositingHelper>, |
| 56 | public cc::DelegatedFrameResourceCollectionClient { |
[email protected] | 0f21e858 | 2013-01-11 11:06:56 | [diff] [blame] | 57 | public: |
[email protected] | bffc830 | 2014-01-23 20:52:16 | [diff] [blame] | 58 | static ChildFrameCompositingHelper* CreateCompositingHelperForBrowserPlugin( |
[email protected] | 94224ba6 | 2014-02-04 00:25:24 | [diff] [blame] | 59 | const base::WeakPtr<BrowserPlugin>& browser_plugin); |
[email protected] | bffc830 | 2014-01-23 20:52:16 | [diff] [blame] | 60 | static ChildFrameCompositingHelper* CreateCompositingHelperForRenderFrame( |
| 61 | blink::WebFrame* frame, |
| 62 | RenderFrameImpl* render_frame, |
| 63 | int host_routing_id); |
| 64 | |
[email protected] | 73405fb | 2013-12-11 04:59:37 | [diff] [blame] | 65 | void CopyFromCompositingSurface(int request_id, |
| 66 | gfx::Rect source_rect, |
| 67 | gfx::Size dest_size); |
[email protected] | f5b4b0f | 2013-04-02 18:16:28 | [diff] [blame] | 68 | void DidCommitCompositorFrame(); |
[email protected] | 0f21e858 | 2013-01-11 11:06:56 | [diff] [blame] | 69 | void EnableCompositing(bool); |
[email protected] | 0d25cb6 | 2013-01-21 15:42:21 | [diff] [blame] | 70 | void OnContainerDestroy(); |
[email protected] | 0f21e858 | 2013-01-11 11:06:56 | [diff] [blame] | 71 | void OnBuffersSwapped(const gfx::Size& size, |
[email protected] | 7c6c09e | 2014-02-15 00:16:17 | [diff] [blame] | 72 | const gpu::Mailbox& mailbox, |
[email protected] | 0f21e858 | 2013-01-11 11:06:56 | [diff] [blame] | 73 | int gpu_route_id, |
[email protected] | 19fa81a0 | 2013-03-04 18:23:32 | [diff] [blame] | 74 | int gpu_host_id, |
| 75 | float device_scale_factor); |
[email protected] | f5b4b0f | 2013-04-02 18:16:28 | [diff] [blame] | 76 | void OnCompositorFrameSwapped(scoped_ptr<cc::CompositorFrame> frame, |
| 77 | int route_id, |
[email protected] | 53b4cc1 | 2013-07-18 23:02:30 | [diff] [blame] | 78 | uint32 output_surface_id, |
[email protected] | f5b4b0f | 2013-04-02 18:16:28 | [diff] [blame] | 79 | int host_id); |
[email protected] | 69b7912 | 2013-02-14 19:16:45 | [diff] [blame] | 80 | void UpdateVisibility(bool); |
[email protected] | f49722f | 2014-01-30 17:54:50 | [diff] [blame] | 81 | void ChildFrameGone(); |
[email protected] | b0030b7 | 2013-11-15 20:35:53 | [diff] [blame] | 82 | |
| 83 | // cc::DelegatedFrameProviderClient implementation. |
| 84 | virtual void UnusedResourcesAreAvailable() OVERRIDE; |
[email protected] | 6d3a46e | 2013-11-25 23:08:53 | [diff] [blame] | 85 | void SetContentsOpaque(bool); |
[email protected] | b0030b7 | 2013-11-15 20:35:53 | [diff] [blame] | 86 | |
[email protected] | 0d25cb6 | 2013-01-21 15:42:21 | [diff] [blame] | 87 | protected: |
| 88 | // Friend RefCounted so that the dtor can be non-public. |
[email protected] | bffc830 | 2014-01-23 20:52:16 | [diff] [blame] | 89 | friend class base::RefCounted<ChildFrameCompositingHelper>; |
| 90 | |
[email protected] | 0f21e858 | 2013-01-11 11:06:56 | [diff] [blame] | 91 | private: |
[email protected] | 94224ba6 | 2014-02-04 00:25:24 | [diff] [blame] | 92 | ChildFrameCompositingHelper( |
| 93 | const base::WeakPtr<BrowserPlugin>& browser_plugin, |
| 94 | blink::WebFrame* frame, |
| 95 | RenderFrameImpl* render_frame, |
| 96 | int host_routing_id); |
[email protected] | bffc830 | 2014-01-23 20:52:16 | [diff] [blame] | 97 | |
[email protected] | 9f39c20 | 2013-06-18 16:06:42 | [diff] [blame] | 98 | enum SwapBuffersType { |
[email protected] | c049b2e | 2013-06-11 04:39:30 | [diff] [blame] | 99 | TEXTURE_IMAGE_TRANSPORT, |
[email protected] | 9f39c20 | 2013-06-18 16:06:42 | [diff] [blame] | 100 | GL_COMPOSITOR_FRAME, |
| 101 | SOFTWARE_COMPOSITOR_FRAME, |
[email protected] | c049b2e | 2013-06-11 04:39:30 | [diff] [blame] | 102 | }; |
[email protected] | 9f39c20 | 2013-06-18 16:06:42 | [diff] [blame] | 103 | struct SwapBuffersInfo { |
| 104 | SwapBuffersInfo(); |
| 105 | |
[email protected] | c049b2e | 2013-06-11 04:39:30 | [diff] [blame] | 106 | gpu::Mailbox name; |
[email protected] | 9f39c20 | 2013-06-18 16:06:42 | [diff] [blame] | 107 | SwapBuffersType type; |
[email protected] | c049b2e | 2013-06-11 04:39:30 | [diff] [blame] | 108 | gfx::Size size; |
| 109 | int route_id; |
[email protected] | 53b4cc1 | 2013-07-18 23:02:30 | [diff] [blame] | 110 | uint32 output_surface_id; |
[email protected] | c049b2e | 2013-06-11 04:39:30 | [diff] [blame] | 111 | int host_id; |
[email protected] | 9f39c20 | 2013-06-18 16:06:42 | [diff] [blame] | 112 | unsigned software_frame_id; |
| 113 | base::SharedMemory* shared_memory; |
[email protected] | c049b2e | 2013-06-11 04:39:30 | [diff] [blame] | 114 | }; |
[email protected] | bffc830 | 2014-01-23 20:52:16 | [diff] [blame] | 115 | virtual ~ChildFrameCompositingHelper(); |
[email protected] | 94224ba6 | 2014-02-04 00:25:24 | [diff] [blame] | 116 | |
| 117 | BrowserPluginManager* GetBrowserPluginManager(); |
| 118 | blink::WebPluginContainer* GetContainer(); |
| 119 | int GetInstanceID(); |
| 120 | |
[email protected] | bffc830 | 2014-01-23 20:52:16 | [diff] [blame] | 121 | void SendCompositorFrameSwappedACKToBrowser( |
| 122 | FrameHostMsg_CompositorFrameSwappedACK_Params& params); |
| 123 | void SendBuffersSwappedACKToBrowser( |
| 124 | FrameHostMsg_BuffersSwappedACK_Params& params); |
| 125 | void SendReclaimCompositorResourcesToBrowser( |
| 126 | FrameHostMsg_ReclaimCompositorResources_Params& params); |
[email protected] | 6d3a46e | 2013-11-25 23:08:53 | [diff] [blame] | 127 | void CheckSizeAndAdjustLayerProperties(const gfx::Size& new_size, |
| 128 | float device_scale_factor, |
| 129 | cc::Layer* layer); |
[email protected] | 9f39c20 | 2013-06-18 16:06:42 | [diff] [blame] | 130 | void OnBuffersSwappedPrivate(const SwapBuffersInfo& mailbox, |
[email protected] | c049b2e | 2013-06-11 04:39:30 | [diff] [blame] | 131 | unsigned sync_point, |
| 132 | float device_scale_factor); |
[email protected] | 9f39c20 | 2013-06-18 16:06:42 | [diff] [blame] | 133 | void MailboxReleased(SwapBuffersInfo mailbox, |
[email protected] | 7ba3ca7 | 2013-04-11 06:37:25 | [diff] [blame] | 134 | unsigned sync_point, |
| 135 | bool lost_resource); |
[email protected] | b0030b7 | 2013-11-15 20:35:53 | [diff] [blame] | 136 | void SendReturnedDelegatedResources(); |
[email protected] | 73405fb | 2013-12-11 04:59:37 | [diff] [blame] | 137 | void CopyFromCompositingSurfaceHasResult( |
| 138 | int request_id, |
| 139 | gfx::Size dest_size, |
| 140 | scoped_ptr<cc::CopyOutputResult> result); |
[email protected] | b0030b7 | 2013-11-15 20:35:53 | [diff] [blame] | 141 | |
[email protected] | 0f21e858 | 2013-01-11 11:06:56 | [diff] [blame] | 142 | int host_routing_id_; |
[email protected] | f5b4b0f | 2013-04-02 18:16:28 | [diff] [blame] | 143 | int last_route_id_; |
[email protected] | 53b4cc1 | 2013-07-18 23:02:30 | [diff] [blame] | 144 | uint32 last_output_surface_id_; |
[email protected] | f5b4b0f | 2013-04-02 18:16:28 | [diff] [blame] | 145 | int last_host_id_; |
[email protected] | 0f21e858 | 2013-01-11 11:06:56 | [diff] [blame] | 146 | bool last_mailbox_valid_; |
[email protected] | 0d25cb6 | 2013-01-21 15:42:21 | [diff] [blame] | 147 | bool ack_pending_; |
[email protected] | 9afdaef | 2013-09-26 07:24:37 | [diff] [blame] | 148 | bool software_ack_pending_; |
[email protected] | 6d3a46e | 2013-11-25 23:08:53 | [diff] [blame] | 149 | bool opaque_; |
[email protected] | 9afdaef | 2013-09-26 07:24:37 | [diff] [blame] | 150 | std::vector<unsigned> unacked_software_frames_; |
[email protected] | 0f21e858 | 2013-01-11 11:06:56 | [diff] [blame] | 151 | |
[email protected] | c2bfe4e | 2013-01-16 01:10:20 | [diff] [blame] | 152 | gfx::Size buffer_size_; |
[email protected] | c2bfe4e | 2013-01-16 01:10:20 | [diff] [blame] | 153 | |
[email protected] | bdca9be2 | 2014-02-18 00:37:49 | [diff] [blame^] | 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 | RenderFrameImpl* render_frame_; |
| 159 | |
[email protected] | 09f6738 | 2013-10-09 21:03:45 | [diff] [blame] | 160 | scoped_refptr<cc::DelegatedFrameResourceCollection> resource_collection_; |
| 161 | scoped_refptr<cc::DelegatedFrameProvider> frame_provider_; |
| 162 | |
[email protected] | 396fbb7 | 2013-01-23 02:33:43 | [diff] [blame] | 163 | scoped_refptr<cc::SolidColorLayer> background_layer_; |
[email protected] | 0f21e858 | 2013-01-11 11:06:56 | [diff] [blame] | 164 | scoped_refptr<cc::TextureLayer> texture_layer_; |
[email protected] | f5b4b0f | 2013-04-02 18:16:28 | [diff] [blame] | 165 | scoped_refptr<cc::DelegatedRendererLayer> delegated_layer_; |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 166 | scoped_ptr<blink::WebLayer> web_layer_; |
[email protected] | bffc830 | 2014-01-23 20:52:16 | [diff] [blame] | 167 | blink::WebFrame* frame_; |
[email protected] | 0d25cb6 | 2013-01-21 15:42:21 | [diff] [blame] | 168 | |
[email protected] | bffc830 | 2014-01-23 20:52:16 | [diff] [blame] | 169 | DISALLOW_COPY_AND_ASSIGN(ChildFrameCompositingHelper); |
[email protected] | 0f21e858 | 2013-01-11 11:06:56 | [diff] [blame] | 170 | }; |
| 171 | |
| 172 | } // namespace content |
| 173 | |
[email protected] | bffc830 | 2014-01-23 20:52:16 | [diff] [blame] | 174 | #endif // CONTENT_RENDERER_CHILD_FRAME_COMPOSITING_HELPER_H_ |