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_FLOW_TEXTURE_H_ 6 #define FLUTTER_FLOW_TEXTURE_H_ 7 8 #include <map> 9 10 #include "flutter/fml/macros.h" 11 #include "flutter/fml/synchronization/waitable_event.h" 12 #include "third_party/skia/include/core/SkCanvas.h" 13 14 namespace flutter { 15 16 class Texture { 17 protected: 18 Texture(int64_t id); 19 20 public: 21 // Called from GPU thread. 22 virtual ~Texture(); 23 24 // Called from GPU thread. 25 virtual void Paint(SkCanvas& canvas, 26 const SkRect& bounds, 27 bool freeze, 28 GrContext* context) = 0; 29 30 // Called from GPU thread. 31 virtual void OnGrContextCreated() = 0; 32 33 // Called from GPU thread. 34 virtual void OnGrContextDestroyed() = 0; 35 36 // Called on GPU thread. 37 virtual void MarkNewFrameAvailable() = 0; 38 Id()39 int64_t Id() { return id_; } 40 41 private: 42 int64_t id_; 43 44 FML_DISALLOW_COPY_AND_ASSIGN(Texture); 45 }; 46 47 class TextureRegistry { 48 public: 49 TextureRegistry(); 50 ~TextureRegistry(); 51 52 // Called from GPU thread. 53 void RegisterTexture(std::shared_ptr<Texture> texture); 54 55 // Called from GPU thread. 56 void UnregisterTexture(int64_t id); 57 58 // Called from GPU thread. 59 std::shared_ptr<Texture> GetTexture(int64_t id); 60 61 // Called from GPU thread. 62 void OnGrContextCreated(); 63 64 // Called from GPU thread. 65 void OnGrContextDestroyed(); 66 67 private: 68 std::map<int64_t, std::shared_ptr<Texture>> mapping_; 69 70 FML_DISALLOW_COPY_AND_ASSIGN(TextureRegistry); 71 }; 72 73 } // namespace flutter 74 75 #endif // FLUTTER_FLOW_TEXTURE_H_ 76