Flutter Engine Uber Docs
Docs for the entire Flutter Engine repo.
 
Loading...
Searching...
No Matches
dl_image.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_DISPLAY_LIST_IMAGE_DL_IMAGE_H_
6#define FLUTTER_DISPLAY_LIST_IMAGE_DL_IMAGE_H_
7
8#include <memory>
9#include <optional>
10#include <string>
11
15#include "flutter/fml/macros.h"
16#include "third_party/skia/include/core/SkImage.h"
17#include "third_party/skia/include/core/SkRefCnt.h"
18
19namespace impeller {
20class DlImageImpeller;
21} // namespace impeller
22
23namespace flutter {
24class DlImageSkia;
25
26//------------------------------------------------------------------------------
27/// @brief Represents an image whose allocation is (usually) resident on
28/// device memory.
29///
30/// Since it is usually impossible or expensive to transmute images
31/// for one rendering backend to another, these objects are backend
32/// specific.
33///
34class DlImage : public SkRefCnt {
35 public:
36 // Describes which GPU context owns this image.
37 enum class OwningContext { kRaster, kIO };
38
39 virtual ~DlImage();
40
41 //----------------------------------------------------------------------------
42 /// @brief The backend type of this image.
43 ///
44 enum class Type { kSkia, kImpeller };
45
46 //----------------------------------------------------------------------------
47 /// @brief Returns the backend type of this image.
48 ///
49 /// @return The image type.
50 ///
51 virtual Type GetImageType() const = 0;
52
53 //----------------------------------------------------------------------------
54 /// @brief Safe downcast to DlImageSkia.
55 ///
56 /// @return A pointer to DlImageSkia or null if not a Skia image.
57 ///
58 virtual const DlImageSkia* asSkiaImage() const { return nullptr; }
59
60 //----------------------------------------------------------------------------
61 /// @brief Safe downcast to DlImageImpeller.
62 ///
63 /// @return A pointer to DlImageImpeller or null if not an Impeller image.
64 ///
66 return nullptr;
67 }
68
69 //----------------------------------------------------------------------------
70 /// @brief Returns true if the image is backed by a GPU texture.
71 ///
72 virtual bool isTextureBacked() const = 0;
73
74 //----------------------------------------------------------------------------
75 /// @brief Gets the color space of the image.
76 ///
77 /// @return The color space.
78 ///
79 virtual DlColorSpace GetColorSpace() const = 0;
80
81 //----------------------------------------------------------------------------
82 /// @brief If the pixel format of this image ignores alpha, this returns
83 /// true. This method might conservatively return false when it
84 /// cannot guarnatee an opaque image, for example when the pixel
85 /// format of the image supports alpha but the image is made up of
86 /// entirely opaque pixels.
87 ///
88 /// @return True if the pixel format of this image ignores alpha.
89 ///
90 virtual bool isOpaque() const = 0;
91
92 //----------------------------------------------------------------------------
93 /// @brief If the underlying platform image held by this object has no
94 /// threading requirements for the release of that image (or if
95 /// arrangements have already been made to forward that image to
96 /// the correct thread upon deletion), this method returns true.
97 ///
98 /// @return True if the underlying image is held in a thread-safe manner.
99 ///
100 virtual bool isUIThreadSafe() const = 0;
101
102 //----------------------------------------------------------------------------
103 /// @return The dimensions of the pixel grid.
104 ///
105 virtual DlISize GetSize() const = 0;
106
107 //----------------------------------------------------------------------------
108 /// @return The approximate byte size of the allocation of this image.
109 /// This takes into account details such as mip-mapping. The
110 /// allocation is usually resident in device memory.
111 ///
112 virtual size_t GetApproximateByteSize() const = 0;
113
114 //----------------------------------------------------------------------------
115 /// @return The width of the pixel grid. A convenience method that calls
116 /// |DlImage::dimensions|.
117 ///
118 int width() const;
119
120 //----------------------------------------------------------------------------
121 /// @return The height of the pixel grid. A convenience method that calls
122 /// |DlImage::dimensions|.
123 ///
124 int height() const;
125
126 //----------------------------------------------------------------------------
127 /// @return The bounds of the pixel grid with 0, 0 as origin. A
128 /// convenience method that calls |DlImage::dimensions|.
129 ///
130 DlIRect GetBounds() const;
131
132 //----------------------------------------------------------------------------
133 /// @return Specifies which context was used to create this image. The
134 /// image must be collected on the same task runner as its
135 /// context.
137
138 //----------------------------------------------------------------------------
139 /// @return An error, if any, that occurred when trying to create the
140 /// image.
141 virtual std::optional<std::string> get_error() const;
142
143 bool Equals(const DlImage* other) const;
144
145 bool Equals(const DlImage& other) const { return Equals(&other); }
146
147 bool Equals(const sk_sp<const DlImage>& other) const {
148 return Equals(other.get());
149 }
150
151 protected:
153};
154
155} // namespace flutter
156
157#endif // FLUTTER_DISPLAY_LIST_IMAGE_DL_IMAGE_H_
Represents an image whose allocation is (usually) resident on device memory.
Definition dl_image.h:34
bool Equals(const DlImage &other) const
Definition dl_image.h:145
virtual size_t GetApproximateByteSize() const =0
bool Equals(const sk_sp< const DlImage > &other) const
Definition dl_image.h:147
virtual const impeller::DlImageImpeller * asImpellerImage() const
Safe downcast to DlImageImpeller.
Definition dl_image.h:65
virtual DlISize GetSize() const =0
virtual bool isTextureBacked() const =0
Returns true if the image is backed by a GPU texture.
virtual std::optional< std::string > get_error() const
Definition dl_image.cc:27
int height() const
Definition dl_image.cc:19
DlIRect GetBounds() const
Definition dl_image.cc:23
Type
The backend type of this image.
Definition dl_image.h:44
virtual bool isOpaque() const =0
If the pixel format of this image ignores alpha, this returns true. This method might conservatively ...
virtual ~DlImage()
virtual DlColorSpace GetColorSpace() const =0
Gets the color space of the image.
virtual Type GetImageType() const =0
Returns the backend type of this image.
bool Equals(const DlImage *other) const
Definition dl_image.cc:31
virtual OwningContext owning_context() const
Definition dl_image.h:136
virtual bool isUIThreadSafe() const =0
If the underlying platform image held by this object has no threading requirements for the release of...
int width() const
Definition dl_image.cc:15
virtual const DlImageSkia * asSkiaImage() const
Safe downcast to DlImageSkia.
Definition dl_image.h:58
DlColorSpace
Definition dl_color.h:13