| 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/aiks/aiks_context.h"
8 #include "impeller/entity/contents/filters/filter_contents.h"
9
10 namespace impeller {
11
12 sk_sp<DlImageImpeller> DlImageImpeller::Make(std::shared_ptr<Texture> texture,
13 OwningContext owning_context) {
14 if (!texture) {
15 return nullptr;
16 }
17 return sk_sp<DlImageImpeller>(
18 new DlImageImpeller(std::move(texture), owning_context));
19 }
20
21 sk_sp<DlImageImpeller> DlImageImpeller::MakeFromYUVTextures(
22 AiksContext* aiks_context,
23 std::shared_ptr<Texture> y_texture,
24 std::shared_ptr<Texture> uv_texture,
25 YUVColorSpace yuv_color_space) {
26 if (!aiks_context || !y_texture || !uv_texture) {
27 return nullptr;
28 }
29 auto yuv_to_rgb_filter_contents = FilterContents::MakeYUVToRGBFilter(
30 std::move(y_texture), std::move(uv_texture), yuv_color_space);
31 impeller::Entity entity;
32 entity.SetBlendMode(impeller::BlendMode::kSource);
33 auto snapshot = yuv_to_rgb_filter_contents->RenderToSnapshot(
34 aiks_context->GetContentContext(), // renderer
35 entity, // entity
36 std::nullopt, // coverage_limit
37 std::nullopt, // sampler_descriptor
38 true, // msaa_enabled
39 /*mip_count=*/1,
40 "MakeYUVToRGBFilter Snapshot"); // label
41 if (!snapshot.has_value()) {
42 return nullptr;
43 }
44 return impeller::DlImageImpeller::Make(snapshot->texture);
45 }
46
47 DlImageImpeller::DlImageImpeller(std::shared_ptr<Texture> texture,
48 OwningContext owning_context)
49 : texture_(std::move(texture)), owning_context_(owning_context) {}
50
51 // |DlImage|
52 DlImageImpeller::~DlImageImpeller() = default;
53
54 // |DlImage|
55 sk_sp<SkImage> DlImageImpeller::skia_image() const {
56 return nullptr;
57 };
58
59 // |DlImage|
60 std::shared_ptr<impeller::Texture> DlImageImpeller::impeller_texture() const {
61 return texture_;
62 }
63
64 // |DlImage|
65 bool DlImageImpeller::isOpaque() const {
66 // Impeller doesn't currently implement opaque alpha types.
67 return false;
68 }
69
70 // |DlImage|
71 bool DlImageImpeller::isTextureBacked() const {
72 // Impeller textures are always ... textures :/
73 return true;
74 }
75
76 // |DlImage|
77 bool DlImageImpeller::isUIThreadSafe() const {
78 // Impeller textures are always thread-safe
79 return true;
80 }
81
82 // |DlImage|
83 SkISize DlImageImpeller::dimensions() const {
84 const auto size = texture_ ? texture_->GetSize() : ISize{};
85 return SkISize::Make(size.width, size.height);
86 }
87
88 // |DlImage|
89 size_t DlImageImpeller::GetApproximateByteSize() const {
90 auto size = sizeof(*this);
91 if (texture_) {
92 size += texture_->GetTextureDescriptor().GetByteSizeOfBaseMipLevel();
93 }
94 return size;
95 }
96
97 } // namespace impeller
impeller::AiksContext
Definition: aiks_context.h:19
impeller::Entity::SetBlendMode
void SetBlendMode(BlendMode blend_mode)
Definition: entity.cc:115
impeller::AiksContext::GetContentContext
ContentContext & GetContentContext() const
Definition: aiks_context.cc:44
impeller::BlendMode::kSource
@ kSource
aiks_context.h
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:21
impeller::DlImageImpeller::isUIThreadSafe
bool isUIThreadSafe() const override
Definition: dl_image_impeller.cc:77
impeller::DlImageImpeller::dimensions
SkISize dimensions() const override
Definition: dl_image_impeller.cc:83
impeller::DlImageImpeller
Definition: dl_image_impeller.h:15
impeller::DlImageImpeller::Make
static sk_sp< DlImageImpeller > Make(std::shared_ptr< Texture > texture, OwningContext owning_context=OwningContext::kIO)
Definition: dl_image_impeller.cc:12
impeller::Entity
Definition: entity.h:20
impeller::TSize
Definition: size.h:19
filter_contents.h
impeller::DlImageImpeller::owning_context
OwningContext owning_context() const override
Definition: dl_image_impeller.h:52
impeller::DlImageImpeller::isOpaque
bool isOpaque() const override
Definition: dl_image_impeller.cc:65
impeller::DlImageImpeller::impeller_texture
std::shared_ptr< impeller::Texture > impeller_texture() const override
Definition: dl_image_impeller.cc:60
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:106
impeller::DlImageImpeller::skia_image
sk_sp< SkImage > skia_image() const override
Definition: dl_image_impeller.cc:55
std
Definition: comparable.h:95
impeller::DlImageImpeller::isTextureBacked
bool isTextureBacked() const override
Definition: dl_image_impeller.cc:71
impeller::YUVColorSpace
YUVColorSpace
Definition: color.h:55
impeller::DlImageImpeller::~DlImageImpeller
~DlImageImpeller() override
impeller
Definition: aiks_blend_unittests.cc:18
impeller::DlImageImpeller::GetApproximateByteSize
size_t GetApproximateByteSize() const override
Definition: dl_image_impeller.cc:89
dl_image_impeller.h