Flutter Engine
texture.h
Go to the documentation of this file.
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_COMMON_GRAPHICS_TEXTURE_H_
6 #define FLUTTER_COMMON_GRAPHICS_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 #include "third_party/skia/include/core/SkSamplingOptions.h"
14 
15 class GrDirectContext;
16 
17 namespace flutter {
18 
19 class Texture {
20  public:
21  explicit Texture(int64_t id); // Called from UI or raster thread.
22  virtual ~Texture(); // Called from raster thread.
23 
24  // Called from raster thread.
25  virtual void Paint(SkCanvas& canvas,
26  const SkRect& bounds,
27  bool freeze,
28  GrDirectContext* context,
29  const SkSamplingOptions& sampling) = 0;
30 
31  // Called from raster thread.
32  virtual void OnGrContextCreated() = 0;
33 
34  // Called from raster thread.
35  virtual void OnGrContextDestroyed() = 0;
36 
37  // Called on raster thread.
38  virtual void MarkNewFrameAvailable() = 0;
39 
40  // Called on raster thread.
41  virtual void OnTextureUnregistered() = 0;
42 
43  int64_t Id() { return id_; }
44 
45  private:
46  int64_t id_;
47 
48  FML_DISALLOW_COPY_AND_ASSIGN(Texture);
49 };
50 
52  public:
54 
55  // Called from raster thread.
56  void RegisterTexture(std::shared_ptr<Texture> texture);
57 
58  // Called from raster thread.
59  void UnregisterTexture(int64_t id);
60 
61  // Called from raster thread.
62  std::shared_ptr<Texture> GetTexture(int64_t id);
63 
64  // Called from raster thread.
65  void OnGrContextCreated();
66 
67  // Called from raster thread.
68  void OnGrContextDestroyed();
69 
70  private:
71  std::map<int64_t, std::shared_ptr<Texture>> mapping_;
72 
74 };
75 
76 } // namespace flutter
77 
78 #endif // FLUTTER_COMMON_GRAPHICS_TEXTURE_H_
int64_t Id()
Definition: texture.h:43
G_BEGIN_DECLS FlTexture * texture
static void UnregisterTexture(JNIEnv *env, jobject jcaller, jlong shell_holder, jlong texture_id)
virtual void OnTextureUnregistered()=0
virtual void OnGrContextDestroyed()=0
virtual void MarkNewFrameAvailable()=0
virtual ~Texture()
virtual void OnGrContextCreated()=0
virtual void Paint(SkCanvas &canvas, const SkRect &bounds, bool freeze, GrDirectContext *context, const SkSamplingOptions &sampling)=0
static void RegisterTexture(JNIEnv *env, jobject jcaller, jlong shell_holder, jlong texture_id, jobject surface_texture)
#define FML_DISALLOW_COPY_AND_ASSIGN(TypeName)
Definition: macros.h:27
Texture(int64_t id)
Definition: texture.cc:9