| 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 "MakeYUVToRGBFilter Snapshot"); // label
40 if (!snapshot.has_value()) {
41 return nullptr;
42 }
43 return impeller::DlImageImpeller::Make(snapshot->texture);
44 }
45
46 DlImageImpeller::DlImageImpeller(std::shared_ptr<Texture> texture,
47 OwningContext owning_context)
48 : texture_(std::move(texture)), owning_context_(owning_context) {}
49
50 // |DlImage|
51 DlImageImpeller::~DlImageImpeller() = default;
52
53 // |DlImage|
54 sk_sp<SkImage> DlImageImpeller::skia_image() const {
55 return nullptr;
56 };
57
58 // |DlImage|
59 std::shared_ptr<impeller::Texture> DlImageImpeller::impeller_texture() const {
60 return texture_;
61 }
62
63 // |DlImage|
64 bool DlImageImpeller::isOpaque() const {
65 // Impeller doesn't currently implement opaque alpha types.
66 return false;
67 }
68
69 // |DlImage|
70 bool DlImageImpeller::isTextureBacked() const {
71 // Impeller textures are always ... textures :/
72 return true;
73 }
74
75 // |DlImage|
76 bool DlImageImpeller::isUIThreadSafe() const {
77 // Impeller textures are always thread-safe
78 return true;
79 }
80
81 // |DlImage|
82 SkISize DlImageImpeller::dimensions() const {
83 const auto size = texture_ ? texture_->GetSize() : ISize{};
84 return SkISize::Make(size.width, size.height);
85 }
86
87 // |DlImage|
88 size_t DlImageImpeller::GetApproximateByteSize() const {
89 auto size = sizeof(*this);
90 if (texture_) {
91 size += texture_->GetTextureDescriptor().GetByteSizeOfBaseMipLevel();
92 }
93 return size;
94 }
95
96 } // namespace impeller
impeller::AiksContext
Definition: aiks_context.h:20
impeller::Entity::SetBlendMode
void SetBlendMode(BlendMode blend_mode)
Definition: entity.cc:97
impeller::AiksContext::GetContentContext
ContentContext & GetContentContext() const
Definition: aiks_context.cc:39
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:76
impeller::DlImageImpeller::dimensions
SkISize dimensions() const override
Definition: dl_image_impeller.cc:82
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:21
impeller::TSize< int64_t >
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:64
impeller::DlImageImpeller::impeller_texture
std::shared_ptr< impeller::Texture > impeller_texture() const override
Definition: dl_image_impeller.cc:59
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:123
impeller::DlImageImpeller::skia_image
sk_sp< SkImage > skia_image() const override
Definition: dl_image_impeller.cc:54
std
Definition: comparable.h:98
impeller::DlImageImpeller::isTextureBacked
bool isTextureBacked() const override
Definition: dl_image_impeller.cc:70
impeller::YUVColorSpace
YUVColorSpace
Definition: color.h:53
impeller::DlImageImpeller::~DlImageImpeller
~DlImageImpeller() override
impeller
Definition: aiks_context.cc:10
impeller::DlImageImpeller::GetApproximateByteSize
size_t GetApproximateByteSize() const override
Definition: dl_image_impeller.cc:88
impeller::BlendMode::kSource
@ kSource
dl_image_impeller.h