Flutter Engine Uber Docs
Docs for the entire Flutter Engine repo.
 
Loading...
Searching...
No Matches
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
9
10namespace impeller {
11
12sk_sp<DlImageImpeller> DlImageImpeller::Make(std::shared_ptr<Texture> texture,
13 OwningContext owning_context) {
14 if (!texture) {
15 return nullptr;
16 }
17 return sk_make_sp<DlImageImpellerTexture>(std::move(texture), owning_context);
18}
19
21 AiksContext* aiks_context,
22 std::shared_ptr<Texture> y_texture,
23 std::shared_ptr<Texture> uv_texture,
24 YUVColorSpace yuv_color_space) {
25 if (!aiks_context || !y_texture || !uv_texture) {
26 return nullptr;
27 }
28 auto yuv_to_rgb_filter_contents = FilterContents::MakeYUVToRGBFilter(
29 std::move(y_texture), std::move(uv_texture), yuv_color_space);
30 impeller::Entity entity;
32
33 // Disable the render target cache so that this snapshot's texture will not
34 // be reused later by other operations.
35 const auto& renderer = aiks_context->GetContentContext();
36 renderer.GetRenderTargetCache()->DisableCache();
37 fml::ScopedCleanupClosure restore_cache(
38 [&] { renderer.GetRenderTargetCache()->EnableCache(); });
39
40 std::optional<Snapshot> snapshot =
41 yuv_to_rgb_filter_contents->RenderToSnapshot(
42 renderer, entity,
43 {.coverage_limit = std::nullopt,
44 .sampler_descriptor = std::nullopt,
45 .msaa_enabled = true,
46 .mip_count = 1,
47 .label = "MakeYUVToRGBFilter Snapshot"});
48 if (!snapshot.has_value()) {
49 return nullptr;
50 }
51 return impeller::DlImageImpeller::Make(snapshot->texture);
52}
53
54std::shared_ptr<Texture> DlImageImpeller::GetCachedTexture(
55 const ContentContext& renderer) const {
56 auto texture = renderer.GetCachedTexture(this);
57 if (texture) {
58 return texture;
59 }
61 renderer.SetCachedTexture(this, texture);
62 return texture;
63}
64
66 OwningContext owning_context)
67 : texture_(std::move(texture)), owning_context_(owning_context) {}
68
69// |DlImage|
71
72// |DlImage|
73std::shared_ptr<impeller::Texture> DlImageImpellerTexture::GetImpellerTexture(
74 const std::shared_ptr<impeller::Context>& context) const {
75 return texture_;
76}
77
78// |DlImage|
80 if (!texture_) {
82 }
83 switch (texture_->GetTextureDescriptor().format) {
87 default:
89 }
90}
91
92// |DlImage|
94 // Impeller doesn't currently implement opaque alpha types.
95 return false;
96}
97
98// |DlImage|
100 // Impeller textures are always thread-safe
101 return true;
102}
103
104// |DlImage|
106 // texture |GetSize()| returns a 64-bit size, but we need a 32-bit size,
107 // so we need to convert to DlISize (the 32-bit variant) either way.
108 return texture_ ? flutter::DlISize(texture_->GetSize()) : flutter::DlISize();
109}
110
111// |DlImage|
113 auto size = sizeof(*this);
114 if (texture_) {
115 size += texture_->GetTextureDescriptor().GetByteSizeOfBaseMipLevel();
116 }
117 return size;
118}
119
120} // namespace impeller
virtual OwningContext owning_context() const
Definition dl_image.h:136
Wraps a closure that is invoked in the destructor unless released by the caller.
Definition closure.h:32
ContentContext & GetContentContext() const
std::shared_ptr< Texture > GetCachedTexture(const flutter::DlImage *image) const
Get a cached texture for the given image.
const std::shared_ptr< RenderTargetAllocator > & GetRenderTargetCache() const
void SetCachedTexture(const flutter::DlImage *image, const std::shared_ptr< Texture > &texture) const
Set a cached texture for the given image.
std::shared_ptr< Context > GetContext() const
std::shared_ptr< Texture > GetCachedTexture(const ContentContext &renderer) const
virtual std::shared_ptr< Texture > GetImpellerTexture(const std::shared_ptr< Context > &context) const =0
static sk_sp< DlImageImpeller > MakeFromYUVTextures(AiksContext *aiks_context, std::shared_ptr< Texture > y_texture, std::shared_ptr< Texture > uv_texture, YUVColorSpace yuv_color_space)
static sk_sp< DlImageImpeller > Make(std::shared_ptr< Texture > texture, OwningContext owning_context=OwningContext::kIO)
flutter::DlColorSpace GetColorSpace() const override
Gets the color space of the image.
DlImageImpellerTexture(std::shared_ptr< Texture > texture, OwningContext owning_context)
bool isUIThreadSafe() const override
If the underlying platform image held by this object has no threading requirements for the release of...
flutter::DlISize GetSize() const override
bool isOpaque() const override
If the pixel format of this image ignores alpha, this returns true. This method might conservatively ...
std::shared_ptr< Texture > GetImpellerTexture(const std::shared_ptr< Context > &context) const override
size_t GetApproximateByteSize() const override
void SetBlendMode(BlendMode blend_mode)
Definition entity.cc:98
static std::shared_ptr< FilterContents > MakeYUVToRGBFilter(std::shared_ptr< Texture > y_texture, std::shared_ptr< Texture > uv_texture, YUVColorSpace yuv_color_space)
FlTexture * texture
impeller::ISize32 DlISize
DlColorSpace
Definition dl_color.h:13
YUVColorSpace
Definition color.h:54
Definition ref_ptr.h:261