Flutter Engine
 
Loading...
Searching...
No Matches
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
11#include "flutter/fml/macros.h"
13
14class GrDirectContext;
15
16namespace impeller {
17class AiksContext;
18};
19
20namespace flutter {
21
23 public:
26
27 // Called from raster thread.
28 virtual void OnGrContextCreated() = 0;
29
30 // Called from raster thread.
31 virtual void OnGrContextDestroyed() = 0;
32
33 private:
35};
36
37class Texture : public ContextListener {
38 public:
39 struct PaintContext {
40 DlCanvas* canvas = nullptr;
41 GrDirectContext* gr_context = nullptr;
43 const DlPaint* paint = nullptr;
44 };
45
46 explicit Texture(int64_t id); // Called from UI or raster thread.
47 virtual ~Texture(); // Called from raster thread.
48
49 // Called from raster thread.
50 virtual void Paint(PaintContext& context,
51 const DlRect& bounds,
52 bool freeze,
53 const DlImageSampling sampling) = 0;
54
55 // Called on raster thread.
56 virtual void MarkNewFrameAvailable() = 0;
57
58 // Called on raster thread.
59 virtual void OnTextureUnregistered() = 0;
60
61 int64_t Id() { return id_; }
62
63 private:
64 int64_t id_;
66};
67
69 public:
71
72 // Called from raster thread.
73 void RegisterTexture(const std::shared_ptr<Texture>& texture);
74
75 // Called from raster thread.
76 void RegisterContextListener(uintptr_t id,
77 std::weak_ptr<ContextListener> image);
78
79 // Called from raster thread.
80 void UnregisterTexture(int64_t id);
81
82 // Called from the raster thread.
83 void UnregisterContextListener(uintptr_t id);
84
85 // Called from raster thread.
86 std::shared_ptr<Texture> GetTexture(int64_t id);
87
88 // Called from raster thread.
89 void OnGrContextCreated();
90
91 // Called from raster thread.
93
94 private:
95 std::map<int64_t, std::shared_ptr<Texture>> mapping_;
96 size_t image_counter_ = 0;
97 // This map keeps track of registered context listeners by their own
98 // externally provided id. It indexes into ordered_images_.
99 std::map<uintptr_t, size_t> image_indices_;
100 // This map makes sure that iteration of images happens in insertion order
101 // (managed by image_counter_) so that images which depend on other images get
102 // re-created in the right order.
103 using InsertionOrderMap =
104 std::map<size_t, std::pair<uintptr_t, std::weak_ptr<ContextListener>>>;
105 InsertionOrderMap ordered_images_;
106
108};
109
110} // namespace flutter
111
112#endif // FLUTTER_COMMON_GRAPHICS_TEXTURE_H_
virtual void OnGrContextCreated()=0
virtual void OnGrContextDestroyed()=0
Developer-facing API for rendering anything within the engine.
Definition dl_canvas.h:32
virtual ~Texture()
virtual void OnTextureUnregistered()=0
virtual void MarkNewFrameAvailable()=0
virtual void Paint(PaintContext &context, const DlRect &bounds, bool freeze, const DlImageSampling sampling)=0
int64_t Id()
Definition texture.h:61
void RegisterTexture(const std::shared_ptr< Texture > &texture)
Definition texture.cc:19
void UnregisterContextListener(uintptr_t id)
Definition texture.cc:47
void RegisterContextListener(uintptr_t id, std::weak_ptr< ContextListener > image)
Definition texture.cc:26
std::shared_ptr< Texture > GetTexture(int64_t id)
Definition texture.cc:93
void UnregisterTexture(int64_t id)
Definition texture.cc:38
FlutterVulkanImage * image
#define FML_DISALLOW_COPY_AND_ASSIGN(TypeName)
Definition macros.h:27
FlTexture * texture
impeller::AiksContext * aiks_context
Definition texture.h:42
GrDirectContext * gr_context
Definition texture.h:41