Re-enable index-basics-workers test to see if still times
[chromium-blink-merge.git] / content / public / browser / android / compositor.h
blobb6a5352b007fc8aa5fc74214a9f17096ad049ea6
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.
5 #ifndef CONTENT_PUBLIC_BROWSER_ANDROID_COMPOSITOR_H_
6 #define CONTENT_PUBLIC_BROWSER_ANDROID_COMPOSITOR_H_
8 #include "base/callback.h"
9 #include "content/common/content_export.h"
10 #include "ui/gfx/native_widget_types.h"
11 #include "ui/gfx/rect.h"
12 #include "ui/gfx/size.h"
14 #include "third_party/WebKit/Source/Platform/chromium/public/WebGraphicsContext3D.h"
16 namespace cc {
17 class Layer;
20 namespace gfx {
21 class JavaBitmap;
24 namespace content {
26 // An interface to the browser-side compositor.
27 class CONTENT_EXPORT Compositor {
28 public:
29 class Client {
30 public:
31 // Tells the client that it should schedule a composite.
32 virtual void ScheduleComposite() = 0;
34 // The compositor has completed swapping a frame.
35 virtual void OnSwapBuffersCompleted() {}
37 // The compositor will eventually swap a frame.
38 virtual void OnSwapBuffersPosted() {}
41 virtual ~Compositor() {}
43 // Performs the global initialization needed before any compositor
44 // instance can be used. This should be called only once.
45 static void Initialize();
47 enum CompositorFlags {
48 // Creates a direct GL context on the thread that draws
49 // (i.e. main or impl thread).
50 DIRECT_CONTEXT_ON_DRAW_THREAD = 1,
52 // Runs the compositor in threaded mode.
53 ENABLE_COMPOSITOR_THREAD = 1 << 1,
56 // Initialize with flags. This should only be called once instead
57 // of Initialize().
58 static void InitializeWithFlags(uint32 flags);
60 // Creates and returns a compositor instance.
61 static Compositor* Create(Client* client);
63 // Attaches the layer tree.
64 virtual void SetRootLayer(scoped_refptr<cc::Layer> root) = 0;
66 // Set the scale factor from DIP to pixel.
67 virtual void setDeviceScaleFactor(float factor) = 0;
69 // Set the output surface bounds.
70 virtual void SetWindowBounds(const gfx::Size& size) = 0;
72 // Sets the window visibility. When becoming invisible, resources will get
73 // freed and other calls into the compositor are not allowed until after
74 // having been made visible again.
75 virtual void SetVisible(bool visible) = 0;
77 // Set the output surface handle which the compositor renders into.
78 // DEPRECATED: Use SetSurface() which takes a Java Surface object.
79 virtual void SetWindowSurface(ANativeWindow* window) = 0;
81 // Set the output surface which the compositor renders into.
82 virtual void SetSurface(jobject surface) = 0;
84 // Tells the view tree to assume a transparent background when rendering.
85 virtual void SetHasTransparentBackground(bool flag) = 0;
87 // Attempts to composite and read back the result into the provided buffer.
88 // The buffer must be at least window width * height * 4 (RGBA) bytes large.
89 // The buffer is not modified if false is returned.
90 virtual bool CompositeAndReadback(void *pixels, const gfx::Rect& rect) = 0;
92 // Invalidate the whole viewport.
93 virtual void SetNeedsRedraw() = 0;
95 // Composite immediately. Used in single-threaded mode.
96 virtual void Composite() = 0;
98 // Generates an OpenGL texture and returns a texture handle. May return 0
99 // if the current context is lost.
100 virtual WebKit::WebGLId GenerateTexture(gfx::JavaBitmap& bitmap) = 0;
102 // Generates an OpenGL compressed texture and returns a texture handle. May
103 // return 0 if the current context is lost.
104 virtual WebKit::WebGLId GenerateCompressedTexture(gfx::Size& size,
105 int data_size,
106 void* data) = 0;
108 // Deletes an OpenGL texture.
109 virtual void DeleteTexture(WebKit::WebGLId texture_id) = 0;
111 // Grabs a copy of |texture_id| and saves it into |bitmap|. No scaling is
112 // done. It is assumed that the texture size matches that of the bitmap.
113 virtual bool CopyTextureToBitmap(WebKit::WebGLId texture_id,
114 gfx::JavaBitmap& bitmap) = 0;
116 // Grabs a copy of |texture_id| and saves it into |bitmap|. No scaling is
117 // done. |src_rect| allows the caller to specify which rect of |texture_id|
118 // to copy to |bitmap|. It needs to match the size of |bitmap|. Returns
119 // true if the |texture_id| was copied into |bitmap|, false if not.
120 virtual bool CopyTextureToBitmap(WebKit::WebGLId texture_id,
121 const gfx::Rect& src_rect,
122 gfx::JavaBitmap& bitmap) = 0;
123 protected:
124 Compositor() {}
127 } // namespace content
129 #endif // CONTENT_PUBLIC_BROWSER_ANDROID_COMPOSITOR_H_