| 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
5 #include "impeller/toolkit/interop/texture.h"
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
23 Texture::Texture(impeller::Context::BackendType backend,
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
51 impeller::Context::BackendType Texture::GetBackendType() const {
52 return backend_;
53 }
54
55 const std::shared_ptr<impeller::Texture>& Texture::GetTexture() const {
56 return texture_;
57 }
58
59 } // namespace impeller::interop
impeller::Context::BackendType
BackendType
Definition: context.h:67
impeller::DlImageImpeller::Make
static sk_sp< DlImageImpeller > Make(std::shared_ptr< Texture > texture, OwningContext owning_context=OwningContext::kIO)
Definition: dl_image_impeller.cc:23
impeller::interop::Context
Definition: context.h:16
impeller::interop::Context::GetContext
std::shared_ptr< impeller::Context > GetContext() const
Definition: context.cc:20
impeller::interop::Context::IsValid
bool IsValid() const
Definition: context.cc:16
impeller::interop::Texture::~Texture
~Texture() override
impeller::interop::Texture::GetBackendType
impeller::Context::BackendType GetBackendType() const
Definition: texture.cc:51
impeller::interop::Texture::GetTexture
const std::shared_ptr< impeller::Texture > & GetTexture() const
Definition: texture.cc:55
impeller::interop::Texture::IsValid
bool IsValid() const
Definition: texture.cc:29
impeller::interop::Texture::MakeImage
sk_sp< DlImageImpeller > MakeImage() const
Definition: texture.cc:47
impeller::interop::Texture::SetContents
bool SetContents(const uint8_t *contents, uint64_t length)
Definition: texture.cc:33
impeller::interop::Texture::Texture
Texture(const Context &context, const TextureDescriptor &descriptor)
Definition: texture.cc:9
impeller::interop
Definition: context_gles.cc:12
std
Definition: comparable.h:95
impeller::TextureDescriptor
A lightweight object that describes the attributes of a texture that can then used an allocator to cr...
Definition: texture_descriptor.h:38
texture.h