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"
13 #include "impeller/geometry/size.h"
14 
15 namespace impeller {
16 
17 class Texture {
18  public:
19  virtual ~Texture();
20 
21  /// @brief Label this resource for inspection in GPU debugging tools.
22  ///
23  /// This functionality may be disabled in release builds.
24  virtual void SetLabel(std::string_view label) = 0;
25 
26  /// @brief Label this resource for inspection in GPU debugging tools, with
27  /// label and trailing will be concatenated together.
28  ///
29  /// This functionality may be disabled in release builds.
30  virtual void SetLabel(std::string_view label, std::string_view trailing) = 0;
31 
32  // Deprecated: use BlitPass::AddCopy instead.
33  [[nodiscard]] bool SetContents(const uint8_t* contents,
34  size_t length,
35  size_t slice = 0,
36  bool is_opaque = false);
37 
38  // Deprecated: use BlitPass::AddCopy instead.
39  [[nodiscard]] bool SetContents(std::shared_ptr<const fml::Mapping> mapping,
40  size_t slice = 0,
41  bool is_opaque = false);
42 
43  virtual bool IsValid() const = 0;
44 
45  virtual ISize GetSize() const = 0;
46 
47  bool IsOpaque() const;
48 
49  size_t GetMipCount() const;
50 
52 
53  /// Update the coordinate system used by the texture.
54  ///
55  /// The setting is used to conditionally invert the coordinates to
56  /// account for the different origin of GLES textures.
57  void SetCoordinateSystem(TextureCoordinateSystem coordinate_system);
58 
60 
61  virtual Scalar GetYCoordScale() const;
62 
63  /// Returns true if mipmaps have never been generated.
64  /// The contents of the mipmap may be out of date if the root texture has been
65  /// modified and the mipmaps hasn't been regenerated.
66  bool NeedsMipmapGeneration() const;
67 
68  protected:
69  explicit Texture(TextureDescriptor desc);
70 
71  [[nodiscard]] virtual bool OnSetContents(const uint8_t* contents,
72  size_t length,
73  size_t slice) = 0;
74 
75  [[nodiscard]] virtual bool OnSetContents(
76  std::shared_ptr<const fml::Mapping> mapping,
77  size_t slice) = 0;
78 
79  bool mipmap_generated_ = false;
80 
81  private:
82  TextureCoordinateSystem coordinate_system_ =
84  const TextureDescriptor desc_;
85  bool is_opaque_ = false;
86 
87  bool IsSliceValid(size_t slice) const;
88 
89  Texture(const Texture&) = delete;
90 
91  Texture& operator=(const Texture&) = delete;
92 };
93 
94 } // namespace impeller
95 
96 #endif // FLUTTER_IMPELLER_CORE_TEXTURE_H_
size_t GetMipCount() const
Definition: texture.cc:53
bool IsOpaque() const
Definition: texture.cc:49
virtual ~Texture()
const TextureDescriptor & GetTextureDescriptor() const
Definition: texture.cc:57
TextureCoordinateSystem GetCoordinateSystem() const
Definition: texture.cc:77
virtual bool OnSetContents(std::shared_ptr< const fml::Mapping > mapping, size_t slice)=0
virtual void SetLabel(std::string_view label, std::string_view trailing)=0
Label this resource for inspection in GPU debugging tools, with label and trailing will be concatenat...
bool NeedsMipmapGeneration() const
Definition: texture.cc:85
Texture(TextureDescriptor desc)
Definition: texture.cc:11
bool mipmap_generated_
Definition: texture.h:79
void SetCoordinateSystem(TextureCoordinateSystem coordinate_system)
Definition: texture.cc:73
virtual void SetLabel(std::string_view label)=0
Label this resource for inspection in GPU debugging tools.
virtual Scalar GetYCoordScale() const
Definition: texture.cc:81
virtual ISize GetSize() const =0
virtual bool OnSetContents(const uint8_t *contents, size_t length, size_t slice)=0
virtual bool IsValid() const =0
bool SetContents(const uint8_t *contents, size_t length, size_t slice=0, bool is_opaque=false)
Definition: texture.cc:15
float Scalar
Definition: scalar.h:19
TextureCoordinateSystem
Definition: formats.h:327
A lightweight object that describes the attributes of a texture that can then used an allocator to cr...