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