Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Image_Base_Graphite.h
Go to the documentation of this file.
1/*
2 * Copyright 2023 Google LLC
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 skgpu_graphite_Image_Base_Graphite_DEFINED
9#define skgpu_graphite_Image_Base_Graphite_DEFINED
10
13#include "src/base/SkSpinlock.h"
15
16enum class SkBackingFit;
17
18namespace skgpu::graphite {
19
20class Context;
21class Device;
22class Image;
23class Recorder;
24class TextureProxy;
25
26class Image_Base : public SkImage_Base {
27public:
28 ~Image_Base() override;
29
30 // Must be called at the time of recording an action that reads from the image, be it a draw
31 // or a copy operation.
32 void notifyInUse(Recorder*) const;
33
34 // Returns true if this image is linked to a device that may render their shared texture(s).
35 bool isDynamic() const;
36
37 // Always copy this image, even if 'subset' and mipmapping match this image exactly.
38 // The base implementation performs all copies as draws.
39 virtual sk_sp<Image> copyImage(Recorder*, const SkIRect& subset,
41
42 // From SkImage.h
43 // TODO(egdaniel) This feels wrong. Re-think how this method is used and works.
44 bool isValid(GrRecordingContext*) const override { return true; }
45
46 // From SkImage_Base.h
47 sk_sp<SkImage> onMakeSubset(Recorder*, const SkIRect&, RequiredProperties) const override;
49 SkColorType targetCT,
50 sk_sp<SkColorSpace> targetCS,
51 RequiredProperties) const override;
52
53 // No-ops for Ganesh APIs
55 const SkImageInfo& dstInfo,
56 void* dstPixels,
57 size_t dstRowBytes,
58 int srcX,
59 int srcY,
60 CachingHint) const override { return false; }
61
63 SkBitmap*,
64 CachingHint = kAllow_CachingHint) const override { return false; }
65
66 sk_sp<SkImage> onMakeSubset(GrDirectContext*, const SkIRect&) const override;
67
70 GrDirectContext*) const override;
71
73 SkIRect srcRect,
77 ReadPixelsContext) const override;
78
80 bool readAlpha,
82 SkIRect srcRect,
83 SkISize dstSize,
87 ReadPixelsContext) const override;
88
89protected:
90 Image_Base(const SkImageInfo& info, uint32_t uniqueID);
91
92 // Create a new flattened copy of the base image using draw operations.
94 const Image_Base*,
95 const SkIRect& subset,
96 const SkColorInfo& dstColorInfo,
98
99 // If the passed-in image is linked with Devices that modify its texture, copy the links to
100 // this Image. This is used when a new Image is created that shares the same texture proxy as
101 // a dynamic image. This can only be called before the Image has been returned from a factory.
102 void linkDevices(const Image_Base*);
103 // Link this image to the Device that can write to their shared texture proxy, so that when the
104 // image is sampled in a draw, any pending work from the Device is automatically flushed. This
105 // can only be called before the Image has been returned from a factory function.
107
108private:
109 // Devices are flushed in notifyImageInUse(). If a linked device is uniquely held by the image
110 // or if it's marked as immutable, it will be unlinked (allowing it to be destroyed eventually).
111 // If all linked devices are removed, this array will become empty. Other than initialization,
112 // this array cannot transition from an empty state to having linked devices, so while it's
113 // empty no locking is required.
114 mutable skia_private::STArray<1, sk_sp<Device>> fLinkedDevices SK_GUARDED_BY(fDeviceLinkLock);
115 mutable SkSpinlock fDeviceLinkLock;
116};
117
118} // namespace skgpu::graphite
119
120#endif // skgpu_graphite_Image_Base_Graphite_DEFINED
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
Definition DM.cpp:213
SkBackingFit
SkColorType
Definition SkColorType.h:19
SkYUVColorSpace
Definition SkImageInfo.h:68
#define SK_GUARDED_BY(x)
uint32_t uniqueID() const
Definition SkImage.h:311
RescaleMode
Definition SkImage.h:587
RescaleGamma
Definition SkImage.h:585
CachingHint
Definition SkImage.h:463
@ kAllow_CachingHint
allows internally caching decoded and copied pixels
Definition SkImage.h:464
void onAsyncRescaleAndReadPixels(const SkImageInfo &, SkIRect srcRect, RescaleGamma, RescaleMode, ReadPixelsCallback, ReadPixelsContext) const override
bool onReadPixels(GrDirectContext *, const SkImageInfo &dstInfo, void *dstPixels, size_t dstRowBytes, int srcX, int srcY, CachingHint) const override
virtual sk_sp< Image > copyImage(Recorder *, const SkIRect &subset, Budgeted, Mipmapped, SkBackingFit) const
sk_sp< SkImage > onMakeSubset(Recorder *, const SkIRect &, RequiredProperties) const override
sk_sp< SkImage > makeColorTypeAndColorSpace(Recorder *, SkColorType targetCT, sk_sp< SkColorSpace > targetCS, RequiredProperties) const override
void notifyInUse(Recorder *) const
sk_sp< SkImage > onMakeColorTypeAndColorSpace(SkColorType, sk_sp< SkColorSpace >, GrDirectContext *) const override
bool getROPixels(GrDirectContext *, SkBitmap *, CachingHint=kAllow_CachingHint) const override
static sk_sp< Image > CopyAsDraw(Recorder *, const Image_Base *, const SkIRect &subset, const SkColorInfo &dstColorInfo, Budgeted, Mipmapped, SkBackingFit)
void linkDevices(const Image_Base *)
void onAsyncRescaleAndReadPixelsYUV420(SkYUVColorSpace, bool readAlpha, sk_sp< SkColorSpace >, SkIRect srcRect, SkISize dstSize, RescaleGamma, RescaleMode, ReadPixelsCallback, ReadPixelsContext) const override
bool isValid(GrRecordingContext *) const override
SkImage::ReadPixelsContext ReadPixelsContext
Definition Device.cpp:81
SkImage::ReadPixelsCallback ReadPixelsCallback
Definition Device.cpp:80
CanvasImage Image
Definition dart_ui.cc:55
Budgeted
Definition GpuTypes.h:35
Mipmapped
Definition GpuTypes.h:53