Flutter Engine
The Flutter Engine
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
16#include <string_view>
17
18enum class SkBackingFit;
19
20namespace skgpu::graphite {
21
22class Context;
23class Device;
24class DrawContext;
25class Image;
26class Recorder;
27class TextureProxy;
28
29class Image_Base : public SkImage_Base {
30public:
31 ~Image_Base() override;
32
33 // Must be called at the time of recording an action that reads from the image, be it a draw
34 // or a copy operation. `drawContext` can be null if the "use" is scoped by a draw.
35 void notifyInUse(Recorder*, DrawContext* drawContext) const;
36
37 // Returns true if this image is linked to a device that may render their shared texture(s).
38 bool isDynamic() const;
39
40 // Always copy this image, even if 'subset' and mipmapping match this image exactly.
41 // The base implementation performs all copies as draws.
43 const SkIRect& subset,
47 std::string_view label) const;
48
49 // From SkImage.h
50 // TODO(egdaniel) This feels wrong. Re-think how this method is used and works.
51 bool isValid(GrRecordingContext*) const override { return true; }
52
53 // From SkImage_Base.h
54 sk_sp<SkImage> onMakeSubset(Recorder*, const SkIRect&, RequiredProperties) const override;
56 SkColorType targetCT,
57 sk_sp<SkColorSpace> targetCS,
58 RequiredProperties) const override;
59
60 // No-ops for Ganesh APIs
62 const SkImageInfo& dstInfo,
63 void* dstPixels,
64 size_t dstRowBytes,
65 int srcX,
66 int srcY,
67 CachingHint) const override { return false; }
68
70 SkBitmap*,
71 CachingHint = kAllow_CachingHint) const override { return false; }
72
73 sk_sp<SkImage> onMakeSubset(GrDirectContext*, const SkIRect&) const override;
74
77 GrDirectContext*) const override;
78
80 SkIRect srcRect,
84 ReadPixelsContext) const override;
85
87 bool readAlpha,
89 SkIRect srcRect,
90 SkISize dstSize,
94 ReadPixelsContext) const override;
95
96protected:
97 Image_Base(const SkImageInfo& info, uint32_t uniqueID);
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
Definition: SkBackingFit.h:16
SkColorType
Definition: SkColorType.h:19
SkYUVColorSpace
Definition: SkImageInfo.h:68
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
Image_Base(const SkImageInfo &info, uint32_t uniqueID)
void linkDevice(sk_sp< Device >)
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
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 *, DrawContext *drawContext) const
virtual sk_sp< Image > copyImage(Recorder *, const SkIRect &subset, Budgeted, Mipmapped, SkBackingFit, std::string_view label) const
sk_sp< SkImage > onMakeColorTypeAndColorSpace(SkColorType, sk_sp< SkColorSpace >, GrDirectContext *) const override
bool getROPixels(GrDirectContext *, SkBitmap *, CachingHint=kAllow_CachingHint) const override
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
Definition: SkRect.h:32
Definition: SkSize.h:16