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