| 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::kSource);
45 auto snapshot = yuv_to_rgb_filter_contents->RenderToSnapshot(
46 aiks_context->GetContentContext(), // renderer
47 entity, // entity
48 std::nullopt, // coverage_limit
49 std::nullopt, // sampler_descriptor
50 true, // msaa_enabled
51 /*mip_count=*/1,
52 "MakeYUVToRGBFilter Snapshot"); // label
53 if (!snapshot.has_value()) {
54 return nullptr;
55 }
56 return impeller::DlImageImpeller::Make(snapshot->texture);
57 }
58
59 DlImageImpeller::DlImageImpeller(std::shared_ptr<Texture> texture,
60 OwningContext owning_context
61 #ifdef FML_OS_IOS_SIMULATOR
62 ,
63 bool is_fake_image
64 #endif // FML_OS_IOS_SIMULATOR
65 )
66 : texture_(std::move(texture)),
67 owning_context_(owning_context)
68 #ifdef FML_OS_IOS_SIMULATOR
69 ,
70 is_fake_image_(is_fake_image)
71 #endif // #ifdef FML_OS_IOS_SIMULATOR
72 {
73 }
74
75 // |DlImage|
76 DlImageImpeller::~DlImageImpeller() = default;
77
78 // |DlImage|
79 sk_sp<SkImage> DlImageImpeller::skia_image() const {
80 return nullptr;
81 };
82
83 // |DlImage|
84 std::shared_ptr<impeller::Texture> DlImageImpeller::impeller_texture() const {
85 return texture_;
86 }
87
88 // |DlImage|
89 bool DlImageImpeller::isOpaque() const {
90 // Impeller doesn't currently implement opaque alpha types.
91 return false;
92 }
93
94 // |DlImage|
95 bool DlImageImpeller::isTextureBacked() const {
96 // Impeller textures are always ... textures :/
97 return true;
98 }
99
100 // |DlImage|
101 bool DlImageImpeller::isUIThreadSafe() const {
102 // Impeller textures are always thread-safe
103 return true;
104 }
105
106 // |DlImage|
107 SkISize DlImageImpeller::dimensions() const {
108 const auto size = texture_ ? texture_->GetSize() : ISize{};
109 return SkISize::Make(size.width, size.height);
110 }
111
112 // |DlImage|
113 size_t DlImageImpeller::GetApproximateByteSize() const {
114 auto size = sizeof(*this);
115 if (texture_) {
116 size += texture_->GetTextureDescriptor().GetByteSizeOfBaseMipLevel();
117 }
118 return size;
119 }
120
121 } // namespace impeller
aiks_context.h
impeller::AiksContext
Definition: aiks_context.h:19
impeller::AiksContext::GetContentContext
ContentContext & GetContentContext() const
Definition: aiks_context.cc:42
impeller::DlImageImpeller
Definition: dl_image_impeller.h:15
impeller::DlImageImpeller::GetApproximateByteSize
size_t GetApproximateByteSize() const override
Definition: dl_image_impeller.cc:113
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:95
impeller::DlImageImpeller::impeller_texture
std::shared_ptr< impeller::Texture > impeller_texture() const override
Definition: dl_image_impeller.cc:84
impeller::DlImageImpeller::dimensions
SkISize dimensions() const override
Definition: dl_image_impeller.cc:107
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::skia_image
sk_sp< SkImage > skia_image() const override
Definition: dl_image_impeller.cc:79
impeller::DlImageImpeller::~DlImageImpeller
~DlImageImpeller() override
impeller::DlImageImpeller::isUIThreadSafe
bool isUIThreadSafe() const override
Definition: dl_image_impeller.cc:101
impeller::DlImageImpeller::isOpaque
bool isOpaque() const override
Definition: dl_image_impeller.cc:89
impeller::DlImageImpeller::owning_context
OwningContext owning_context() const override
Definition: dl_image_impeller.h:57
impeller::Entity
Definition: entity.h:20
impeller::Entity::SetBlendMode
void SetBlendMode(BlendMode blend_mode)
Definition: entity.cc:97
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:108
dl_image_impeller.h
filter_contents.h
impeller
Definition: allocation.cc:12
impeller::YUVColorSpace
YUVColorSpace
Definition: color.h:54
impeller::BlendMode::kSource
@ kSource
std
Definition: comparable.h:95
impeller::TSize
Definition: size.h:25