Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
SkImage_Ganesh.h
Go to the documentation of this file.
1/*
2 * Copyright 2015 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8#ifndef SkImage_Ganesh_DEFINED
9#define SkImage_Ganesh_DEFINED
10
14#include "src/base/SkSpinlock.h"
15#include "src/gpu/Swizzle.h"
19
20#include <cstddef>
21#include <cstdint>
22#include <memory>
23#include <tuple>
24
25class GrBackendFormat;
27class GrDirectContext;
29class GrImageContext;
31class GrRenderTask;
32class GrSurfaceProxy;
33class SkColorInfo;
34class SkColorSpace;
35class SkImage;
36class SkMatrix;
37enum class GrColorType;
38enum class GrImageTexGenPolicy : int;
39enum class GrSemaphoresSubmitted : bool;
40enum class SkTileMode;
41enum GrSurfaceOrigin : int;
42enum SkColorType : int;
43enum SkYUVColorSpace : int;
44struct GrFlushInfo;
45struct SkIRect;
46struct SkISize;
47struct SkImageInfo;
48struct SkRect;
49
50namespace skgpu {
51enum class Mipmapped : bool;
52enum class Protected : bool;
53}
54
55class SkImage_Ganesh final : public SkImage_GaneshBase {
56public:
58 uint32_t uniqueID,
61
63 GrSurfaceProxyView volatileSrc,
64 SkColorInfo colorInfo);
65
66 ~SkImage_Ganesh() override;
67
68 // From SkImage.h
69 size_t textureSize() const override;
70
71 // From SkImage_Base.h
73
74 bool onHasMipmaps() const override;
75 bool onIsProtected() const override;
76
80 GrDirectContext*) const final;
81
83
85 SkIRect srcRect,
89 ReadPixelsContext) const override;
90
92 bool readAlpha,
94 SkIRect srcRect,
95 SkISize dstSize,
99 ReadPixelsContext) const override;
100
101 void generatingSurfaceIsDeleted() override;
102
103 // From SkImage_GaneshBase.h
105
106 std::tuple<GrSurfaceProxyView, GrColorType> asView(GrRecordingContext*,
108 GrImageTexGenPolicy) const override;
109
110 std::unique_ptr<GrFragmentProcessor> asFragmentProcessor(GrRecordingContext*,
112 const SkTileMode[2],
113 const SkMatrix&,
114 const SkRect*,
115 const SkRect*) const override;
116
117 // If this is image is a cached SkSurface snapshot then this method is called by the SkSurface
118 // before a write to check if the surface must make a copy to avoid modifying the image's
119 // contents.
120 bool surfaceMustCopyOnWrite(GrSurfaceProxy* surfaceProxy) const;
121
123 bool flushPendingGrContextIO,
124 GrSurfaceOrigin* origin) const;
125
126 GrSurfaceOrigin origin() const override { return fOrigin; }
127
128private:
130 GrSurfaceProxyView volatileSrc,
131 sk_sp<GrSurfaceProxy> stableCopy,
132 sk_sp<GrRenderTask> copyTask,
133 int volatileSrcTargetCount,
135
136 GrSurfaceProxyView makeView(GrRecordingContext*) const;
137
138 // Thread-safe wrapper around the proxies backing this image. Handles dynamically switching
139 // from a "volatile" proxy that may be overwritten (by an SkSurface that this image was snapped
140 // from) to a "stable" proxy that is a copy of the volatile proxy. It allows the image to cancel
141 // the copy if the stable proxy is never required because the contents of the volatile proxy
142 // were never mutated by the SkSurface during the image lifetime.
143 class ProxyChooser {
144 public:
145 ProxyChooser(sk_sp<GrSurfaceProxy> stableProxy,
146 sk_sp<GrSurfaceProxy> volatileProxy,
147 sk_sp<GrRenderTask> copyTask,
148 int volatileProxyTargetCount);
149
150 ProxyChooser(sk_sp<GrSurfaceProxy> stableProxy);
151
152 ~ProxyChooser();
153
154 // Checks if there is a volatile proxy that is safe to use. If so returns it, otherwise
155 // returns the stable proxy (and drops the volatile one if it exists).
157 // Call when it is known copy is necessary.
158 sk_sp<GrSurfaceProxy> switchToStableProxy() SK_EXCLUDES(fLock);
159 // Call when it is known for sure copy won't be necessary.
160 sk_sp<GrSurfaceProxy> makeVolatileProxyStable() SK_EXCLUDES(fLock);
161
162 bool surfaceMustCopyOnWrite(GrSurfaceProxy* surfaceProxy) const SK_EXCLUDES(fLock);
163
164 // Queries that should be independent of which proxy is in use.
165 size_t gpuMemorySize() const SK_EXCLUDES(fLock);
166 skgpu::Mipmapped mipmapped() const SK_EXCLUDES(fLock);
167 skgpu::Protected isProtected() const SK_EXCLUDES(fLock);
168#ifdef SK_DEBUG
169 const GrBackendFormat& backendFormat() SK_EXCLUDES(fLock);
170#endif
171
172 private:
173 mutable SkSpinlock fLock;
174 sk_sp<GrSurfaceProxy> fStableProxy SK_GUARDED_BY(fLock);
175 sk_sp<GrSurfaceProxy> fVolatileProxy SK_GUARDED_BY(fLock);
176 sk_sp<GrRenderTask> fVolatileToStableCopyTask;
177 // The number of GrRenderTasks targeting the volatile proxy at creation time. If the
178 // proxy's target count increases it indicates additional writes and we must switch
179 // to using the stable copy.
180 const int fVolatileProxyTargetCount = 0;
181 };
182
183 mutable ProxyChooser fChooser;
184 skgpu::Swizzle fSwizzle;
185 GrSurfaceOrigin fOrigin;
186
187 using INHERITED = SkImage_GaneshBase;
188};
189
190#endif
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
Definition DM.cpp:213
GrColorType
GrSurfaceOrigin
Definition GrTypes.h:147
GrSemaphoresSubmitted
Definition GrTypes.h:229
SkColorType
Definition SkColorType.h:19
GrImageTexGenPolicy
Definition SkGr.h:141
SkYUVColorSpace
Definition SkImageInfo.h:68
#define SK_EXCLUDES(...)
#define SK_GUARDED_BY(x)
SkTileMode
Definition SkTileMode.h:13
Type::kYUV Type::kRGBA() int(0.7 *637)
virtual sk_sp< SkImage > onMakeColorTypeAndColorSpace(SkColorType, sk_sp< SkColorSpace >, GrDirectContext *) const=0
GrImageContext * context() const final
void generatingSurfaceIsDeleted() override
std::unique_ptr< GrFragmentProcessor > asFragmentProcessor(GrRecordingContext *, SkSamplingOptions, const SkTileMode[2], const SkMatrix &, const SkRect *, const SkRect *) const override
sk_sp< SkImage > onMakeColorTypeAndColorSpace(SkColorType, sk_sp< SkColorSpace >, GrDirectContext *) const final
bool onIsProtected() const override
SkImage_Base::Type type() const override
sk_sp< SkImage > onReinterpretColorSpace(sk_sp< SkColorSpace >) const final
void onAsyncRescaleAndReadPixelsYUV420(SkYUVColorSpace, bool readAlpha, sk_sp< SkColorSpace >, SkIRect srcRect, SkISize dstSize, RescaleGamma, RescaleMode, ReadPixelsCallback, ReadPixelsContext) const override
bool getExistingBackendTexture(GrBackendTexture *outTexture, bool flushPendingGrContextIO, GrSurfaceOrigin *origin) const
GrSurfaceOrigin origin() const override
bool onHasMipmaps() const override
GrSemaphoresSubmitted flush(GrDirectContext *, const GrFlushInfo &) const override
bool surfaceMustCopyOnWrite(GrSurfaceProxy *surfaceProxy) const
void onAsyncRescaleAndReadPixels(const SkImageInfo &, SkIRect srcRect, RescaleGamma, RescaleMode, ReadPixelsCallback, ReadPixelsContext) const override
size_t textureSize() const override
~SkImage_Ganesh() override
std::tuple< GrSurfaceProxyView, GrColorType > asView(GrRecordingContext *, skgpu::Mipmapped, GrImageTexGenPolicy) const override
static sk_sp< SkImage > MakeWithVolatileSrc(sk_sp< GrRecordingContext > rContext, GrSurfaceProxyView volatileSrc, SkColorInfo colorInfo)
uint32_t uniqueID() const
Definition SkImage.h:311
RescaleMode
Definition SkImage.h:587
RescaleGamma
Definition SkImage.h:585
SkImage::ReadPixelsContext ReadPixelsContext
Definition Device.cpp:81
SkImage::ReadPixelsCallback ReadPixelsCallback
Definition Device.cpp:80
Mipmapped
Definition GpuTypes.h:53
Protected
Definition GpuTypes.h:61