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_GPU_GPU_SURFACE_GL_DELEGATE_H_ 6 #define FLUTTER_SHELL_GPU_GPU_SURFACE_GL_DELEGATE_H_ 7 8 #include "flutter/flow/embedded_views.h" 9 #include "flutter/fml/macros.h" 10 #include "third_party/skia/include/core/SkMatrix.h" 11 #include "third_party/skia/include/gpu/gl/GrGLInterface.h" 12 13 namespace flutter { 14 15 class GPUSurfaceGLDelegate { 16 public: 17 // Called to make the main GL context current on the current thread. 18 virtual bool GLContextMakeCurrent() = 0; 19 20 // Called to clear the current GL context on the thread. This may be called on 21 // either the GPU or IO threads. 22 virtual bool GLContextClearCurrent() = 0; 23 24 // Called to present the main GL surface. This is only called for the main GL 25 // context and not any of the contexts dedicated for IO. 26 virtual bool GLContextPresent() = 0; 27 28 // For PC preivew GLContextSendSurface(const void * pixels,const size_t size,const int32_t width,const int32_t height)29 virtual bool GLContextSendSurface(const void* pixels, 30 const size_t size, 31 const int32_t width, 32 const int32_t height) { 33 return false; 34 }; 35 36 // The ID of the main window bound framebuffer. Typically FBO0. 37 virtual intptr_t GLContextFBO() const = 0; 38 39 // The rendering subsystem assumes that the ID of the main window bound 40 // framebuffer remains constant throughout. If this assumption in incorrect, 41 // embedders are required to return true from this method. In such cases, 42 // GLContextFBO() will be called again to acquire the new FBO ID for rendering 43 // subsequent frames. 44 virtual bool GLContextFBOResetAfterPresent() const; 45 46 // Create an offscreen surface to render into before onscreen composition. 47 virtual bool UseOffscreenSurface() const; 48 49 // A transformation applied to the onscreen surface before the canvas is 50 // flushed. 51 virtual SkMatrix GLContextSurfaceTransformation() const; 52 53 // Get a reference to the external views embedder. This happens on the same 54 // thread that the renderer is operating on. 55 virtual ExternalViewEmbedder* GetExternalViewEmbedder() = 0; 56 57 sk_sp<const GrGLInterface> GetGLInterface() const; 58 59 // TODO(chinmaygarde): The presence of this method is to work around the fact 60 // that not all platforms can accept a custom GL proc table. Migrate all 61 // platforms to move GL proc resolution to the embedder and remove this 62 // method. 63 static sk_sp<const GrGLInterface> GetDefaultPlatformGLInterface(); 64 65 using GLProcResolver = 66 std::function<void* /* proc name */ (const char* /* proc address */)>; 67 // Provide a custom GL proc resolver. If no such resolver is present, Skia 68 // will attempt to do GL proc address resolution on its own. Embedders that 69 // have specific opinions on GL API selection or need to add their own 70 // instrumentation to specific GL calls can specify custom GL functions 71 // here. 72 virtual GLProcResolver GetGLProcResolver() const; 73 }; 74 75 } // namespace flutter 76 77 #endif // FLUTTER_SHELL_GPU_GPU_SURFACE_GL_DELEGATE_H_ 78