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,size_t size)29 virtual bool GLContextSendSurface(const void* pixels, size_t size) { return false; }; 30 31 // The ID of the main window bound framebuffer. Typically FBO0. 32 virtual intptr_t GLContextFBO() const = 0; 33 34 // The rendering subsystem assumes that the ID of the main window bound 35 // framebuffer remains constant throughout. If this assumption in incorrect, 36 // embedders are required to return true from this method. In such cases, 37 // GLContextFBO() will be called again to acquire the new FBO ID for rendering 38 // subsequent frames. 39 virtual bool GLContextFBOResetAfterPresent() const; 40 41 // Create an offscreen surface to render into before onscreen composition. 42 virtual bool UseOffscreenSurface() const; 43 44 // A transformation applied to the onscreen surface before the canvas is 45 // flushed. 46 virtual SkMatrix GLContextSurfaceTransformation() const; 47 48 // Get a reference to the external views embedder. This happens on the same 49 // thread that the renderer is operating on. 50 virtual ExternalViewEmbedder* GetExternalViewEmbedder() = 0; 51 52 sk_sp<const GrGLInterface> GetGLInterface() const; 53 54 // TODO(chinmaygarde): The presence of this method is to work around the fact 55 // that not all platforms can accept a custom GL proc table. Migrate all 56 // platforms to move GL proc resolution to the embedder and remove this 57 // method. 58 static sk_sp<const GrGLInterface> GetDefaultPlatformGLInterface(); 59 60 using GLProcResolver = 61 std::function<void* /* proc name */ (const char* /* proc address */)>; 62 // Provide a custom GL proc resolver. If no such resolver is present, Skia 63 // will attempt to do GL proc address resolution on its own. Embedders that 64 // have specific opinions on GL API selection or need to add their own 65 // instrumentation to specific GL calls can specify custom GL functions 66 // here. 67 virtual GLProcResolver GetGLProcResolver() const; 68 }; 69 70 } // namespace flutter 71 72 #endif // FLUTTER_SHELL_GPU_GPU_SURFACE_GL_DELEGATE_H_ 73