• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 //******************************************************************************
6 // This is a copy of the coresponding android_webview/public/browser header.
7 // Any changes to the interface should be made there.
8 //
9 // The purpose of having the copy is twofold:
10 //  - it removes the need to have Chromium sources present in the tree in order
11 //    to build the plat_support library,
12 //  - it captures API that the corresponding Android release supports.
13 //******************************************************************************
14 
15 #ifndef ANDROID_WEBVIEW_PUBLIC_BROWSER_DRAW_GL_H_
16 #define ANDROID_WEBVIEW_PUBLIC_BROWSER_DRAW_GL_H_
17 
18 #ifdef __cplusplus
19 extern "C" {
20 #endif
21 
22 
23 // 1 is L/L MR1
24 //
25 // 2 starts at M, and added an imperfect workaround for complex clipping by
26 // elevating the WebView into an FBO layer. If any transform, clip, or outline
27 // clip occurs that would either likely use the stencil buffer for clipping, or
28 // require shader based clipping in HWUI, the WebView is drawn into an FBO (if
29 // it fits).
30 // This is a temporary workaround for a lack of WebView support for stencil/
31 // shader based round rect clipping, and should be removed when webview is
32 // capable of supporting these clips internally when drawing.
33 static const int kAwDrawGLInfoVersion = 2;
34 
35 // Holds the information required to trigger an OpenGL drawing operation.
36 struct AwDrawGLInfo {
37   int version;  // The AwDrawGLInfo this struct was built with.
38 
39   // Input: tells the draw function what action to perform.
40   enum Mode {
41     kModeDraw = 0,
42     kModeProcess,
43     kModeProcessNoContext,
44     kModeSync,
45   } mode;
46 
47   // Input: current clip rect in surface coordinates. Reflects the current state
48   // of the OpenGL scissor rect. Both the OpenGL scissor rect and viewport are
49   // set by the caller of the draw function and updated during View animations.
50   int clip_left;
51   int clip_top;
52   int clip_right;
53   int clip_bottom;
54 
55   // Input: current width/height of destination surface.
56   int width;
57   int height;
58 
59   // Input: is the View rendered into an independent layer.
60   // If false, the surface is likely to hold to the full screen contents, with
61   // the scissor box set by the caller to the actual View location and size.
62   // Also the transformation matrix will contain at least a translation to the
63   // position of the View to render, plus any other transformations required as
64   // part of any ongoing View animation. View translucency (alpha) is ignored,
65   // although the framework will set is_layer to true for non-opaque cases.
66   // Can be requested via the View.setLayerType(View.LAYER_TYPE_NONE, ...)
67   // Android API method.
68   //
69   // If true, the surface is dedicated to the View and should have its size.
70   // The viewport and scissor box are set by the caller to the whole surface.
71   // Animation transformations are handled by the caller and not reflected in
72   // the provided transformation matrix. Translucency works normally.
73   // Can be requested via the View.setLayerType(View.LAYER_TYPE_HARDWARE, ...)
74   // Android API method.
75   bool is_layer;
76 
77   // Input: current transformation matrix in surface pixels.
78   // Uses the column-based OpenGL matrix format.
79   float transform[16];
80 };
81 
82 // Function to invoke a direct GL draw into the client's pre-configured
83 // GL context. Obtained via AwContents.getDrawGLFunction() (static).
84 // |view_context| is an opaque identifier that was returned by the corresponding
85 // call to AwContents.getAwDrawGLViewContext().
86 // |draw_info| carries the in and out parameters for this draw.
87 // |spare| ignored; pass NULL.
88 typedef void (AwDrawGLFunction)(long view_context,
89                                 AwDrawGLInfo* draw_info,
90                                 void* spare);
91 enum AwMapMode {
92   MAP_READ_ONLY,
93   MAP_WRITE_ONLY,
94   MAP_READ_WRITE,
95 };
96 
97 // Called to create a GraphicBuffer
98 typedef long AwCreateGraphicBufferFunction(int w, int h);
99 // Called to release a GraphicBuffer
100 typedef void AwReleaseGraphicBufferFunction(long buffer_id);
101 // Called to map a GraphicBuffer in |mode|.
102 typedef int AwMapFunction(long buffer_id, AwMapMode mode, void** vaddr);
103 // Called to unmap a GraphicBuffer
104 typedef int AwUnmapFunction(long buffer_id);
105 // Called to get a native buffer pointer
106 typedef void* AwGetNativeBufferFunction(long buffer_id);
107 // Called to get the stride of the buffer
108 typedef unsigned int AwGetStrideFunction(long buffer_id);
109 
110 static const int kAwDrawGLFunctionTableVersion = 1;
111 
112 // Set of functions used in rendering in hardware mode
113 struct AwDrawGLFunctionTable {
114   int version;
115   AwCreateGraphicBufferFunction* create_graphic_buffer;
116   AwReleaseGraphicBufferFunction* release_graphic_buffer;
117   AwMapFunction* map;
118   AwUnmapFunction* unmap;
119   AwGetNativeBufferFunction* get_native_buffer;
120   AwGetStrideFunction* get_stride;
121 };
122 
123 #ifdef __cplusplus
124 }  // extern "C"
125 #endif
126 
127 #endif  // ANDROID_WEBVIEW_PUBLIC_BROWSER_DRAW_GL_H_
128