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