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