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 
6 
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;
33 
34  // Disable the render target cache so that this snapshot's texture will not
35  // be reused later by other operations.
36  const auto& renderer = aiks_context->GetContentContext();
37  renderer.GetRenderTargetCache()->DisableCache();
38  fml::ScopedCleanupClosure restore_cache(
39  [&] { renderer.GetRenderTargetCache()->EnableCache(); });
40 
41  std::optional<Snapshot> snapshot =
42  yuv_to_rgb_filter_contents->RenderToSnapshot(
43  renderer, entity,
44  {.coverage_limit = std::nullopt,
45  .sampler_descriptor = std::nullopt,
46  .msaa_enabled = true,
47  .mip_count = 1,
48  .label = "MakeYUVToRGBFilter Snapshot"});
49  if (!snapshot.has_value()) {
50  return nullptr;
51  }
52  return impeller::DlImageImpeller::Make(snapshot->texture);
53 }
54 
55 DlImageImpeller::DlImageImpeller(std::shared_ptr<Texture> texture,
56  OwningContext owning_context)
57  : texture_(std::move(texture)), owning_context_(owning_context) {}
58 
59 // |DlImage|
61 
62 // |DlImage|
63 sk_sp<SkImage> DlImageImpeller::skia_image() const {
64  return nullptr;
65 };
66 
67 // |DlImage|
68 std::shared_ptr<impeller::Texture> DlImageImpeller::impeller_texture() const {
69  return texture_;
70 }
71 
72 // |DlImage|
74  // Impeller doesn't currently implement opaque alpha types.
75  return false;
76 }
77 
78 // |DlImage|
80  // Impeller textures are always ... textures :/
81  return true;
82 }
83 
84 // |DlImage|
86  // Impeller textures are always thread-safe
87  return true;
88 }
89 
90 // |DlImage|
91 flutter::DlISize DlImageImpeller::GetSize() const {
92  // texture |GetSize()| returns a 64-bit size, but we need a 32-bit size,
93  // so we need to convert to DlISize (the 32-bit variant) either way.
94  return texture_ ? flutter::DlISize(texture_->GetSize()) : flutter::DlISize();
95 }
96 
97 // |DlImage|
99  auto size = sizeof(*this);
100  if (texture_) {
101  size += texture_->GetTextureDescriptor().GetByteSizeOfBaseMipLevel();
102  }
103  return size;
104 }
105 
106 } // namespace impeller
ContentContext & GetContentContext() const
Definition: aiks_context.cc:42
const std::shared_ptr< RenderTargetAllocator > & GetRenderTargetCache() const
size_t GetApproximateByteSize() const override
static sk_sp< DlImageImpeller > MakeFromYUVTextures(AiksContext *aiks_context, std::shared_ptr< Texture > y_texture, std::shared_ptr< Texture > uv_texture, YUVColorSpace yuv_color_space)
bool isTextureBacked() const override
std::shared_ptr< impeller::Texture > impeller_texture() const override
static sk_sp< DlImageImpeller > Make(std::shared_ptr< Texture > texture, OwningContext owning_context=OwningContext::kIO)
flutter::DlISize GetSize() const override
sk_sp< SkImage > skia_image() const override
bool isUIThreadSafe() const override
bool isOpaque() const override
OwningContext owning_context() 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)
YUVColorSpace
Definition: color.h:54
Definition: comparable.h:93