compositor.h revision 5821806d5e7f356e8fa4b058a389a808ea183019
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 gfx { 17class JavaBitmap; 18} 19 20namespace WebKit { 21class WebLayer; 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. 42 static void Initialize(); 43 44 // Creates and returns a compositor instance. 45 static Compositor* Create(Client* client); 46 47 // Attaches the layer tree. 48 virtual void SetRootLayer(WebKit::WebLayer* root) = 0; 49 50 // Set the output surface bounds. 51 virtual void SetWindowBounds(const gfx::Size& size) = 0; 52 53 // Set the output surface handle which the compositor renders into. 54 virtual void SetWindowSurface(ANativeWindow* window) = 0; 55 56 // Attempts to composite and read back the result into the provided buffer. 57 // The buffer must be at least window width * height * 4 (RGBA) bytes large. 58 // The buffer is not modified if false is returned. 59 virtual bool CompositeAndReadback(void *pixels, const gfx::Rect& rect) = 0; 60 61 // Composite immediately. Used in single-threaded mode. 62 virtual void Composite() = 0; 63 64 // Generates an OpenGL texture and returns a texture handle. May return 0 65 // if the current context is lost. 66 virtual WebKit::WebGLId GenerateTexture(gfx::JavaBitmap& bitmap) = 0; 67 68 // Generates an OpenGL compressed texture and returns a texture handle. May 69 // return 0 if the current context is lost. 70 virtual WebKit::WebGLId GenerateCompressedTexture(gfx::Size& size, 71 int data_size, 72 void* data) = 0; 73 74 // Deletes an OpenGL texture. 75 virtual void DeleteTexture(WebKit::WebGLId texture_id) = 0; 76 77 // Grabs a copy of |texture_id| and saves it into |bitmap|. No scaling is 78 // done. It is assumed that the texture size matches that of the bitmap. 79 virtual void CopyTextureToBitmap(WebKit::WebGLId texture_id, 80 gfx::JavaBitmap& bitmap) = 0; 81 protected: 82 Compositor() {} 83}; 84 85} // namespace content 86 87#endif // CONTENT_PUBLIC_BROWSER_ANDROID_COMPOSITOR_H_ 88