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