scoped_app_gl_state_restore.h 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. // Copyright 2013 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_BROWSER_GFX_SCOPED_APP_GL_STATE_RESTORE_H_
  5. #define ANDROID_WEBVIEW_BROWSER_GFX_SCOPED_APP_GL_STATE_RESTORE_H_
  6. #include <memory>
  7. #include <vector>
  8. namespace android_webview {
  9. struct StencilState {
  10. unsigned char stencil_test_enabled;
  11. int stencil_front_func;
  12. int stencil_front_ref;
  13. int stencil_front_mask;
  14. int stencil_back_func;
  15. int stencil_back_ref;
  16. int stencil_back_mask;
  17. int stencil_clear;
  18. int stencil_front_writemask;
  19. int stencil_back_writemask;
  20. int stencil_front_fail_op;
  21. int stencil_front_z_fail_op;
  22. int stencil_front_z_pass_op;
  23. int stencil_back_fail_op;
  24. int stencil_back_z_fail_op;
  25. int stencil_back_z_pass_op;
  26. };
  27. // This class is not thread safe and should only be used on the UI thread.
  28. class ScopedAppGLStateRestore {
  29. public:
  30. enum CallMode {
  31. MODE_DRAW,
  32. MODE_RESOURCE_MANAGEMENT,
  33. };
  34. static ScopedAppGLStateRestore* Current();
  35. ScopedAppGLStateRestore(CallMode mode, bool save_restore);
  36. ScopedAppGLStateRestore(const ScopedAppGLStateRestore&) = delete;
  37. ScopedAppGLStateRestore& operator=(const ScopedAppGLStateRestore&) = delete;
  38. ~ScopedAppGLStateRestore();
  39. StencilState stencil_state() const;
  40. int framebuffer_binding_ext() const;
  41. // Android HWUI has a bug that asks functor to draw into a 8-bit mask for
  42. // functionality that is not related to and not needed by webview.
  43. // Skip this draw which is doing extra unnecessary work.
  44. bool skip_draw() const;
  45. class Impl {
  46. public:
  47. Impl();
  48. virtual ~Impl();
  49. const StencilState& stencil_state() const { return stencil_state_; }
  50. int framebuffer_binding_ext() const { return framebuffer_binding_ext_; }
  51. bool skip_draw() const { return skip_draw_; }
  52. protected:
  53. StencilState stencil_state_{};
  54. int framebuffer_binding_ext_ = 0;
  55. bool skip_draw_ = false;
  56. };
  57. private:
  58. std::unique_ptr<Impl> impl_;
  59. };
  60. } // namespace android_webview
  61. #endif // ANDROID_WEBVIEW_BROWSER_GFX_SCOPED_APP_GL_STATE_RESTORE_H_