Brian Osman | 45580d3 | 2016-11-23 09:37:01 -0500 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2016 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 GrSurfaceContext_DEFINED |
| 9 | #define GrSurfaceContext_DEFINED |
| 10 | |
Brian Salomon | 63a0a75 | 2020-06-26 13:32:09 -0400 | [diff] [blame] | 11 | #include "include/core/SkImage.h" |
Brian Salomon | e9ad998 | 2019-07-22 16:17:41 -0400 | [diff] [blame] | 12 | #include "include/core/SkRect.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 13 | #include "include/core/SkRefCnt.h" |
Mike Reed | 1efa14d | 2021-01-02 21:44:59 -0500 | [diff] [blame] | 14 | #include "include/core/SkSamplingOptions.h" |
Brian Salomon | e9ad998 | 2019-07-22 16:17:41 -0400 | [diff] [blame] | 15 | #include "include/core/SkSurface.h" |
Brian Salomon | 4bc0c1f | 2019-09-30 15:12:27 -0400 | [diff] [blame] | 16 | #include "src/gpu/GrColorInfo.h" |
Brian Salomon | 1d43530 | 2019-07-01 13:05:28 -0400 | [diff] [blame] | 17 | #include "src/gpu/GrDataUtils.h" |
Brian Salomon | 6aa6505 | 2020-01-28 12:16:53 -0500 | [diff] [blame] | 18 | #include "src/gpu/GrImageInfo.h" |
Brian Salomon | dd4087d | 2020-12-23 20:36:44 -0500 | [diff] [blame] | 19 | #include "src/gpu/GrPixmap.h" |
Brian Salomon | d63638b | 2021-03-05 14:00:07 -0500 | [diff] [blame] | 20 | #include "src/gpu/GrRenderTask.h" |
Greg Daniel | f91aeb2 | 2019-06-18 09:58:02 -0400 | [diff] [blame] | 21 | #include "src/gpu/GrSurfaceProxy.h" |
Greg Daniel | 901b98e | 2019-10-22 09:54:02 -0400 | [diff] [blame] | 22 | #include "src/gpu/GrSurfaceProxyView.h" |
Brian Osman | 45580d3 | 2016-11-23 09:37:01 -0500 | [diff] [blame] | 23 | |
Robert Phillips | 7215283 | 2017-01-25 17:31:35 -0500 | [diff] [blame] | 24 | class GrDrawingManager; |
Robert Phillips | 6989370 | 2019-02-22 11:16:30 -0500 | [diff] [blame] | 25 | class GrRecordingContext; |
Robert Phillips | 2734136 | 2016-12-14 08:46:47 -0500 | [diff] [blame] | 26 | class GrRenderTargetProxy; |
Brian Osman | 45580d3 | 2016-11-23 09:37:01 -0500 | [diff] [blame] | 27 | class GrSingleOwner; |
| 28 | class GrSurface; |
Brian Salomon | 590f567 | 2020-12-16 11:44:47 -0500 | [diff] [blame] | 29 | class GrSurfaceDrawContext; |
| 30 | class GrSurfaceFillContext; |
Robert Phillips | 2734136 | 2016-12-14 08:46:47 -0500 | [diff] [blame] | 31 | class GrSurfaceProxy; |
| 32 | class GrTextureProxy; |
Brian Osman | 45580d3 | 2016-11-23 09:37:01 -0500 | [diff] [blame] | 33 | struct SkIPoint; |
| 34 | struct SkIRect; |
| 35 | |
| 36 | /** |
| 37 | * A helper object to orchestrate commands for a particular surface |
| 38 | */ |
Brian Salomon | 57f211b | 2019-08-21 15:21:09 -0400 | [diff] [blame] | 39 | class GrSurfaceContext { |
Brian Osman | 45580d3 | 2016-11-23 09:37:01 -0500 | [diff] [blame] | 40 | public: |
Brian Salomon | eebe735 | 2020-12-09 16:37:04 -0500 | [diff] [blame] | 41 | // If the passed in GrSurfaceProxy is renderable this will return a GrSurfaceDrawContext, |
Greg Daniel | bfa19c4 | 2019-12-19 16:41:40 -0500 | [diff] [blame] | 42 | // otherwise it will return a GrSurfaceContext. |
Greg Daniel | 3912a4b | 2020-01-14 09:56:04 -0500 | [diff] [blame] | 43 | static std::unique_ptr<GrSurfaceContext> Make(GrRecordingContext*, |
| 44 | GrSurfaceProxyView readView, |
Brian Salomon | 14f99fc | 2020-12-07 12:19:47 -0500 | [diff] [blame] | 45 | const GrColorInfo&); |
Greg Daniel | bfa19c4 | 2019-12-19 16:41:40 -0500 | [diff] [blame] | 46 | |
Brian Salomon | 590f567 | 2020-12-16 11:44:47 -0500 | [diff] [blame] | 47 | // Makes either a GrSurfaceContext, GrFillDrawContext, or a GrSurfaceDrawContext, depending on |
| 48 | // GrRenderable and the GrImageInfo. |
Brian Salomon | 14f99fc | 2020-12-07 12:19:47 -0500 | [diff] [blame] | 49 | static std::unique_ptr<GrSurfaceContext> Make(GrRecordingContext*, |
| 50 | const GrImageInfo&, |
| 51 | const GrBackendFormat&, |
| 52 | SkBackingFit = SkBackingFit::kExact, |
| 53 | GrSurfaceOrigin = kTopLeft_GrSurfaceOrigin, |
| 54 | GrRenderable = GrRenderable::kNo, |
| 55 | int renderTargetSampleCnt = 1, |
| 56 | GrMipmapped = GrMipmapped::kNo, |
| 57 | GrProtected = GrProtected::kNo, |
| 58 | SkBudgeted = SkBudgeted::kYes); |
| 59 | |
Brian Salomon | 590f567 | 2020-12-16 11:44:47 -0500 | [diff] [blame] | 60 | // Same as the above but chooses the texture format using the default format for the color type. |
Brian Salomon | 14f99fc | 2020-12-07 12:19:47 -0500 | [diff] [blame] | 61 | static std::unique_ptr<GrSurfaceContext> Make(GrRecordingContext*, |
| 62 | const GrImageInfo&, |
| 63 | SkBackingFit = SkBackingFit::kExact, |
| 64 | GrSurfaceOrigin = kTopLeft_GrSurfaceOrigin, |
| 65 | GrRenderable = GrRenderable::kNo, |
| 66 | int renderTargetSampleCnt = 1, |
| 67 | GrMipmapped = GrMipmapped::kNo, |
| 68 | GrProtected = GrProtected::kNo, |
| 69 | SkBudgeted = SkBudgeted::kYes); |
Greg Daniel | bfa19c4 | 2019-12-19 16:41:40 -0500 | [diff] [blame] | 70 | |
| 71 | // If it is known that the GrSurfaceProxy is not renderable, you can directly call the the ctor |
| 72 | // here to make a GrSurfaceContext on the stack. |
Brian Salomon | 14f99fc | 2020-12-07 12:19:47 -0500 | [diff] [blame] | 73 | GrSurfaceContext(GrRecordingContext*, GrSurfaceProxyView readView, const GrColorInfo&); |
Greg Daniel | bfa19c4 | 2019-12-19 16:41:40 -0500 | [diff] [blame] | 74 | |
Brian Salomon | bf6b979 | 2019-08-21 09:38:10 -0400 | [diff] [blame] | 75 | virtual ~GrSurfaceContext() = default; |
Brian Osman | 45580d3 | 2016-11-23 09:37:01 -0500 | [diff] [blame] | 76 | |
Chris Dalton | 66deeb2 | 2021-07-23 13:57:03 -0600 | [diff] [blame^] | 77 | GrRecordingContext* recordingContext() const { return fContext; } |
Brian Salomon | 70fe17e | 2020-11-30 14:33:58 -0500 | [diff] [blame] | 78 | |
Brian Salomon | 4bc0c1f | 2019-09-30 15:12:27 -0400 | [diff] [blame] | 79 | const GrColorInfo& colorInfo() const { return fColorInfo; } |
Brian Salomon | 6aa6505 | 2020-01-28 12:16:53 -0500 | [diff] [blame] | 80 | GrImageInfo imageInfo() const { return {fColorInfo, fReadView.proxy()->dimensions()}; } |
| 81 | |
Greg Daniel | 3912a4b | 2020-01-14 09:56:04 -0500 | [diff] [blame] | 82 | GrSurfaceOrigin origin() const { return fReadView.origin(); } |
| 83 | GrSwizzle readSwizzle() const { return fReadView.swizzle(); } |
| 84 | // TODO: See if it makes sense for this to return a const& instead and require the callers to |
| 85 | // make a copy (which refs the proxy) if needed. |
| 86 | GrSurfaceProxyView readSurfaceView() { return fReadView; } |
Robert Phillips | 2c86249 | 2017-01-18 10:08:39 -0500 | [diff] [blame] | 87 | |
Brian Salomon | c524378 | 2020-04-02 12:50:34 -0400 | [diff] [blame] | 88 | SkISize dimensions() const { return fReadView.dimensions(); } |
Greg Daniel | 3912a4b | 2020-01-14 09:56:04 -0500 | [diff] [blame] | 89 | int width() const { return fReadView.proxy()->width(); } |
| 90 | int height() const { return fReadView.proxy()->height(); } |
Robert Phillips | d46697a | 2017-01-25 12:10:37 -0500 | [diff] [blame] | 91 | |
Robert Phillips | 9af0bca | 2021-05-27 19:17:55 -0400 | [diff] [blame] | 92 | GrMipmapped mipmapped() const { return fReadView.mipmapped(); } |
| 93 | |
Brian Salomon | 4d2d6f4 | 2019-07-26 14:15:11 -0400 | [diff] [blame] | 94 | const GrCaps* caps() const; |
| 95 | |
Robert Phillips | 2c86249 | 2017-01-18 10:08:39 -0500 | [diff] [blame] | 96 | /** |
Brian Salomon | dd4087d | 2020-12-23 20:36:44 -0500 | [diff] [blame] | 97 | * Reads a rectangle of pixels from the surface context. |
Adlai Holler | c95b589 | 2020-08-11 12:02:22 -0400 | [diff] [blame] | 98 | * @param dContext The direct context to use |
Brian Salomon | 1d43530 | 2019-07-01 13:05:28 -0400 | [diff] [blame] | 99 | * @param dst destination pixels for the read |
Brian Salomon | 1d43530 | 2019-07-01 13:05:28 -0400 | [diff] [blame] | 100 | * @param srcPt offset w/in the surface context from which to read |
Brian Salomon | 1d43530 | 2019-07-01 13:05:28 -0400 | [diff] [blame] | 101 | * is a GrDirectContext and fail otherwise. |
Robert Phillips | 2c86249 | 2017-01-18 10:08:39 -0500 | [diff] [blame] | 102 | */ |
Brian Salomon | dd4087d | 2020-12-23 20:36:44 -0500 | [diff] [blame] | 103 | bool readPixels(GrDirectContext* dContext, GrPixmap dst, SkIPoint srcPt); |
Robert Phillips | 2c86249 | 2017-01-18 10:08:39 -0500 | [diff] [blame] | 104 | |
Brian Salomon | 63a0a75 | 2020-06-26 13:32:09 -0400 | [diff] [blame] | 105 | using ReadPixelsCallback = SkImage::ReadPixelsCallback; |
| 106 | using ReadPixelsContext = SkImage::ReadPixelsContext; |
| 107 | using RescaleGamma = SkImage::RescaleGamma; |
Mike Reed | 1efa14d | 2021-01-02 21:44:59 -0500 | [diff] [blame] | 108 | using RescaleMode = SkImage::RescaleMode; |
Brian Salomon | 63a0a75 | 2020-06-26 13:32:09 -0400 | [diff] [blame] | 109 | |
| 110 | // GPU implementation for SkImage:: and SkSurface::asyncRescaleAndReadPixels. |
Adlai Holler | c95b589 | 2020-08-11 12:02:22 -0400 | [diff] [blame] | 111 | void asyncRescaleAndReadPixels(GrDirectContext*, |
| 112 | const SkImageInfo& info, |
Brian Salomon | 63a0a75 | 2020-06-26 13:32:09 -0400 | [diff] [blame] | 113 | const SkIRect& srcRect, |
| 114 | RescaleGamma rescaleGamma, |
Mike Reed | 1efa14d | 2021-01-02 21:44:59 -0500 | [diff] [blame] | 115 | RescaleMode, |
Brian Salomon | 63a0a75 | 2020-06-26 13:32:09 -0400 | [diff] [blame] | 116 | ReadPixelsCallback callback, |
Adlai Holler | c95b589 | 2020-08-11 12:02:22 -0400 | [diff] [blame] | 117 | ReadPixelsContext callbackContext); |
Brian Salomon | 63a0a75 | 2020-06-26 13:32:09 -0400 | [diff] [blame] | 118 | |
| 119 | // GPU implementation for SkImage:: and SkSurface::asyncRescaleAndReadPixelsYUV420. |
Adlai Holler | c95b589 | 2020-08-11 12:02:22 -0400 | [diff] [blame] | 120 | void asyncRescaleAndReadPixelsYUV420(GrDirectContext*, |
| 121 | SkYUVColorSpace yuvColorSpace, |
Brian Salomon | 63a0a75 | 2020-06-26 13:32:09 -0400 | [diff] [blame] | 122 | sk_sp<SkColorSpace> dstColorSpace, |
| 123 | const SkIRect& srcRect, |
| 124 | SkISize dstSize, |
| 125 | RescaleGamma rescaleGamma, |
Mike Reed | 1efa14d | 2021-01-02 21:44:59 -0500 | [diff] [blame] | 126 | RescaleMode, |
Brian Salomon | 63a0a75 | 2020-06-26 13:32:09 -0400 | [diff] [blame] | 127 | ReadPixelsCallback callback, |
| 128 | ReadPixelsContext context); |
| 129 | |
Robert Phillips | 2c86249 | 2017-01-18 10:08:39 -0500 | [diff] [blame] | 130 | /** |
Brian Salomon | 2c67340 | 2021-04-02 14:36:58 -0400 | [diff] [blame] | 131 | * Writes a rectangle of pixels from src into the surfaceDrawContext at the specified position. |
| 132 | * @param dContext The direct context to use |
| 133 | * @param src source for the write |
| 134 | * @param dstPt offset w/in the surface context at which to write |
Robert Phillips | 2c86249 | 2017-01-18 10:08:39 -0500 | [diff] [blame] | 135 | */ |
Brian Salomon | ea1d39b | 2021-04-01 17:06:52 -0400 | [diff] [blame] | 136 | bool writePixels(GrDirectContext* dContext, |
| 137 | GrCPixmap src, |
Brian Salomon | 75ee737 | 2021-04-06 15:04:35 -0400 | [diff] [blame] | 138 | SkIPoint dstPt); |
Greg Daniel | 6eb8c24 | 2019-06-05 10:22:24 -0400 | [diff] [blame] | 139 | |
Brian Salomon | 2c67340 | 2021-04-02 14:36:58 -0400 | [diff] [blame] | 140 | /** |
| 141 | * Fully populates either the base level or all MIP levels of the GrSurface with pixel data. |
| 142 | * @param dContext The direct context to use |
| 143 | * @param src Array of pixmaps |
| 144 | * @param numLevels Number of pixmaps in src. To succeed this must be 1 or the total |
| 145 | * number of MIP levels. |
| 146 | */ |
Brian Salomon | ea1d39b | 2021-04-01 17:06:52 -0400 | [diff] [blame] | 147 | bool writePixels(GrDirectContext* dContext, |
| 148 | const GrCPixmap src[], |
Brian Salomon | 75ee737 | 2021-04-06 15:04:35 -0400 | [diff] [blame] | 149 | int numLevels); |
Brian Salomon | 2c67340 | 2021-04-02 14:36:58 -0400 | [diff] [blame] | 150 | |
Greg Daniel | 3912a4b | 2020-01-14 09:56:04 -0500 | [diff] [blame] | 151 | GrSurfaceProxy* asSurfaceProxy() { return fReadView.proxy(); } |
| 152 | const GrSurfaceProxy* asSurfaceProxy() const { return fReadView.proxy(); } |
Greg Daniel | c61d7e3 | 2020-02-04 14:27:45 -0500 | [diff] [blame] | 153 | sk_sp<GrSurfaceProxy> asSurfaceProxyRef() { return fReadView.refProxy(); } |
Robert Phillips | f200a90 | 2017-01-30 13:27:37 -0500 | [diff] [blame] | 154 | |
Greg Daniel | 3912a4b | 2020-01-14 09:56:04 -0500 | [diff] [blame] | 155 | GrTextureProxy* asTextureProxy() { return fReadView.asTextureProxy(); } |
| 156 | const GrTextureProxy* asTextureProxy() const { return fReadView.asTextureProxy(); } |
| 157 | sk_sp<GrTextureProxy> asTextureProxyRef() { return fReadView.asTextureProxyRef(); } |
Robert Phillips | f200a90 | 2017-01-30 13:27:37 -0500 | [diff] [blame] | 158 | |
Greg Daniel | 3912a4b | 2020-01-14 09:56:04 -0500 | [diff] [blame] | 159 | GrRenderTargetProxy* asRenderTargetProxy() { return fReadView.asRenderTargetProxy(); } |
Greg Daniel | 46e366a | 2019-12-16 14:38:36 -0500 | [diff] [blame] | 160 | const GrRenderTargetProxy* asRenderTargetProxy() const { |
Greg Daniel | 3912a4b | 2020-01-14 09:56:04 -0500 | [diff] [blame] | 161 | return fReadView.asRenderTargetProxy(); |
Greg Daniel | 46e366a | 2019-12-16 14:38:36 -0500 | [diff] [blame] | 162 | } |
| 163 | sk_sp<GrRenderTargetProxy> asRenderTargetProxyRef() { |
Greg Daniel | 3912a4b | 2020-01-14 09:56:04 -0500 | [diff] [blame] | 164 | return fReadView.asRenderTargetProxyRef(); |
Greg Daniel | 46e366a | 2019-12-16 14:38:36 -0500 | [diff] [blame] | 165 | } |
Robert Phillips | 2734136 | 2016-12-14 08:46:47 -0500 | [diff] [blame] | 166 | |
John Stiles | 0fbc6a3 | 2021-06-04 14:40:57 -0400 | [diff] [blame] | 167 | virtual GrSurfaceDrawContext* asSurfaceDrawContext() { return nullptr; } |
Brian Salomon | 590f567 | 2020-12-16 11:44:47 -0500 | [diff] [blame] | 168 | virtual GrSurfaceFillContext* asFillContext() { return nullptr; } |
Robert Phillips | d46697a | 2017-01-25 12:10:37 -0500 | [diff] [blame] | 169 | |
Brian Salomon | 11ad4cc | 2020-05-15 12:07:59 -0400 | [diff] [blame] | 170 | /** |
| 171 | * Rescales the contents of srcRect. The gamma in which the rescaling occurs is controlled by |
| 172 | * RescaleGamma. It is always in the original gamut. The result is converted to the color type |
| 173 | * and color space of info after rescaling. Note: this currently requires that the info have a |
| 174 | * different size than srcRect. Though, it could be relaxed to allow non-scaling color |
| 175 | * conversions. |
| 176 | */ |
Brian Salomon | bacbb92 | 2021-01-21 19:48:00 -0500 | [diff] [blame] | 177 | std::unique_ptr<GrSurfaceFillContext> rescale(const GrImageInfo& info, |
Brian Salomon | eebe735 | 2020-12-09 16:37:04 -0500 | [diff] [blame] | 178 | GrSurfaceOrigin, |
| 179 | SkIRect srcRect, |
| 180 | SkImage::RescaleGamma, |
Mike Reed | 1efa14d | 2021-01-02 21:44:59 -0500 | [diff] [blame] | 181 | SkImage::RescaleMode); |
Brian Salomon | 11ad4cc | 2020-05-15 12:07:59 -0400 | [diff] [blame] | 182 | |
Brian Salomon | 1c86b63 | 2020-12-11 12:36:01 -0500 | [diff] [blame] | 183 | /** |
Brian Salomon | bacbb92 | 2021-01-21 19:48:00 -0500 | [diff] [blame] | 184 | * Like the above but allows the caller ot specify a destination fill context and |
Brian Salomon | 1c86b63 | 2020-12-11 12:36:01 -0500 | [diff] [blame] | 185 | * rect within that context. The dst rect must be contained by the dst or this will fail. |
| 186 | */ |
Brian Salomon | bacbb92 | 2021-01-21 19:48:00 -0500 | [diff] [blame] | 187 | bool rescaleInto(GrSurfaceFillContext* dst, |
Brian Salomon | 1c86b63 | 2020-12-11 12:36:01 -0500 | [diff] [blame] | 188 | SkIRect dstRect, |
| 189 | SkIRect srcRect, |
| 190 | SkImage::RescaleGamma, |
Mike Reed | 1efa14d | 2021-01-02 21:44:59 -0500 | [diff] [blame] | 191 | SkImage::RescaleMode); |
Brian Salomon | 1c86b63 | 2020-12-11 12:36:01 -0500 | [diff] [blame] | 192 | |
Greg Daniel | 46cfbc6 | 2019-06-07 11:43:30 -0400 | [diff] [blame] | 193 | #if GR_TEST_UTILS |
Brian Salomon | 982127b | 2021-01-21 10:43:35 -0500 | [diff] [blame] | 194 | bool testCopy(sk_sp<GrSurfaceProxy> src, const SkIRect& srcRect, const SkIPoint& dstPoint) { |
Brian Salomon | d63638b | 2021-03-05 14:00:07 -0500 | [diff] [blame] | 195 | return this->copy(std::move(src), srcRect, dstPoint) != nullptr; |
Greg Daniel | 46cfbc6 | 2019-06-07 11:43:30 -0400 | [diff] [blame] | 196 | } |
| 197 | |
Brian Salomon | 982127b | 2021-01-21 10:43:35 -0500 | [diff] [blame] | 198 | bool testCopy(sk_sp<GrSurfaceProxy> src) { |
| 199 | auto rect = SkIRect::MakeSize(src->dimensions()); |
Brian Salomon | d63638b | 2021-03-05 14:00:07 -0500 | [diff] [blame] | 200 | return this->copy(std::move(src), rect, {0, 0}) != nullptr; |
Greg Daniel | 46cfbc6 | 2019-06-07 11:43:30 -0400 | [diff] [blame] | 201 | } |
| 202 | #endif |
| 203 | |
Brian Osman | 45580d3 | 2016-11-23 09:37:01 -0500 | [diff] [blame] | 204 | protected: |
Robert Phillips | 0d075de | 2019-03-04 11:08:13 -0500 | [diff] [blame] | 205 | GrDrawingManager* drawingManager(); |
| 206 | const GrDrawingManager* drawingManager() const; |
Brian Osman | 45580d3 | 2016-11-23 09:37:01 -0500 | [diff] [blame] | 207 | |
Greg Daniel | 46e366a | 2019-12-16 14:38:36 -0500 | [diff] [blame] | 208 | SkDEBUGCODE(void validate() const;) |
Robert Phillips | 2de8cfa | 2017-06-28 10:33:41 -0400 | [diff] [blame] | 209 | |
Brian Salomon | 70fe17e | 2020-11-30 14:33:58 -0500 | [diff] [blame] | 210 | SkDEBUGCODE(GrSingleOwner* singleOwner() const;) |
Brian Osman | 45580d3 | 2016-11-23 09:37:01 -0500 | [diff] [blame] | 211 | |
Robert Phillips | 6989370 | 2019-02-22 11:16:30 -0500 | [diff] [blame] | 212 | GrRecordingContext* fContext; |
Brian Osman | 45580d3 | 2016-11-23 09:37:01 -0500 | [diff] [blame] | 213 | |
Greg Daniel | 3912a4b | 2020-01-14 09:56:04 -0500 | [diff] [blame] | 214 | GrSurfaceProxyView fReadView; |
Greg Daniel | 901b98e | 2019-10-22 09:54:02 -0400 | [diff] [blame] | 215 | |
Brian Salomon | 4d2d6f4 | 2019-07-26 14:15:11 -0400 | [diff] [blame] | 216 | // Inserts a transfer, part of the implementation of asyncReadPixels and |
| 217 | // asyncRescaleAndReadPixelsYUV420(). |
| 218 | struct PixelTransferResult { |
| 219 | using ConversionFn = void(void* dst, const void* mappedBuffer); |
| 220 | // If null then the transfer could not be performed. Otherwise this buffer will contain |
| 221 | // the pixel data when the transfer is complete. |
| 222 | sk_sp<GrGpuBuffer> fTransferBuffer; |
| 223 | // If this is null then the transfer buffer will contain the data in the requested |
| 224 | // color type. Otherwise, when the transfer is done this must be called to convert |
| 225 | // from the transfer buffer's color type to the requested color type. |
| 226 | std::function<ConversionFn> fPixelConverter; |
| 227 | }; |
| 228 | PixelTransferResult transferPixels(GrColorType colorType, const SkIRect& rect); |
| 229 | |
Brian Salomon | 63a0a75 | 2020-06-26 13:32:09 -0400 | [diff] [blame] | 230 | // The async read step of asyncRescaleAndReadPixels() |
Adlai Holler | c95b589 | 2020-08-11 12:02:22 -0400 | [diff] [blame] | 231 | void asyncReadPixels(GrDirectContext*, |
| 232 | const SkIRect& srcRect, |
| 233 | SkColorType, |
| 234 | ReadPixelsCallback, |
| 235 | ReadPixelsContext); |
Brian Salomon | 63a0a75 | 2020-06-26 13:32:09 -0400 | [diff] [blame] | 236 | |
Robert Phillips | e305cc1f | 2016-12-14 12:19:05 -0500 | [diff] [blame] | 237 | private: |
Greg Daniel | 46cfbc6 | 2019-06-07 11:43:30 -0400 | [diff] [blame] | 238 | friend class GrSurfaceProxy; // for copy |
| 239 | |
Greg Daniel | 46e366a | 2019-12-16 14:38:36 -0500 | [diff] [blame] | 240 | SkDEBUGCODE(virtual void onValidate() const {}) |
| 241 | |
Greg Daniel | 46cfbc6 | 2019-06-07 11:43:30 -0400 | [diff] [blame] | 242 | /** |
| 243 | * Copy 'src' into the proxy backing this context. This call will not do any draw fallback. |
| 244 | * Currently only writePixels and replaceRenderTarget call this directly. All other copies |
| 245 | * should go through GrSurfaceProxy::Copy. |
| 246 | * @param src src of pixels |
Greg Daniel | 46cfbc6 | 2019-06-07 11:43:30 -0400 | [diff] [blame] | 247 | * @param dstPoint the origin of the 'srcRect' in the destination coordinate space |
Brian Salomon | d63638b | 2021-03-05 14:00:07 -0500 | [diff] [blame] | 248 | * @return a task (that may be skippable by calling canSkip) if successful and |
| 249 | * null otherwise. |
Greg Daniel | 46cfbc6 | 2019-06-07 11:43:30 -0400 | [diff] [blame] | 250 | * |
| 251 | * Note: Notionally, 'srcRect' is clipped to 'src's extent with 'dstPoint' being adjusted. |
| 252 | * Then the 'srcRect' offset by 'dstPoint' is clipped against the dst's extent. |
| 253 | * The end result is only valid src pixels and dst pixels will be touched but the copied |
| 254 | * regions will not be shifted. The 'src' must have the same origin as the backing proxy |
| 255 | * of fSurfaceContext. |
| 256 | */ |
Brian Salomon | d63638b | 2021-03-05 14:00:07 -0500 | [diff] [blame] | 257 | sk_sp<GrRenderTask> copy(sk_sp<GrSurfaceProxy> src, SkIRect srcRect, SkIPoint dstPoint); |
Greg Daniel | 46cfbc6 | 2019-06-07 11:43:30 -0400 | [diff] [blame] | 258 | |
Brian Salomon | 2c67340 | 2021-04-02 14:36:58 -0400 | [diff] [blame] | 259 | bool internalWritePixels(GrDirectContext* dContext, |
| 260 | const GrCPixmap src[], |
| 261 | int numLevels, |
Brian Salomon | 75ee737 | 2021-04-06 15:04:35 -0400 | [diff] [blame] | 262 | SkIPoint); |
Brian Salomon | 2c67340 | 2021-04-02 14:36:58 -0400 | [diff] [blame] | 263 | |
Brian Salomon | 63a0a75 | 2020-06-26 13:32:09 -0400 | [diff] [blame] | 264 | class AsyncReadResult; |
| 265 | |
Brian Salomon | 4bc0c1f | 2019-09-30 15:12:27 -0400 | [diff] [blame] | 266 | GrColorInfo fColorInfo; |
Brian Salomon | f3569f0 | 2017-10-24 12:52:33 -0400 | [diff] [blame] | 267 | |
John Stiles | 7571f9e | 2020-09-02 22:42:33 -0400 | [diff] [blame] | 268 | using INHERITED = SkRefCnt; |
Brian Osman | 45580d3 | 2016-11-23 09:37:01 -0500 | [diff] [blame] | 269 | }; |
| 270 | |
| 271 | #endif |