| Flutter Impeller |

dl_image_impeller.cc
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 #include "impeller/display_list/dl_image_impeller.h"
6
7 #include "impeller/display_list/aiks_context.h"
8 #include "impeller/entity/contents/filters/filter_contents.h"
9
10 namespace impeller {
11
12 #if FML_OS_IOS_SIMULATOR
13 sk_sp<DlImageImpeller> DlImageImpeller::Make(std::shared_ptr<Texture> texture,
14 OwningContext owning_context,
15 bool is_fake_image) {
16 if (!texture && !is_fake_image) {
17 return nullptr;
18 }
19 return sk_sp<DlImageImpeller>(
20 new DlImageImpeller(std::move(texture), owning_context, is_fake_image));
21 }
22 #else
23 sk_sp<DlImageImpeller> DlImageImpeller::Make(std::shared_ptr<Texture> texture,
24 OwningContext owning_context) {
25 if (!texture) {
26 return nullptr;
27 }
28 return sk_sp<DlImageImpeller>(
29 new DlImageImpeller(std::move(texture), owning_context));
30 }
31 #endif // FML_OS_IOS_SIMULATOR
32
33 sk_sp<DlImageImpeller> DlImageImpeller::MakeFromYUVTextures(
34 AiksContext* aiks_context,
35 std::shared_ptr<Texture> y_texture,
36 std::shared_ptr<Texture> uv_texture,
37 YUVColorSpace yuv_color_space) {
38 if (!aiks_context || !y_texture || !uv_texture) {
39 return nullptr;
40 }
41 auto yuv_to_rgb_filter_contents = FilterContents::MakeYUVToRGBFilter(
42 std::move(y_texture), std::move(uv_texture), yuv_color_space);
43 impeller::Entity entity;
44 entity.SetBlendMode(impeller::BlendMode::kSrc);
45
46 // Disable the render target cache so that this snapshot's texture will not
47 // be reused later by other operations.
48 const auto& renderer = aiks_context->GetContentContext();
49 renderer.GetRenderTargetCache()->DisableCache();
50 fml::ScopedCleanupClosure restore_cache(
51 [&] { renderer.GetRenderTargetCache()->EnableCache(); });
52
53 std::optional<Snapshot> snapshot =
54 yuv_to_rgb_filter_contents->RenderToSnapshot(
55 renderer, entity,
56 {.coverage_limit = std::nullopt,
57 .sampler_descriptor = std::nullopt,
58 .msaa_enabled = true,
59 .mip_count = 1,
60 .label = "MakeYUVToRGBFilter Snapshot"});
61 if (!snapshot.has_value()) {
62 return nullptr;
63 }
64 return impeller::DlImageImpeller::Make(snapshot->texture);
65 }
66
67 DlImageImpeller::DlImageImpeller(std::shared_ptr<Texture> texture,
68 OwningContext owning_context
69 #ifdef FML_OS_IOS_SIMULATOR
70 ,
71 bool is_fake_image
72 #endif // FML_OS_IOS_SIMULATOR
73 )
74 : texture_(std::move(texture)),
75 owning_context_(owning_context)
76 #ifdef FML_OS_IOS_SIMULATOR
77 ,
78 is_fake_image_(is_fake_image)
79 #endif // #ifdef FML_OS_IOS_SIMULATOR
80 {
81 }
82
83 // |DlImage|
84 DlImageImpeller::~DlImageImpeller() = default;
85
86 // |DlImage|
87 sk_sp<SkImage> DlImageImpeller::skia_image() const {
88 return nullptr;
89 };
90
91 // |DlImage|
92 std::shared_ptr<impeller::Texture> DlImageImpeller::impeller_texture() const {
93 return texture_;
94 }
95
96 // |DlImage|
97 bool DlImageImpeller::isOpaque() const {
98 // Impeller doesn't currently implement opaque alpha types.
99 return false;
100 }
101
102 // |DlImage|
103 bool DlImageImpeller::isTextureBacked() const {
104 // Impeller textures are always ... textures :/
105 return true;
106 }
107
108 // |DlImage|
109 bool DlImageImpeller::isUIThreadSafe() const {
110 // Impeller textures are always thread-safe
111 return true;
112 }
113
114 // |DlImage|
115 flutter::DlISize DlImageImpeller::GetSize() const {
116 // texture |GetSize()| returns a 64-bit size, but we need a 32-bit size,
117 // so we need to convert to DlISize (the 32-bit variant) either way.
118 return texture_ ? flutter::DlISize(texture_->GetSize()) : flutter::DlISize();
119 }
120
121 // |DlImage|
122 size_t DlImageImpeller::GetApproximateByteSize() const {
123 auto size = sizeof(*this);
124 if (texture_) {
125 size += texture_->GetTextureDescriptor().GetByteSizeOfBaseMipLevel();
126 }
127 return size;
128 }
129
130 } // namespace impeller
aiks_context.h
impeller::AiksContext
Definition: aiks_context.h:20
impeller::AiksContext::GetContentContext
ContentContext & GetContentContext() const
Definition: aiks_context.cc:42
impeller::ContentContext::GetRenderTargetCache
const std::shared_ptr< RenderTargetAllocator > & GetRenderTargetCache() const
Definition: content_context.h:270
impeller::DlImageImpeller
Definition: dl_image_impeller.h:15
impeller::DlImageImpeller::GetApproximateByteSize
size_t GetApproximateByteSize() const override
Definition: dl_image_impeller.cc:122
impeller::DlImageImpeller::MakeFromYUVTextures
static sk_sp< DlImageImpeller > MakeFromYUVTextures(AiksContext *aiks_context, std::shared_ptr< Texture > y_texture, std::shared_ptr< Texture > uv_texture, YUVColorSpace yuv_color_space)
Definition: dl_image_impeller.cc:33
impeller::DlImageImpeller::isTextureBacked
bool isTextureBacked() const override
Definition: dl_image_impeller.cc:103
impeller::DlImageImpeller::impeller_texture
std::shared_ptr< impeller::Texture > impeller_texture() const override
Definition: dl_image_impeller.cc:92
impeller::DlImageImpeller::Make
static sk_sp< DlImageImpeller > Make(std::shared_ptr< Texture > texture, OwningContext owning_context=OwningContext::kIO)
Definition: dl_image_impeller.cc:23
impeller::DlImageImpeller::GetSize
flutter::DlISize GetSize() const override
Definition: dl_image_impeller.cc:115
impeller::DlImageImpeller::skia_image
sk_sp< SkImage > skia_image() const override
Definition: dl_image_impeller.cc:87
impeller::DlImageImpeller::~DlImageImpeller
~DlImageImpeller() override
impeller::DlImageImpeller::isUIThreadSafe
bool isUIThreadSafe() const override
Definition: dl_image_impeller.cc:109
impeller::DlImageImpeller::isOpaque
bool isOpaque() const override
Definition: dl_image_impeller.cc:97
impeller::DlImageImpeller::owning_context
OwningContext owning_context() const override
Definition: dl_image_impeller.h:57
impeller::Entity
Definition: entity.h:26
impeller::Entity::SetBlendMode
void SetBlendMode(BlendMode blend_mode)
Definition: entity.cc:98
impeller::FilterContents::MakeYUVToRGBFilter
static std::shared_ptr< FilterContents > MakeYUVToRGBFilter(std::shared_ptr< Texture > y_texture, std::shared_ptr< Texture > uv_texture, YUVColorSpace yuv_color_space)
Definition: filter_contents.cc:107
dl_image_impeller.h
filter_contents.h
impeller
Definition: allocation.cc:12
impeller::YUVColorSpace
YUVColorSpace
Definition: color.h:54
impeller::BlendMode::kSrc
@ kSrc
std
Definition: comparable.h:95