Flutter Impeller
texture.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 
7 namespace impeller::interop {
8 
9 Texture::Texture(const Context& context, const TextureDescriptor& descriptor) {
10  if (!context.IsValid()) {
11  return;
12  }
13  auto texture =
14  context.GetContext()->GetResourceAllocator()->CreateTexture(descriptor);
15  if (!texture || !texture->IsValid()) {
16  return;
17  }
18  texture->SetLabel("UserCreated");
19  backend_ = context.GetContext()->GetBackendType();
20  texture_ = std::move(texture);
21 }
22 
24  std::shared_ptr<impeller::Texture> texture)
25  : backend_(backend), texture_(std::move(texture)) {}
26 
27 Texture::~Texture() = default;
28 
29 bool Texture::IsValid() const {
30  return !!texture_;
31 }
32 
33 bool Texture::SetContents(const uint8_t* contents, uint64_t length) {
34  if (!IsValid()) {
35  return false;
36  }
37  return texture_->SetContents(contents, length);
38 }
39 
40 bool Texture::SetContents(std::shared_ptr<const fml::Mapping> contents) {
41  if (!IsValid()) {
42  return false;
43  }
44  return texture_->SetContents(std::move(contents));
45 }
46 
47 sk_sp<DlImageImpeller> Texture::MakeImage() const {
48  return DlImageImpeller::Make(texture_);
49 }
50 
52  return backend_;
53 }
54 
55 const std::shared_ptr<impeller::Texture>& Texture::GetTexture() const {
56  return texture_;
57 }
58 
59 } // namespace impeller::interop
static sk_sp< DlImageImpeller > Make(std::shared_ptr< Texture > texture, OwningContext owning_context=OwningContext::kIO)
std::shared_ptr< impeller::Context > GetContext() const
Definition: context.cc:20
bool IsValid() const
Definition: context.cc:16
impeller::Context::BackendType GetBackendType() const
Definition: texture.cc:51
const std::shared_ptr< impeller::Texture > & GetTexture() const
Definition: texture.cc:55
bool IsValid() const
Definition: texture.cc:29
sk_sp< DlImageImpeller > MakeImage() const
Definition: texture.cc:47
bool SetContents(const uint8_t *contents, uint64_t length)
Definition: texture.cc:33
Texture(const Context &context, const TextureDescriptor &descriptor)
Definition: texture.cc:9
Definition: comparable.h:95
A lightweight object that describes the attributes of a texture that can then used an allocator to cr...