Flutter Engine
The 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
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:
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_;
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
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:37
void RegisterTexture(const std::shared_ptr< Texture > &texture)
Definition texture.cc:19
std::shared_ptr< Texture > GetTexture(int64_t id)
Definition texture.cc:93
void UnregisterTexture(int64_t id)
Definition texture.cc:38
void UnregisterContextListener(uintptr_t id)
Definition texture.cc:47
void RegisterContextListener(uintptr_t id, std::weak_ptr< ContextListener > image)
Definition texture.cc:26
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
sk_sp< SkImage > image
Definition examples.cpp:29
#define FML_DISALLOW_COPY_AND_ASSIGN(TypeName)
Definition macros.h:27
FlTexture * texture
impeller::AiksContext * aiks_context
Definition texture.h:44
GrDirectContext * gr_context
Definition texture.h:43