draw_gl.h 4.7 KB

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