aw_gl_surface.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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_AW_GL_SURFACE_H_
  5. #define ANDROID_WEBVIEW_BROWSER_GFX_AW_GL_SURFACE_H_
  6. #include "ui/gfx/geometry/rect.h"
  7. #include "ui/gfx/geometry/transform.h"
  8. #include "ui/gl/gl_display.h"
  9. #include "ui/gl/gl_surface_egl.h"
  10. namespace android_webview {
  11. // This surface is used to represent the underlying surface provided by the App
  12. // inside a hardware draw. Note that offscreen contexts will not be using this
  13. // GLSurface.
  14. class AwGLSurface : public gl::GLSurfaceEGL {
  15. public:
  16. AwGLSurface(gl::GLDisplayEGL* display, bool is_angle);
  17. AwGLSurface(gl::GLDisplayEGL* display, scoped_refptr<gl::GLSurface> surface);
  18. AwGLSurface(const AwGLSurface&) = delete;
  19. AwGLSurface& operator=(const AwGLSurface&) = delete;
  20. // Implement GLSurface.
  21. bool Initialize(gl::GLSurfaceFormat format) override;
  22. void Destroy() override;
  23. bool IsOffscreen() override;
  24. unsigned int GetBackingFramebufferObject() override;
  25. gfx::SwapResult SwapBuffers(PresentationCallback callback) override;
  26. bool OnMakeCurrent(gl::GLContext* context) override;
  27. gfx::Size GetSize() override;
  28. void* GetHandle() override;
  29. gl::GLDisplay* GetGLDisplay() override;
  30. gl::GLSurfaceFormat GetFormat() override;
  31. bool Resize(const gfx::Size& size,
  32. float scale_factor,
  33. const gfx::ColorSpace& color_space,
  34. bool has_alpha) override;
  35. EGLConfig GetConfig() override;
  36. void SetSize(const gfx::Size& size);
  37. void MaybeDidPresent(const gfx::PresentationFeedback& feedback);
  38. virtual void RecalculateClipAndTransform(gfx::Size* viewport,
  39. gfx::Rect* clip_rect,
  40. gfx::Transform* transform) {}
  41. // Returns true if this GLSurface created fbo to implement stencil clipping.
  42. // This doesn't take into account if fbo was created by Android.
  43. virtual bool IsDrawingToFBO();
  44. protected:
  45. ~AwGLSurface() override;
  46. private:
  47. const bool is_angle_;
  48. // This is used when when webview is compositing with vulkan. There are still
  49. // random code that expect to a real EGL context to be present to eg run
  50. // glGetError. A real EGL context requires a real EGL surface.
  51. // Note this is currently mutually exclusive with `is_angle_`.
  52. const scoped_refptr<gl::GLSurface> wrapped_surface_;
  53. PresentationCallback pending_presentation_callback_;
  54. gfx::Size size_{1, 1};
  55. EGLSurface surface_ = nullptr;
  56. };
  57. } // namespace android_webview
  58. #endif // ANDROID_WEBVIEW_BROWSER_GFX_AW_GL_SURFACE_H_