| Flutter Impeller |

texture.h
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 #ifndef FLUTTER_IMPELLER_CORE_TEXTURE_H_
6 #define FLUTTER_IMPELLER_CORE_TEXTURE_H_
7
8 #include <string_view>
9
10 #include "flutter/fml/mapping.h"
11 #include "impeller/core/formats.h"
12 #include "impeller/core/texture_descriptor.h"
13 #include "impeller/geometry/size.h"
14
15 namespace impeller {
16
17 class Texture {
18 public:
19 virtual ~Texture();
20
21 virtual void SetLabel(std::string_view label) = 0;
22
23 // Deprecated: use BlitPass::AddCopy instead.
24 [[nodiscard]] bool SetContents(const uint8_t* contents,
25 size_t length,
26 size_t slice = 0,
27 bool is_opaque = false);
28
29 // Deprecated: use BlitPass::AddCopy instead.
30 [[nodiscard]] bool SetContents(std::shared_ptr<const fml::Mapping> mapping,
31 size_t slice = 0,
32 bool is_opaque = false);
33
34 virtual bool IsValid() const = 0;
35
36 virtual ISize GetSize() const = 0;
37
38 bool IsOpaque() const;
39
40 size_t GetMipCount() const;
41
42 const TextureDescriptor& GetTextureDescriptor() const;
43
44 /// Update the coordinate system used by the texture.
45 ///
46 /// The setting is used to conditionally invert the coordinates to
47 /// account for the different origin of GLES textures.
48 void SetCoordinateSystem(TextureCoordinateSystem coordinate_system);
49
50 TextureCoordinateSystem GetCoordinateSystem() const;
51
52 virtual Scalar GetYCoordScale() const;
53
54 /// Returns true if mipmaps have never been generated.
55 /// The contents of the mipmap may be out of date if the root texture has been
56 /// modified and the mipmaps hasn't been regenerated.
57 bool NeedsMipmapGeneration() const;
58
59 protected:
60 explicit Texture(TextureDescriptor desc);
61
62 [[nodiscard]] virtual bool OnSetContents(const uint8_t* contents,
63 size_t length,
64 size_t slice) = 0;
65
66 [[nodiscard]] virtual bool OnSetContents(
67 std::shared_ptr<const fml::Mapping> mapping,
68 size_t slice) = 0;
69
70 bool mipmap_generated_ = false;
71
72 private:
73 TextureCoordinateSystem coordinate_system_ =
74 TextureCoordinateSystem::kRenderToTexture;
75 const TextureDescriptor desc_;
76 bool is_opaque_ = false;
77
78 bool IsSliceValid(size_t slice) const;
79
80 Texture(const Texture&) = delete;
81
82 Texture& operator=(const Texture&) = delete;
83 };
84
85 } // namespace impeller
86
87 #endif // FLUTTER_IMPELLER_CORE_TEXTURE_H_
impeller::Texture::NeedsMipmapGeneration
bool NeedsMipmapGeneration() const
Definition: texture.cc:85
impeller::Texture::~Texture
virtual ~Texture()
impeller::Scalar
float Scalar
Definition: scalar.h:18
impeller::Texture::GetMipCount
size_t GetMipCount() const
Definition: texture.cc:53
impeller::Texture::GetTextureDescriptor
const TextureDescriptor & GetTextureDescriptor() const
Definition: texture.cc:57
texture_descriptor.h
formats.h
impeller::Texture::IsValid
virtual bool IsValid() const =0
impeller::Texture::GetYCoordScale
virtual Scalar GetYCoordScale() const
Definition: texture.cc:81
impeller::TextureCoordinateSystem
TextureCoordinateSystem
Definition: formats.h:327
impeller::TextureCoordinateSystem::kRenderToTexture
@ kRenderToTexture
impeller::Texture
Definition: texture.h:17
impeller::TSize
Definition: size.h:19
impeller::Texture::SetCoordinateSystem
void SetCoordinateSystem(TextureCoordinateSystem coordinate_system)
Definition: texture.cc:73
impeller::Texture::IsOpaque
bool IsOpaque() const
Definition: texture.cc:49
impeller::Texture::mipmap_generated_
bool mipmap_generated_
Definition: texture.h:70
impeller::Texture::GetSize
virtual ISize GetSize() const =0
impeller::Texture::SetLabel
virtual void SetLabel(std::string_view label)=0
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
impeller::Texture::OnSetContents
virtual bool OnSetContents(const uint8_t *contents, size_t length, size_t slice)=0
impeller::Texture::Texture
Texture(TextureDescriptor desc)
Definition: texture.cc:11
impeller::Texture::GetCoordinateSystem
TextureCoordinateSystem GetCoordinateSystem() const
Definition: texture.cc:77
impeller
Definition: allocation.cc:12
impeller::Texture::SetContents
bool SetContents(const uint8_t *contents, size_t length, size_t slice=0, bool is_opaque=false)
Definition: texture.cc:15
size.h