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_COMMON_SURFACE_H_ 6 #define FLUTTER_SHELL_COMMON_SURFACE_H_ 7 8 #include <memory> 9 10 #include "flutter/flow/compositor_context.h" 11 #include "flutter/flow/embedded_views.h" 12 #include "flutter/fml/macros.h" 13 #include "third_party/skia/include/core/SkCanvas.h" 14 15 namespace flutter { 16 17 /// Represents a Frame that has been fully configured for the underlying client 18 /// rendering API. A frame may only be submitted once. 19 class SurfaceFrame { 20 public: 21 using SubmitCallback = 22 std::function<bool(const SurfaceFrame& surface_frame, SkCanvas* canvas)>; 23 24 SurfaceFrame(sk_sp<SkSurface> surface, SubmitCallback submit_callback); 25 26 ~SurfaceFrame(); 27 28 bool Submit(); 29 30 SkCanvas* SkiaCanvas(); 31 32 sk_sp<SkSurface> SkiaSurface() const; 33 34 private: 35 bool submitted_; 36 sk_sp<SkSurface> surface_; 37 SubmitCallback submit_callback_; 38 39 bool PerformSubmit(); 40 41 FML_DISALLOW_COPY_AND_ASSIGN(SurfaceFrame); 42 }; 43 44 /// Abstract Base Class that represents where we will be rendering content. 45 class Surface { 46 public: 47 Surface(); 48 49 virtual ~Surface(); 50 51 virtual bool IsValid() = 0; 52 53 virtual std::unique_ptr<SurfaceFrame> AcquireFrame(const SkISize& size) = 0; 54 55 virtual SkMatrix GetRootTransformation() const = 0; 56 57 virtual GrContext* GetContext() = 0; 58 59 virtual flutter::ExternalViewEmbedder* GetExternalViewEmbedder(); 60 61 virtual bool MakeRenderContextCurrent(); 62 63 private: 64 FML_DISALLOW_COPY_AND_ASSIGN(Surface); 65 }; 66 67 } // namespace flutter 68 69 #endif // FLUTTER_SHELL_COMMON_SURFACE_H_ 70