- add sources.
[platform/framework/web/crosswalk.git] / src / content / public / browser / android / compositor.h
1 // Copyright (c) 2012 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_PUBLIC_BROWSER_ANDROID_COMPOSITOR_H_
6 #define CONTENT_PUBLIC_BROWSER_ANDROID_COMPOSITOR_H_
7
8 #include "base/callback.h"
9 #include "cc/resources/ui_resource_bitmap.h"
10 #include "cc/resources/ui_resource_client.h"
11 #include "content/common/content_export.h"
12 #include "ui/gfx/native_widget_types.h"
13 #include "ui/gfx/rect.h"
14 #include "ui/gfx/size.h"
15
16 #include "third_party/WebKit/public/platform/WebGraphicsContext3D.h"
17
18 namespace cc {
19 class Layer;
20 }
21
22 namespace gfx {
23 class JavaBitmap;
24 }
25
26 namespace content {
27 class CompositorClient;
28
29 // An interface to the browser-side compositor.
30 class CONTENT_EXPORT Compositor {
31  public:
32   virtual ~Compositor() {}
33
34   // Performs the global initialization needed before any compositor
35   // instance can be used. This should be called only once.
36   static void Initialize();
37
38   // Creates and returns a compositor instance.
39   static Compositor* Create(CompositorClient* client);
40
41   // Attaches the layer tree.
42   virtual void SetRootLayer(scoped_refptr<cc::Layer> root) = 0;
43
44   // Set the scale factor from DIP to pixel.
45   virtual void setDeviceScaleFactor(float factor) = 0;
46
47   // Set the output surface bounds.
48   virtual void SetWindowBounds(const gfx::Size& size) = 0;
49
50   // Sets the window visibility. When becoming invisible, resources will get
51   // freed and other calls into the compositor are not allowed until after
52   // having been made visible again.
53   virtual void SetVisible(bool visible) = 0;
54
55   // Set the output surface handle which the compositor renders into.
56   // DEPRECATED: Use SetSurface() which takes a Java Surface object.
57   virtual void SetWindowSurface(ANativeWindow* window) = 0;
58
59   // Set the output surface which the compositor renders into.
60   virtual void SetSurface(jobject surface) = 0;
61
62   // Attempts to composite and read back the result into the provided buffer.
63   // The buffer must be at least window width * height * 4 (RGBA) bytes large.
64   // The buffer is not modified if false is returned.
65   virtual bool CompositeAndReadback(void *pixels, const gfx::Rect& rect) = 0;
66
67   // Composite immediately. Used in single-threaded mode.
68   virtual void Composite() = 0;
69
70   // Generates a UIResource and returns a UIResourceId.  May return 0.
71   virtual cc::UIResourceId GenerateUIResource(
72       const cc::UIResourceBitmap& bitmap) = 0;
73
74   // Deletes a UIResource.
75   virtual void DeleteUIResource(cc::UIResourceId resource_id) = 0;
76
77   // Generates an OpenGL texture and returns a texture handle.  May return 0
78   // if the current context is lost.
79   virtual WebKit::WebGLId GenerateTexture(gfx::JavaBitmap& bitmap) = 0;
80
81   // Generates an OpenGL compressed texture and returns a texture handle.  May
82   // return 0 if the current context is lost.
83   virtual WebKit::WebGLId GenerateCompressedTexture(gfx::Size& size,
84                                                     int data_size,
85                                                     void* data) = 0;
86
87   // Deletes an OpenGL texture.
88   virtual void DeleteTexture(WebKit::WebGLId texture_id) = 0;
89
90   // Grabs a copy of |texture_id| and saves it into |bitmap|.  No scaling is
91   // done.  It is assumed that the texture size matches that of the bitmap.
92   virtual bool CopyTextureToBitmap(WebKit::WebGLId texture_id,
93                                    gfx::JavaBitmap& bitmap) = 0;
94
95   // Grabs a copy of |texture_id| and saves it into |bitmap|.  No scaling is
96   // done. |src_rect| allows the caller to specify which rect of |texture_id|
97   // to copy to |bitmap|.  It needs to match the size of |bitmap|.  Returns
98   // true if the |texture_id| was copied into |bitmap|, false if not.
99   virtual bool CopyTextureToBitmap(WebKit::WebGLId texture_id,
100                                    const gfx::Rect& src_rect,
101                                    gfx::JavaBitmap& bitmap) = 0;
102  protected:
103   Compositor() {}
104 };
105
106 }  // namespace content
107
108 #endif  // CONTENT_PUBLIC_BROWSER_ANDROID_COMPOSITOR_H_