1 // Copyright 2013 The Flutter 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 FLUTTER_SHELL_PLATFORM_EMBEDDER_EMBEDDER_SURFACE_GL_H_ 6 #define FLUTTER_SHELL_PLATFORM_EMBEDDER_EMBEDDER_SURFACE_GL_H_ 7 8 #include "flutter/fml/macros.h" 9 #include "flutter/shell/gpu/gpu_surface_gl.h" 10 #include "flutter/shell/platform/embedder/embedder_external_view_embedder.h" 11 #include "flutter/shell/platform/embedder/embedder_surface.h" 12 13 namespace flutter { 14 15 class EmbedderSurfaceGL final : public EmbedderSurface, 16 public GPUSurfaceGLDelegate { 17 public: 18 struct GLDispatchTable { 19 std::function<bool(void)> gl_make_current_callback; // required 20 std::function<bool(void)> gl_clear_current_callback; // required 21 std::function<bool(void)> gl_present_callback; // required 22 // for PC preview, optional 23 std::function<bool(const void*, const size_t, const int32_t, const int32_t)> gl_send_surface_callback; 24 std::function<intptr_t(void)> gl_fbo_callback; // required 25 std::function<bool(void)> gl_make_resource_current_callback; // optional 26 std::function<SkMatrix(void)> 27 gl_surface_transformation_callback; // optional 28 std::function<void*(const char*)> gl_proc_resolver; // optional 29 }; 30 31 EmbedderSurfaceGL( 32 GLDispatchTable gl_dispatch_table, 33 bool fbo_reset_after_present, 34 std::unique_ptr<EmbedderExternalViewEmbedder> external_view_embedder); 35 36 ~EmbedderSurfaceGL() override; 37 38 private: 39 bool valid_ = false; 40 GLDispatchTable gl_dispatch_table_; 41 bool fbo_reset_after_present_; 42 43 std::unique_ptr<EmbedderExternalViewEmbedder> external_view_embedder_; 44 45 // |EmbedderSurface| 46 bool IsValid() const override; 47 48 // |EmbedderSurface| 49 std::unique_ptr<Surface> CreateGPUSurface() override; 50 51 // |EmbedderSurface| 52 sk_sp<GrContext> CreateResourceContext() const override; 53 54 // |GPUSurfaceGLDelegate| 55 bool GLContextMakeCurrent() override; 56 57 // |GPUSurfaceGLDelegate| 58 bool GLContextClearCurrent() override; 59 60 // |GPUSurfaceGLDelegate| 61 bool GLContextPresent() override; 62 63 // |GPUSurfaceGLDelegate| 64 bool GLContextSendSurface(const void* pixels, size_t size, int32_t width, int32_t height) override; 65 66 // |GPUSurfaceGLDelegate| 67 intptr_t GLContextFBO() const override; 68 69 // |GPUSurfaceGLDelegate| 70 bool GLContextFBOResetAfterPresent() const override; 71 72 // |GPUSurfaceGLDelegate| 73 SkMatrix GLContextSurfaceTransformation() const override; 74 75 // |GPUSurfaceGLDelegate| 76 ExternalViewEmbedder* GetExternalViewEmbedder() override; 77 78 // |GPUSurfaceGLDelegate| 79 GLProcResolver GetGLProcResolver() const override; 80 81 FML_DISALLOW_COPY_AND_ASSIGN(EmbedderSurfaceGL); 82 }; 83 84 } // namespace flutter 85 86 #endif // FLUTTER_SHELL_PLATFORM_EMBEDDER_EMBEDDER_SURFACE_GL_H_ 87