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