1 // Copyright (c) 2013 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_BROWSER_PLUGIN_BROWSER_PLUGIN_COMPOSITING_HELPER_H_ 6 #define CONTENT_RENDERER_BROWSER_PLUGIN_BROWSER_PLUGIN_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 "cc/layers/delegated_frame_resource_collection.h" 14 #include "content/common/content_export.h" 15 #include "gpu/command_buffer/common/mailbox.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 TextureLayer; 28 class DelegatedFrameProvider; 29 class DelegatedFrameResourceCollection; 30 class DelegatedRendererLayer; 31 } 32 33 namespace blink { 34 class WebPluginContainer; 35 class WebLayer; 36 } 37 38 namespace gfx { 39 class Rect; 40 class Size; 41 } 42 43 namespace content { 44 45 class BrowserPluginManager; 46 47 class CONTENT_EXPORT BrowserPluginCompositingHelper : 48 public base::RefCounted<BrowserPluginCompositingHelper>, 49 public cc::DelegatedFrameResourceCollectionClient { 50 public: 51 BrowserPluginCompositingHelper(blink::WebPluginContainer* container, 52 BrowserPluginManager* manager, 53 int instance_id, 54 int host_routing_id); 55 void CopyFromCompositingSurface(int request_id, 56 gfx::Rect source_rect, 57 gfx::Size dest_size); 58 void DidCommitCompositorFrame(); 59 void EnableCompositing(bool); 60 void OnContainerDestroy(); 61 void OnBuffersSwapped(const gfx::Size& size, 62 const std::string& mailbox_name, 63 int gpu_route_id, 64 int gpu_host_id, 65 float device_scale_factor); 66 void OnCompositorFrameSwapped(scoped_ptr<cc::CompositorFrame> frame, 67 int route_id, 68 uint32 output_surface_id, 69 int host_id); 70 void UpdateVisibility(bool); 71 72 // cc::DelegatedFrameProviderClient implementation. 73 virtual void UnusedResourcesAreAvailable() OVERRIDE; 74 void SetContentsOpaque(bool); 75 76 protected: 77 // Friend RefCounted so that the dtor can be non-public. 78 friend class base::RefCounted<BrowserPluginCompositingHelper>; 79 private: 80 enum SwapBuffersType { 81 TEXTURE_IMAGE_TRANSPORT, 82 GL_COMPOSITOR_FRAME, 83 SOFTWARE_COMPOSITOR_FRAME, 84 }; 85 struct SwapBuffersInfo { 86 SwapBuffersInfo(); 87 88 gpu::Mailbox name; 89 SwapBuffersType type; 90 gfx::Size size; 91 int route_id; 92 uint32 output_surface_id; 93 int host_id; 94 unsigned software_frame_id; 95 base::SharedMemory* shared_memory; 96 }; 97 virtual ~BrowserPluginCompositingHelper(); 98 void CheckSizeAndAdjustLayerProperties(const gfx::Size& new_size, 99 float device_scale_factor, 100 cc::Layer* layer); 101 void OnBuffersSwappedPrivate(const SwapBuffersInfo& mailbox, 102 unsigned sync_point, 103 float device_scale_factor); 104 void MailboxReleased(SwapBuffersInfo mailbox, 105 unsigned sync_point, 106 bool lost_resource); 107 void SendReturnedDelegatedResources(); 108 void CopyFromCompositingSurfaceHasResult( 109 int request_id, 110 gfx::Size dest_size, 111 scoped_ptr<cc::CopyOutputResult> result); 112 113 int instance_id_; 114 int host_routing_id_; 115 int last_route_id_; 116 uint32 last_output_surface_id_; 117 int last_host_id_; 118 bool last_mailbox_valid_; 119 bool ack_pending_; 120 bool software_ack_pending_; 121 bool opaque_; 122 std::vector<unsigned> unacked_software_frames_; 123 124 gfx::Size buffer_size_; 125 126 scoped_refptr<cc::DelegatedFrameResourceCollection> resource_collection_; 127 scoped_refptr<cc::DelegatedFrameProvider> frame_provider_; 128 129 scoped_refptr<cc::SolidColorLayer> background_layer_; 130 scoped_refptr<cc::TextureLayer> texture_layer_; 131 scoped_refptr<cc::DelegatedRendererLayer> delegated_layer_; 132 scoped_ptr<blink::WebLayer> web_layer_; 133 blink::WebPluginContainer* container_; 134 135 scoped_refptr<BrowserPluginManager> browser_plugin_manager_; 136 }; 137 138 } // namespace content 139 140 #endif // CONTENT_RENDERER_BROWSER_PLUGIN_BROWSER_PLUGIN_COMPOSITING_HELPER_H_ 141