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 #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;
45 
46  // Disable the render target cache so that this snapshot's texture will not
47  // be reused later by other operations.
48  const auto& renderer = aiks_context->GetContentContext();
49  renderer.GetRenderTargetCache()->DisableCache();
50  fml::ScopedCleanupClosure restore_cache(
51  [&] { renderer.GetRenderTargetCache()->EnableCache(); });
52 
53  std::optional<Snapshot> snapshot =
54  yuv_to_rgb_filter_contents->RenderToSnapshot(
55  renderer, // renderer
56  entity, // entity
57  std::nullopt, // coverage_limit
58  std::nullopt, // sampler_descriptor
59  true, // msaa_enabled
60  /*mip_count=*/1,
61  "MakeYUVToRGBFilter Snapshot"); // label
62  if (!snapshot.has_value()) {
63  return nullptr;
64  }
65  return impeller::DlImageImpeller::Make(snapshot->texture);
66 }
67 
68 DlImageImpeller::DlImageImpeller(std::shared_ptr<Texture> texture,
69  OwningContext owning_context
70 #ifdef FML_OS_IOS_SIMULATOR
71  ,
72  bool is_fake_image
73 #endif // FML_OS_IOS_SIMULATOR
74  )
75  : texture_(std::move(texture)),
76  owning_context_(owning_context)
77 #ifdef FML_OS_IOS_SIMULATOR
78  ,
79  is_fake_image_(is_fake_image)
80 #endif // #ifdef FML_OS_IOS_SIMULATOR
81 {
82 }
83 
84 // |DlImage|
86 
87 // |DlImage|
88 sk_sp<SkImage> DlImageImpeller::skia_image() const {
89  return nullptr;
90 };
91 
92 // |DlImage|
93 std::shared_ptr<impeller::Texture> DlImageImpeller::impeller_texture() const {
94  return texture_;
95 }
96 
97 // |DlImage|
99  // Impeller doesn't currently implement opaque alpha types.
100  return false;
101 }
102 
103 // |DlImage|
105  // Impeller textures are always ... textures :/
106  return true;
107 }
108 
109 // |DlImage|
111  // Impeller textures are always thread-safe
112  return true;
113 }
114 
115 // |DlImage|
116 flutter::DlISize DlImageImpeller::GetSize() const {
117  // texture |GetSize()| returns a 64-bit size, but we need a 32-bit size,
118  // so we need to convert to DlISize (the 32-bit variant) either way.
119  return texture_ ? flutter::DlISize(texture_->GetSize()) : flutter::DlISize();
120 }
121 
122 // |DlImage|
124  auto size = sizeof(*this);
125  if (texture_) {
126  size += texture_->GetTextureDescriptor().GetByteSizeOfBaseMipLevel();
127  }
128  return size;
129 }
130 
131 } // 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:97
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:95