- add sources.
[platform/framework/web/crosswalk.git] / src / content / renderer / browser_plugin / browser_plugin_compositing_helper.h
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 "content/common/content_export.h"
14 #include "gpu/command_buffer/common/mailbox.h"
15 #include "ui/gfx/size.h"
16
17 namespace base {
18 class SharedMemory;
19 }
20
21 namespace cc {
22 class CompositorFrame;
23 class Layer;
24 class SolidColorLayer;
25 class TextureLayer;
26 class DelegatedFrameProvider;
27 class DelegatedFrameResourceCollection;
28 class DelegatedRendererLayer;
29 }
30
31 namespace WebKit {
32 class WebPluginContainer;
33 class WebLayer;
34 }
35
36 namespace content {
37
38 class BrowserPluginManager;
39
40 class CONTENT_EXPORT BrowserPluginCompositingHelper :
41     public base::RefCounted<BrowserPluginCompositingHelper> {
42  public:
43   BrowserPluginCompositingHelper(WebKit::WebPluginContainer* container,
44                                  BrowserPluginManager* manager,
45                                  int instance_id,
46                                  int host_routing_id);
47   void DidCommitCompositorFrame();
48   void EnableCompositing(bool);
49   void OnContainerDestroy();
50   void OnBuffersSwapped(const gfx::Size& size,
51                         const std::string& mailbox_name,
52                         int gpu_route_id,
53                         int gpu_host_id,
54                         float device_scale_factor);
55   void OnCompositorFrameSwapped(scoped_ptr<cc::CompositorFrame> frame,
56                                 int route_id,
57                                 uint32 output_surface_id,
58                                 int host_id);
59   void UpdateVisibility(bool);
60  protected:
61   // Friend RefCounted so that the dtor can be non-public.
62   friend class base::RefCounted<BrowserPluginCompositingHelper>;
63  private:
64   enum SwapBuffersType {
65     TEXTURE_IMAGE_TRANSPORT,
66     GL_COMPOSITOR_FRAME,
67     SOFTWARE_COMPOSITOR_FRAME,
68   };
69   struct SwapBuffersInfo {
70     SwapBuffersInfo();
71
72     gpu::Mailbox name;
73     SwapBuffersType type;
74     gfx::Size size;
75     int route_id;
76     uint32 output_surface_id;
77     int host_id;
78     unsigned software_frame_id;
79     base::SharedMemory* shared_memory;
80   };
81   ~BrowserPluginCompositingHelper();
82   void CheckSizeAndAdjustLayerBounds(const gfx::Size& new_size,
83                                      float device_scale_factor,
84                                      cc::Layer* layer);
85   void OnBuffersSwappedPrivate(const SwapBuffersInfo& mailbox,
86                                unsigned sync_point,
87                                float device_scale_factor);
88   void MailboxReleased(SwapBuffersInfo mailbox,
89                        unsigned sync_point,
90                        bool lost_resource);
91   int instance_id_;
92   int host_routing_id_;
93   int last_route_id_;
94   uint32 last_output_surface_id_;
95   int last_host_id_;
96   bool last_mailbox_valid_;
97   bool ack_pending_;
98   bool software_ack_pending_;
99   std::vector<unsigned> unacked_software_frames_;
100
101   gfx::Size buffer_size_;
102
103   scoped_refptr<cc::DelegatedFrameResourceCollection> resource_collection_;
104   scoped_refptr<cc::DelegatedFrameProvider> frame_provider_;
105
106   scoped_refptr<cc::SolidColorLayer> background_layer_;
107   scoped_refptr<cc::TextureLayer> texture_layer_;
108   scoped_refptr<cc::DelegatedRendererLayer> delegated_layer_;
109   scoped_ptr<WebKit::WebLayer> web_layer_;
110   WebKit::WebPluginContainer* container_;
111
112   scoped_refptr<BrowserPluginManager> browser_plugin_manager_;
113 };
114
115 }  // namespace content
116
117 #endif  // CONTENT_RENDERER_BROWSER_PLUGIN_BROWSER_PLUGIN_COMPOSITING_HELPER_H_