Home | History | Annotate | Download | only in browser
      1 // Copyright 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 ANDROID_WEBVIEW_PUBLIC_BROWSER_DRAW_GL_H_
      6 #define ANDROID_WEBVIEW_PUBLIC_BROWSER_DRAW_GL_H_
      7 
      8 #ifdef __cplusplus
      9 extern "C" {
     10 #endif
     11 
     12 static const int kAwDrawGLInfoVersion = 1;
     13 
     14 // Holds the information required to trigger an OpenGL drawing operation.
     15 struct AwDrawGLInfo {
     16   int version;  // The AwDrawGLInfo this struct was built with.
     17 
     18   // Input: tells the draw function what action to perform.
     19   enum Mode {
     20     kModeDraw = 0,
     21     kModeProcess,
     22     kModeProcessNoContext,
     23     kModeSync,
     24   } mode;
     25 
     26   // Input: current clip rect in surface coordinates. Reflects the current state
     27   // of the OpenGL scissor rect. Both the OpenGL scissor rect and viewport are
     28   // set by the caller of the draw function and updated during View animations.
     29   int clip_left;
     30   int clip_top;
     31   int clip_right;
     32   int clip_bottom;
     33 
     34   // Input: current width/height of destination surface.
     35   int width;
     36   int height;
     37 
     38   // Input: is the View rendered into an independent layer.
     39   // If false, the surface is likely to hold to the full screen contents, with
     40   // the scissor box set by the caller to the actual View location and size.
     41   // Also the transformation matrix will contain at least a translation to the
     42   // position of the View to render, plus any other transformations required as
     43   // part of any ongoing View animation. View translucency (alpha) is ignored,
     44   // although the framework will set is_layer to true for non-opaque cases.
     45   // Can be requested via the View.setLayerType(View.LAYER_TYPE_NONE, ...)
     46   // Android API method.
     47   //
     48   // If true, the surface is dedicated to the View and should have its size.
     49   // The viewport and scissor box are set by the caller to the whole surface.
     50   // Animation transformations are handled by the caller and not reflected in
     51   // the provided transformation matrix. Translucency works normally.
     52   // Can be requested via the View.setLayerType(View.LAYER_TYPE_HARDWARE, ...)
     53   // Android API method.
     54   bool is_layer;
     55 
     56   // Input: current transformation matrix in surface pixels.
     57   // Uses the column-based OpenGL matrix format.
     58   float transform[16];
     59 };
     60 
     61 // Function to invoke a direct GL draw into the client's pre-configured
     62 // GL context. Obtained via AwContents.getDrawGLFunction() (static).
     63 // |view_context| is an opaque identifier that was returned by the corresponding
     64 // call to AwContents.getAwDrawGLViewContext().
     65 // |draw_info| carries the in and out parameters for this draw.
     66 // |spare| ignored; pass NULL.
     67 typedef void (AwDrawGLFunction)(long view_context,
     68                                 AwDrawGLInfo* draw_info,
     69                                 void* spare);
     70 enum AwMapMode {
     71   MAP_READ_ONLY,
     72   MAP_WRITE_ONLY,
     73   MAP_READ_WRITE,
     74 };
     75 
     76 // Called to create a GraphicBuffer
     77 typedef long AwCreateGraphicBufferFunction(int w, int h);
     78 // Called to release a GraphicBuffer
     79 typedef void AwReleaseGraphicBufferFunction(long buffer_id);
     80 // Called to map a GraphicBuffer in |mode|.
     81 typedef int AwMapFunction(long buffer_id, AwMapMode mode, void** vaddr);
     82 // Called to unmap a GraphicBuffer
     83 typedef int AwUnmapFunction(long buffer_id);
     84 // Called to get a native buffer pointer
     85 typedef void* AwGetNativeBufferFunction(long buffer_id);
     86 // Called to get the stride of the buffer
     87 typedef unsigned int AwGetStrideFunction(long buffer_id);
     88 
     89 static const int kAwDrawGLFunctionTableVersion = 1;
     90 
     91 // Set of functions used in rendering in hardware mode
     92 struct AwDrawGLFunctionTable {
     93   int version;
     94   AwCreateGraphicBufferFunction* create_graphic_buffer;
     95   AwReleaseGraphicBufferFunction* release_graphic_buffer;
     96   AwMapFunction* map;
     97   AwUnmapFunction* unmap;
     98   AwGetNativeBufferFunction* get_native_buffer;
     99   AwGetStrideFunction* get_stride;
    100 };
    101 
    102 #ifdef __cplusplus
    103 }  // extern "C"
    104 #endif
    105 
    106 #endif  // ANDROID_WEBVIEW_PUBLIC_BROWSER_DRAW_GL_H_
    107