Flutter Engine
 
Loading...
Searching...
No Matches
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
7namespace impeller::interop {
8
9Texture::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
27Texture::~Texture() = default;
28
29bool Texture::IsValid() const {
30 return !!texture_;
31}
32
33bool Texture::SetContents(const uint8_t* contents, uint64_t length) {
34 if (!IsValid()) {
35 return false;
36 }
37 return texture_->SetContents(contents, length);
38}
39
40bool 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
47sk_sp<DlImageImpeller> Texture::MakeImage() const {
48 return DlImageImpeller::Make(texture_);
49}
50
54
55const 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
impeller::Context::BackendType GetBackendType() const
Definition texture.cc:51
const std::shared_ptr< impeller::Texture > & GetTexture() const
Definition texture.cc:55
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
size_t length
FlTexture * texture
Definition ref_ptr.h:261
A lightweight object that describes the attributes of a texture that can then used an allocator to cr...