| 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 backend_ = context.GetContext()->GetBackendType();
19 texture_ = std::move(texture);
20 }
21
22 Texture::Texture(impeller::Context::BackendType backend,
23 std::shared_ptr<impeller::Texture> texture)
24 : backend_(backend), texture_(std::move(texture)) {}
25
26 Texture::~Texture() = default;
27
28 bool Texture::IsValid() const {
29 return !!texture_;
30 }
31
32 bool Texture::SetContents(const uint8_t* contents, uint64_t length) {
33 if (!IsValid()) {
34 return false;
35 }
36 return texture_->SetContents(contents, length);
37 }
38
39 bool Texture::SetContents(std::shared_ptr<const fml::Mapping> contents) {
40 if (!IsValid()) {
41 return false;
42 }
43 return texture_->SetContents(std::move(contents));
44 }
45
46 sk_sp<DlImageImpeller> Texture::MakeImage() const {
47 return DlImageImpeller::Make(texture_);
48 }
49
50 impeller::Context::BackendType Texture::GetBackendType() const {
51 return backend_;
52 }
53
54 const std::shared_ptr<impeller::Texture>& Texture::GetTexture() const {
55 return texture_;
56 }
57
58 } // namespace impeller::interop
impeller::Context::BackendType
BackendType
Definition: context.h:48
impeller::interop::Texture::Texture
Texture(const Context &context, const TextureDescriptor &descriptor)
Definition: texture.cc:9
impeller::interop::Context::GetContext
std::shared_ptr< impeller::Context > GetContext() const
Definition: context.cc:37
impeller::interop
Definition: color_filter.cc:7
impeller::interop::Context::IsValid
bool IsValid() const
Definition: context.cc:33
impeller::interop::Texture::MakeImage
sk_sp< DlImageImpeller > MakeImage() const
Definition: texture.cc:46
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:17
impeller::interop::Texture::GetTexture
const std::shared_ptr< impeller::Texture > & GetTexture() const
Definition: texture.cc:54
impeller::interop::Texture::SetContents
bool SetContents(const uint8_t *contents, uint64_t length)
Definition: texture.cc:32
texture.h
impeller::interop::Texture::IsValid
bool IsValid() const
Definition: texture.cc:28
impeller::interop::Texture::GetBackendType
impeller::Context::BackendType GetBackendType() const
Definition: texture.cc:50
impeller::interop::Texture::~Texture
~Texture() override
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