compositor.h revision 2a99a7e74a7f215066514fe81d2bfa6639d9eddd
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 "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" 13 14#include "third_party/WebKit/Source/Platform/chromium/public/WebGraphicsContext3D.h" 15 16namespace cc { 17class Layer; 18} 19 20namespace gfx { 21class JavaBitmap; 22} 23 24namespace content { 25 26// An interface to the browser-side compositor. 27class 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; 33 34 // The compositor has completed swapping a frame. 35 virtual void OnSwapBuffersCompleted() {} 36 }; 37 38 virtual ~Compositor() {} 39 40 // Performs the global initialization needed before any compositor 41 // instance can be used. This should be called only once. 42 static void Initialize(); 43 44 enum CompositorFlags { 45 // Creates a direct GL context on the thread that draws 46 // (i.e. main or impl thread). 47 DIRECT_CONTEXT_ON_DRAW_THREAD = 1, 48 49 // Runs the compositor in threaded mode. 50 ENABLE_COMPOSITOR_THREAD = 1 << 1, 51 }; 52 53 // Initialize with flags. This should only be called once instead 54 // of Initialize(). 55 static void InitializeWithFlags(uint32 flags); 56 57 // Creates and returns a compositor instance. 58 static Compositor* Create(Client* client); 59 60 // Attaches the layer tree. 61 virtual void SetRootLayer(scoped_refptr<cc::Layer> root) = 0; 62 63 // Set the scale factor from DIP to pixel. 64 virtual void setDeviceScaleFactor(float factor) = 0; 65 66 // Set the output surface bounds. 67 virtual void SetWindowBounds(const gfx::Size& size) = 0; 68 69 // Sets the window visibility. When becoming invisible, resources will get 70 // freed and other calls into the compositor are not allowed until after 71 // having been made visible again. 72 virtual void SetVisible(bool visible) = 0; 73 74 // Set the output surface handle which the compositor renders into. 75 // DEPRECATED: Use SetSurface() which takes a Java Surface object. 76 virtual void SetWindowSurface(ANativeWindow* window) = 0; 77 78 // Set the output surface which the compositor renders into. 79 virtual void SetSurface(jobject surface) = 0; 80 81 // Tells the view tree to assume a transparent background when rendering. 82 virtual void SetHasTransparentBackground(bool flag) = 0; 83 84 // Attempts to composite and read back the result into the provided buffer. 85 // The buffer must be at least window width * height * 4 (RGBA) bytes large. 86 // The buffer is not modified if false is returned. 87 virtual bool CompositeAndReadback(void *pixels, const gfx::Rect& rect) = 0; 88 89 // Composite immediately. Used in single-threaded mode. 90 virtual void Composite() = 0; 91 92 // Generates an OpenGL texture and returns a texture handle. May return 0 93 // if the current context is lost. 94 virtual WebKit::WebGLId GenerateTexture(gfx::JavaBitmap& bitmap) = 0; 95 96 // Generates an OpenGL compressed texture and returns a texture handle. May 97 // return 0 if the current context is lost. 98 virtual WebKit::WebGLId GenerateCompressedTexture(gfx::Size& size, 99 int data_size, 100 void* data) = 0; 101 102 // Deletes an OpenGL texture. 103 virtual void DeleteTexture(WebKit::WebGLId texture_id) = 0; 104 105 // Grabs a copy of |texture_id| and saves it into |bitmap|. No scaling is 106 // done. It is assumed that the texture size matches that of the bitmap. 107 virtual bool CopyTextureToBitmap(WebKit::WebGLId texture_id, 108 gfx::JavaBitmap& bitmap) = 0; 109 110 // Grabs a copy of |texture_id| and saves it into |bitmap|. No scaling is 111 // done. |src_rect| allows the caller to specify which rect of |texture_id| 112 // to copy to |bitmap|. It needs to match the size of |bitmap|. Returns 113 // true if the |texture_id| was copied into |bitmap|, false if not. 114 virtual bool CopyTextureToBitmap(WebKit::WebGLId texture_id, 115 const gfx::Rect& src_rect, 116 gfx::JavaBitmap& bitmap) = 0; 117 protected: 118 Compositor() {} 119}; 120 121} // namespace content 122 123#endif // CONTENT_PUBLIC_BROWSER_ANDROID_COMPOSITOR_H_ 124