blob: c8b6e79246bd593198990c6f0a4825d66bf33f6c [file] [log] [blame]
reed@google.comc9062042012-07-30 18:06:00 +00001/*
2 * Copyright 2012 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
Brian Salomonab32f652019-05-10 14:24:50 -04008#include <atomic>
Brian Salomon201700f2019-05-17 12:05:44 -04009#include <cmath>
Mike Kleinc0bd9f92019-04-23 12:05:21 -050010#include "include/core/SkCanvas.h"
11#include "include/core/SkFontLCDConfig.h"
12#include "include/gpu/GrBackendSurface.h"
Brian Salomonab32f652019-05-10 14:24:50 -040013#include "src/core/SkAutoPixmapStorage.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050014#include "src/core/SkImagePriv.h"
15#include "src/image/SkSurface_Base.h"
Robert Phillips8caf85f2018-04-05 09:30:38 -040016
reed4a8126e2014-09-22 07:29:03 -070017static SkPixelGeometry compute_default_geometry() {
18 SkFontLCDConfig::LCDOrder order = SkFontLCDConfig::GetSubpixelOrder();
19 if (SkFontLCDConfig::kNONE_LCDOrder == order) {
20 return kUnknown_SkPixelGeometry;
21 } else {
22 // Bit0 is RGB(0), BGR(1)
23 // Bit1 is H(0), V(1)
24 const SkPixelGeometry gGeo[] = {
25 kRGB_H_SkPixelGeometry,
26 kBGR_H_SkPixelGeometry,
27 kRGB_V_SkPixelGeometry,
28 kBGR_V_SkPixelGeometry,
29 };
30 int index = 0;
31 if (SkFontLCDConfig::kBGR_LCDOrder == order) {
32 index |= 1;
33 }
34 if (SkFontLCDConfig::kVertical_LCDOrientation == SkFontLCDConfig::GetSubpixelOrientation()){
35 index |= 2;
36 }
37 return gGeo[index];
38 }
39}
40
41SkSurfaceProps::SkSurfaceProps() : fFlags(0), fPixelGeometry(kUnknown_SkPixelGeometry) {}
42
43SkSurfaceProps::SkSurfaceProps(InitType) : fFlags(0), fPixelGeometry(compute_default_geometry()) {}
44
45SkSurfaceProps::SkSurfaceProps(uint32_t flags, InitType)
46 : fFlags(flags)
47 , fPixelGeometry(compute_default_geometry())
48{}
49
50SkSurfaceProps::SkSurfaceProps(uint32_t flags, SkPixelGeometry pg)
51 : fFlags(flags), fPixelGeometry(pg)
52{}
53
reed4af267b2014-11-21 08:46:37 -080054SkSurfaceProps::SkSurfaceProps(const SkSurfaceProps& other)
55 : fFlags(other.fFlags)
56 , fPixelGeometry(other.fPixelGeometry)
57{}
58
reed@google.com889b09e2012-07-27 21:10:42 +000059///////////////////////////////////////////////////////////////////////////////
60
reed4a8126e2014-09-22 07:29:03 -070061SkSurface_Base::SkSurface_Base(int width, int height, const SkSurfaceProps* props)
Robert Phillipsa54ccb22017-01-31 07:40:33 -050062 : INHERITED(width, height, props) {
reed@google.com9ea5a3b2012-07-30 21:03:46 +000063}
reed@google.com889b09e2012-07-27 21:10:42 +000064
reed4a8126e2014-09-22 07:29:03 -070065SkSurface_Base::SkSurface_Base(const SkImageInfo& info, const SkSurfaceProps* props)
Robert Phillipsa54ccb22017-01-31 07:40:33 -050066 : INHERITED(info, props) {
reed@google.com1360c522014-01-08 21:25:26 +000067}
68
reed@google.com9ea5a3b2012-07-30 21:03:46 +000069SkSurface_Base::~SkSurface_Base() {
reed@google.com97af1a62012-08-28 12:19:02 +000070 // in case the canvas outsurvives us, we null the callback
71 if (fCachedCanvas) {
halcanary96fcdcc2015-08-27 07:41:13 -070072 fCachedCanvas->setSurfaceBase(nullptr);
reed@google.com97af1a62012-08-28 12:19:02 +000073 }
reed@google.com9ea5a3b2012-07-30 21:03:46 +000074}
reed@google.com889b09e2012-07-27 21:10:42 +000075
Robert Phillips8caf85f2018-04-05 09:30:38 -040076GrBackendTexture SkSurface_Base::onGetBackendTexture(BackendHandleAccess) {
77 return GrBackendTexture(); // invalid
78}
79
80GrBackendRenderTarget SkSurface_Base::onGetBackendRenderTarget(BackendHandleAccess) {
81 return GrBackendRenderTarget(); // invalid
82}
83
Brian Salomonaad83152019-05-24 10:16:35 -040084bool SkSurface_Base::onReplaceBackendTexture(const GrBackendTexture&,
85 GrSurfaceOrigin,
86 TextureReleaseProc,
87 ReleaseContext) {
88 return false;
89}
90
reed4a8126e2014-09-22 07:29:03 -070091void SkSurface_Base::onDraw(SkCanvas* canvas, SkScalar x, SkScalar y, const SkPaint* paint) {
Robert Phillipsac6b1fa2017-03-20 08:38:50 -040092 auto image = this->makeImageSnapshot();
reed@google.com889b09e2012-07-27 21:10:42 +000093 if (image) {
piotaixrb5fae932014-09-24 13:03:30 -070094 canvas->drawImage(image, x, y, paint);
reed@google.com889b09e2012-07-27 21:10:42 +000095 }
96}
97
Brian Salomon031b0ba2019-05-23 11:05:26 -040098void SkSurface_Base::onAsyncRescaleAndReadPixels(const SkImageInfo& info, const SkIRect& srcRect,
99 SkSurface::RescaleGamma rescaleGamma,
100 SkFilterQuality rescaleQuality,
101 SkSurface::ReadPixelsCallback callback,
102 SkSurface::ReadPixelsContext context) {
103 int srcW = srcRect.width();
104 int srcH = srcRect.height();
105 float sx = (float)info.width() / srcW;
106 float sy = (float)info.height() / srcH;
107 // How many bilerp/bicubic steps to do in X and Y. + means upscaling, - means downscaling.
108 int stepsX;
109 int stepsY;
110 if (rescaleQuality > kNone_SkFilterQuality) {
111 stepsX = static_cast<int>((sx > 1.f) ? std::ceil(std::log2f(sx))
112 : std::floor(std::log2f(sx)));
113 stepsY = static_cast<int>((sy > 1.f) ? std::ceil(std::log2f(sy))
114 : std::floor(std::log2f(sy)));
115 } else {
116 stepsX = sx != 1.f;
117 stepsY = sy != 1.f;
118 }
119
120 SkPaint paint;
121 paint.setBlendMode(SkBlendMode::kSrc);
122 if (stepsX < 0 || stepsY < 0) {
123 // Don't trigger MIP generation. We don't currently have a way to trigger bicubic for
124 // downscaling draws.
125 rescaleQuality = std::min(rescaleQuality, kLow_SkFilterQuality);
126 }
127 paint.setFilterQuality(rescaleQuality);
128 sk_sp<SkSurface> src(SkRef(this));
129 int srcX = srcRect.fLeft;
130 int srcY = srcRect.fTop;
131 SkCanvas::SrcRectConstraint constraint = SkCanvas::kStrict_SrcRectConstraint;
132 // Assume we should ignore the rescale linear request if the surface has no color space since
133 // it's unclear how we'd linearize from an unknown color space.
134 if (rescaleGamma == SkSurface::RescaleGamma::kLinear &&
135 this->getCanvas()->imageInfo().colorSpace() &&
136 !this->getCanvas()->imageInfo().colorSpace()->gammaIsLinear()) {
137 auto cs = this->getCanvas()->imageInfo().colorSpace()->makeLinearGamma();
138 // Promote to F16 color type to preserve precision.
139 auto ii = SkImageInfo::Make(srcW, srcH, kRGBA_F16_SkColorType,
140 this->getCanvas()->imageInfo().alphaType(), std::move(cs));
141 auto linearSurf = this->makeSurface(ii);
142 if (!linearSurf) {
143 // Maybe F16 isn't supported? Try again with original color type.
144 ii = ii.makeColorType(this->getCanvas()->imageInfo().colorType());
145 linearSurf = this->makeSurface(ii);
146 if (!linearSurf) {
147 callback(context, nullptr, 0);
148 return;
149 }
150 }
151 this->draw(linearSurf->getCanvas(), -srcX, -srcY, &paint);
152 src = std::move(linearSurf);
153 srcX = 0;
154 srcY = 0;
155 constraint = SkCanvas::kFast_SrcRectConstraint;
156 }
157 while (stepsX || stepsY) {
158 int nextW = info.width();
159 int nextH = info.height();
160 if (stepsX < 0) {
161 nextW = info.width() << (-stepsX - 1);
162 stepsX++;
163 } else if (stepsX != 0) {
164 if (stepsX > 1) {
165 nextW = srcW * 2;
166 }
167 --stepsX;
168 }
169 if (stepsY < 0) {
170 nextH = info.height() << (-stepsY - 1);
171 stepsY++;
172 } else if (stepsY != 0) {
173 if (stepsY > 1) {
174 nextH = srcH * 2;
175 }
176 --stepsY;
177 }
178 auto ii = src->getCanvas()->imageInfo().makeWH(nextW, nextH);
179 if (!stepsX && !stepsY) {
180 // Might as well fold conversion to final info in the last step.
181 ii = info;
182 }
183 auto next = this->makeSurface(ii);
184 if (!next) {
185 callback(context, nullptr, 0);
186 return;
187 }
188 next->getCanvas()->drawImageRect(
189 src->makeImageSnapshot(), SkIRect::MakeXYWH(srcX, srcY, srcW, srcH),
190 SkRect::MakeWH((float)nextW, (float)nextH), &paint, constraint);
191 src = std::move(next);
192 srcX = srcY = 0;
193 srcW = nextW;
194 srcH = nextH;
195 constraint = SkCanvas::kFast_SrcRectConstraint;
196 }
197
Brian Salomonab32f652019-05-10 14:24:50 -0400198 SkAutoPixmapStorage pm;
199 pm.alloc(info);
Brian Salomon031b0ba2019-05-23 11:05:26 -0400200 if (src->readPixels(pm, srcX, srcY)) {
Brian Salomonab32f652019-05-10 14:24:50 -0400201 callback(context, pm.addr(), pm.rowBytes());
202 } else {
203 callback(context, nullptr, 0);
204 }
205}
206
Brian Salomon024bd002019-06-11 11:38:16 -0400207void SkSurface_Base::onAsyncRescaleAndReadPixelsYUV420(
208 SkYUVColorSpace yuvColorSpace, sk_sp<SkColorSpace> dstColorSpace, const SkIRect& srcRect,
209 int dstW, int dstH, RescaleGamma rescaleGamma, SkFilterQuality rescaleQuality,
210 ReadPixelsCallbackYUV420 callback, ReadPixelsContext context) {
211 // TODO: Call non-YUV asyncRescaleAndReadPixels and then make our callback convert to YUV and
212 // call client's callback.
213 callback(context, nullptr, nullptr);
214}
215
reedc83a2972015-07-16 07:40:45 -0700216bool SkSurface_Base::outstandingImageSnapshot() const {
217 return fCachedImage && !fCachedImage->unique();
218}
219
commit-bot@chromium.orgc4c98702013-04-22 14:28:01 +0000220void SkSurface_Base::aboutToDraw(ContentChangeMode mode) {
reed@google.com97af1a62012-08-28 12:19:02 +0000221 this->dirtyGenerationID();
222
commit-bot@chromium.org28361fa2014-03-28 16:08:05 +0000223 SkASSERT(!fCachedCanvas || fCachedCanvas->getSurfaceBase() == this);
reed@google.com97af1a62012-08-28 12:19:02 +0000224
bsalomon49f085d2014-09-05 13:34:00 -0700225 if (fCachedImage) {
reed@google.com97af1a62012-08-28 12:19:02 +0000226 // the surface may need to fork its backend, if its sharing it with
227 // the cached image. Note: we only call if there is an outstanding owner
228 // on the image (besides us).
reed26e0e582015-07-29 11:44:52 -0700229 bool unique = fCachedImage->unique();
230 if (!unique) {
commit-bot@chromium.orgc4c98702013-04-22 14:28:01 +0000231 this->onCopyOnWrite(mode);
reed@google.com97af1a62012-08-28 12:19:02 +0000232 }
233
234 // regardless of copy-on-write, we must drop our cached image now, so
235 // that the next request will get our new contents.
Robert Phillipsa54ccb22017-01-31 07:40:33 -0500236 fCachedImage.reset();
reed26e0e582015-07-29 11:44:52 -0700237
238 if (unique) {
239 // Our content isn't held by any image now, so we can consider that content mutable.
240 // Raster surfaces need to be told it's safe to consider its pixels mutable again.
241 // We make this call after the ->unref() so the subclass can assert there are no images.
242 this->onRestoreBackingMutability();
243 }
commit-bot@chromium.org28361fa2014-03-28 16:08:05 +0000244 } else if (kDiscard_ContentChangeMode == mode) {
245 this->onDiscard();
reed@google.com97af1a62012-08-28 12:19:02 +0000246 }
247}
248
249uint32_t SkSurface_Base::newGenerationID() {
commit-bot@chromium.org28361fa2014-03-28 16:08:05 +0000250 SkASSERT(!fCachedCanvas || fCachedCanvas->getSurfaceBase() == this);
Mike Klein0ec1c572018-12-04 11:52:51 -0500251 static std::atomic<uint32_t> nextID{1};
252 return nextID++;
reed@google.com97af1a62012-08-28 12:19:02 +0000253}
254
reed@google.com889b09e2012-07-27 21:10:42 +0000255static SkSurface_Base* asSB(SkSurface* surface) {
256 return static_cast<SkSurface_Base*>(surface);
257}
258
Robert Phillips9907e6e2019-06-25 14:47:04 -0400259static const SkSurface_Base* asConstSB(const SkSurface* surface) {
260 return static_cast<const SkSurface_Base*>(surface);
261}
262
reed@google.com889b09e2012-07-27 21:10:42 +0000263///////////////////////////////////////////////////////////////////////////////
264
reed4a8126e2014-09-22 07:29:03 -0700265SkSurface::SkSurface(int width, int height, const SkSurfaceProps* props)
266 : fProps(SkSurfacePropsCopyOrDefault(props)), fWidth(width), fHeight(height)
267{
reedb2497c22014-12-31 12:31:43 -0800268 SkASSERT(fWidth > 0);
269 SkASSERT(fHeight > 0);
reed@google.com1360c522014-01-08 21:25:26 +0000270 fGenerationID = 0;
271}
272
reed4a8126e2014-09-22 07:29:03 -0700273SkSurface::SkSurface(const SkImageInfo& info, const SkSurfaceProps* props)
274 : fProps(SkSurfacePropsCopyOrDefault(props)), fWidth(info.width()), fHeight(info.height())
275{
reedb2497c22014-12-31 12:31:43 -0800276 SkASSERT(fWidth > 0);
277 SkASSERT(fHeight > 0);
reed@google.com889b09e2012-07-27 21:10:42 +0000278 fGenerationID = 0;
279}
280
Mike Reed4b203ad2019-06-17 17:45:01 -0400281SkImageInfo SkSurface::imageInfo() {
282 // TODO: do we need to go through canvas for this?
283 return this->getCanvas()->imageInfo();
284}
285
reed@google.com97af1a62012-08-28 12:19:02 +0000286uint32_t SkSurface::generationID() {
287 if (0 == fGenerationID) {
288 fGenerationID = asSB(this)->newGenerationID();
289 }
290 return fGenerationID;
291}
292
commit-bot@chromium.orgc4c98702013-04-22 14:28:01 +0000293void SkSurface::notifyContentWillChange(ContentChangeMode mode) {
294 asSB(this)->aboutToDraw(mode);
reed@google.com97af1a62012-08-28 12:19:02 +0000295}
296
reed@google.com9ea5a3b2012-07-30 21:03:46 +0000297SkCanvas* SkSurface::getCanvas() {
298 return asSB(this)->getCachedCanvas();
reed@google.com889b09e2012-07-27 21:10:42 +0000299}
300
Robert Phillipsac6b1fa2017-03-20 08:38:50 -0400301sk_sp<SkImage> SkSurface::makeImageSnapshot() {
302 return asSB(this)->refCachedImage();
reed@google.com889b09e2012-07-27 21:10:42 +0000303}
304
Mike Reed114bde82018-11-21 09:12:09 -0500305sk_sp<SkImage> SkSurface::makeImageSnapshot(const SkIRect& srcBounds) {
306 const SkIRect surfBounds = { 0, 0, fWidth, fHeight };
307 SkIRect bounds = srcBounds;
308 if (!bounds.intersect(surfBounds)) {
309 return nullptr;
310 }
311 SkASSERT(!bounds.isEmpty());
312 if (bounds == surfBounds) {
313 return this->makeImageSnapshot();
314 } else {
315 return asSB(this)->onNewImageSnapshot(&bounds);
316 }
317}
318
reede8f30622016-03-23 18:59:25 -0700319sk_sp<SkSurface> SkSurface::makeSurface(const SkImageInfo& info) {
mike@reedtribe.orgb9476252012-11-15 02:37:45 +0000320 return asSB(this)->onNewSurface(info);
reed@google.com889b09e2012-07-27 21:10:42 +0000321}
322
Mike Reed4b203ad2019-06-17 17:45:01 -0400323sk_sp<SkSurface> SkSurface::makeSurface(int width, int height) {
324 return this->makeSurface(this->imageInfo().makeWH(width, height));
325}
326
reed@google.com889b09e2012-07-27 21:10:42 +0000327void SkSurface::draw(SkCanvas* canvas, SkScalar x, SkScalar y,
328 const SkPaint* paint) {
329 return asSB(this)->onDraw(canvas, x, y, paint);
330}
commit-bot@chromium.orgc3bd8af2014-02-13 17:14:46 +0000331
reed6ceeebd2016-03-09 14:26:26 -0800332bool SkSurface::peekPixels(SkPixmap* pmap) {
333 return this->getCanvas()->peekPixels(pmap);
commit-bot@chromium.orgc3bd8af2014-02-13 17:14:46 +0000334}
reed4a8126e2014-09-22 07:29:03 -0700335
Mike Reed353196f2017-07-21 11:01:18 -0400336bool SkSurface::readPixels(const SkPixmap& pm, int srcX, int srcY) {
337 return this->getCanvas()->readPixels(pm, srcX, srcY);
338}
339
reed7543aa22014-12-09 14:39:44 -0800340bool SkSurface::readPixels(const SkImageInfo& dstInfo, void* dstPixels, size_t dstRowBytes,
341 int srcX, int srcY) {
Mike Reed353196f2017-07-21 11:01:18 -0400342 return this->readPixels({dstInfo, dstPixels, dstRowBytes}, srcX, srcY);
343}
344
345bool SkSurface::readPixels(const SkBitmap& bitmap, int srcX, int srcY) {
346 SkPixmap pm;
347 return bitmap.peekPixels(&pm) && this->readPixels(pm, srcX, srcY);
reed7543aa22014-12-09 14:39:44 -0800348}
349
Brian Salomon201700f2019-05-17 12:05:44 -0400350void SkSurface::asyncRescaleAndReadPixels(const SkImageInfo& info, const SkIRect& srcRect,
351 RescaleGamma rescaleGamma, SkFilterQuality rescaleQuality,
352 ReadPixelsCallback callback, ReadPixelsContext context) {
Brian Salomonab32f652019-05-10 14:24:50 -0400353 if (!SkIRect::MakeWH(this->width(), this->height()).contains(srcRect) ||
Brian Salomon201700f2019-05-17 12:05:44 -0400354 !SkImageInfoIsValid(info)) {
Brian Salomonab32f652019-05-10 14:24:50 -0400355 callback(context, nullptr, 0);
356 return;
357 }
Brian Salomon031b0ba2019-05-23 11:05:26 -0400358 asSB(this)->onAsyncRescaleAndReadPixels(info, srcRect, rescaleGamma, rescaleQuality, callback,
359 context);
Brian Salomonab32f652019-05-10 14:24:50 -0400360}
361
Brian Salomon024bd002019-06-11 11:38:16 -0400362void SkSurface::asyncRescaleAndReadPixelsYUV420(
363 SkYUVColorSpace yuvColorSpace, sk_sp<SkColorSpace> dstColorSpace, const SkIRect& srcRect,
364 int dstW, int dstH, RescaleGamma rescaleGamma, SkFilterQuality rescaleQuality,
365 ReadPixelsCallbackYUV420 callback, ReadPixelsContext context) {
366 if (!SkIRect::MakeWH(this->width(), this->height()).contains(srcRect) || (dstW & 0b1) ||
367 (dstH & 0b1)) {
368 callback(context, nullptr, nullptr);
369 return;
370 }
371 asSB(this)->onAsyncRescaleAndReadPixelsYUV420(yuvColorSpace, std::move(dstColorSpace), srcRect,
372 dstW, dstH, rescaleGamma, rescaleQuality,
373 callback, context);
374}
375
Mike Reed4c790bd2018-02-08 14:10:40 -0500376void SkSurface::writePixels(const SkPixmap& pmap, int x, int y) {
377 if (pmap.addr() == nullptr || pmap.width() <= 0 || pmap.height() <= 0) {
378 return;
379 }
380
381 const SkIRect srcR = SkIRect::MakeXYWH(x, y, pmap.width(), pmap.height());
382 const SkIRect dstR = SkIRect::MakeWH(this->width(), this->height());
383 if (SkIRect::Intersects(srcR, dstR)) {
384 ContentChangeMode mode = kRetain_ContentChangeMode;
385 if (srcR.contains(dstR)) {
386 mode = kDiscard_ContentChangeMode;
387 }
388 asSB(this)->aboutToDraw(mode);
389 asSB(this)->onWritePixels(pmap, x, y);
390 }
391}
392
393void SkSurface::writePixels(const SkBitmap& src, int x, int y) {
394 SkPixmap pm;
395 if (src.peekPixels(&pm)) {
396 this->writePixels(pm, x, y);
397 }
398}
399
Robert Phillips8caf85f2018-04-05 09:30:38 -0400400GrBackendTexture SkSurface::getBackendTexture(BackendHandleAccess access) {
401 return asSB(this)->onGetBackendTexture(access);
402}
403
404GrBackendRenderTarget SkSurface::getBackendRenderTarget(BackendHandleAccess access) {
405 return asSB(this)->onGetBackendRenderTarget(access);
406}
Robert Phillips8caf85f2018-04-05 09:30:38 -0400407
Brian Salomonaad83152019-05-24 10:16:35 -0400408bool SkSurface::replaceBackendTexture(const GrBackendTexture& backendTexture,
409 GrSurfaceOrigin origin,
410 TextureReleaseProc textureReleaseProc,
411 ReleaseContext releaseContext) {
412 return asSB(this)->onReplaceBackendTexture(backendTexture, origin, textureReleaseProc,
413 releaseContext);
414}
415
Greg Daniela5cb7812017-06-16 09:45:32 -0400416void SkSurface::flush() {
Greg Daniele6bfb7d2019-04-17 15:26:11 -0400417 this->flush(BackendSurfaceAccess::kNoAccess, GrFlushInfo());
Greg Danielbae71212019-03-01 15:24:35 -0500418}
419
Greg Daniele6bfb7d2019-04-17 15:26:11 -0400420GrSemaphoresSubmitted SkSurface::flush(BackendSurfaceAccess access, const GrFlushInfo& flushInfo) {
421 return asSB(this)->onFlush(access, flushInfo);
Greg Daniela5cb7812017-06-16 09:45:32 -0400422}
423
Greg Daniel5816b3d2019-04-22 11:46:41 -0400424GrSemaphoresSubmitted SkSurface::flush(BackendSurfaceAccess access, GrFlushFlags flags,
425 int numSemaphores, GrBackendSemaphore signalSemaphores[],
426 GrGpuFinishedProc finishedProc,
427 GrGpuFinishedContext finishedContext) {
428 GrFlushInfo info;
429 info.fFlags = flags;
430 info.fNumSemaphores = numSemaphores;
431 info.fSignalSemaphores = signalSemaphores;
432 info.fFinishedProc = finishedProc;
433 info.fFinishedContext = finishedContext;
434 return this->flush(access, info);
435}
436
Greg Danielb9990e42019-04-10 16:28:52 -0400437GrSemaphoresSubmitted SkSurface::flush(BackendSurfaceAccess access, FlushFlags flags,
438 int numSemaphores, GrBackendSemaphore signalSemaphores[]) {
439 GrFlushFlags grFlags = flags == kSyncCpu_FlushFlag ? kSyncCpu_GrFlushFlag : kNone_GrFlushFlags;
Greg Daniele6bfb7d2019-04-17 15:26:11 -0400440 GrFlushInfo info;
441 info.fFlags = grFlags;
442 info.fNumSemaphores = numSemaphores;
443 info.fSignalSemaphores = signalSemaphores;
444 return this->flush(access, info);
Greg Danielb9990e42019-04-10 16:28:52 -0400445}
446
Greg Daniel51316782017-08-02 15:10:09 +0000447GrSemaphoresSubmitted SkSurface::flushAndSignalSemaphores(int numSemaphores,
448 GrBackendSemaphore signalSemaphores[]) {
Greg Daniele6bfb7d2019-04-17 15:26:11 -0400449 GrFlushInfo info;
450 info.fNumSemaphores = numSemaphores;
451 info.fSignalSemaphores = signalSemaphores;
452 return this->flush(BackendSurfaceAccess::kNoAccess, info);
Greg Daniela5cb7812017-06-16 09:45:32 -0400453}
454
Greg Danielc64ee462017-06-15 16:59:49 -0400455bool SkSurface::wait(int numSemaphores, const GrBackendSemaphore* waitSemaphores) {
456 return asSB(this)->onWait(numSemaphores, waitSemaphores);
ericrkf7b8b8a2016-02-24 14:49:51 -0800457}
458
Robert Phillipsad8a43f2017-08-30 12:06:35 -0400459bool SkSurface::characterize(SkSurfaceCharacterization* characterization) const {
Robert Phillips9907e6e2019-06-25 14:47:04 -0400460 return asConstSB(this)->onCharacterize(characterization);
461}
462
463bool SkSurface::isCompatible(const SkSurfaceCharacterization& characterization) const {
464 return asConstSB(this)->onIsCompatible(characterization);
Robert Phillipsad8a43f2017-08-30 12:06:35 -0400465}
466
Robert Phillips7ffbcf92017-12-04 12:52:46 -0500467bool SkSurface::draw(SkDeferredDisplayList* ddl) {
Robert Phillipsad8a43f2017-08-30 12:06:35 -0400468 return asSB(this)->onDraw(ddl);
469}
470
reed4a8126e2014-09-22 07:29:03 -0700471//////////////////////////////////////////////////////////////////////////////////////
Mike Kleinc0bd9f92019-04-23 12:05:21 -0500472#include "include/utils/SkNoDrawCanvas.h"
Mike Reed44d04bd2017-06-28 19:57:21 -0400473
474class SkNullSurface : public SkSurface_Base {
475public:
476 SkNullSurface(int width, int height) : SkSurface_Base(width, height, nullptr) {}
477
478protected:
479 SkCanvas* onNewCanvas() override {
480 return new SkNoDrawCanvas(this->width(), this->height());
481 }
482 sk_sp<SkSurface> onNewSurface(const SkImageInfo& info) override {
483 return MakeNull(info.width(), info.height());
484 }
Mike Reed114bde82018-11-21 09:12:09 -0500485 sk_sp<SkImage> onNewImageSnapshot(const SkIRect* subsetOrNull) override { return nullptr; }
Mike Reed4c790bd2018-02-08 14:10:40 -0500486 void onWritePixels(const SkPixmap&, int x, int y) override {}
Mike Reed44d04bd2017-06-28 19:57:21 -0400487 void onDraw(SkCanvas*, SkScalar x, SkScalar y, const SkPaint*) override {}
488 void onCopyOnWrite(ContentChangeMode) override {}
489};
490
491sk_sp<SkSurface> SkSurface::MakeNull(int width, int height) {
492 if (width < 1 || height < 1) {
493 return nullptr;
494 }
495 return sk_sp<SkSurface>(new SkNullSurface(width, height));
496}
497
498//////////////////////////////////////////////////////////////////////////////////////
reed4a8126e2014-09-22 07:29:03 -0700499
500#if !SK_SUPPORT_GPU
501
Brian Salomonbdecacf2018-02-02 20:32:49 -0500502sk_sp<SkSurface> SkSurface::MakeRenderTarget(GrContext*, SkBudgeted, const SkImageInfo&, int,
503 GrSurfaceOrigin, const SkSurfaceProps*, bool) {
halcanary96fcdcc2015-08-27 07:41:13 -0700504 return nullptr;
reed4a8126e2014-09-22 07:29:03 -0700505}
506
Robert Phillips9338c602019-02-19 12:52:29 -0500507sk_sp<SkSurface> SkSurface::MakeRenderTarget(GrRecordingContext*, const SkSurfaceCharacterization&,
Robert Phillips6b6fcc72018-03-30 13:57:00 -0400508 SkBudgeted) {
509 return nullptr;
510}
511
Greg Daniel94403452017-04-18 15:52:36 -0400512sk_sp<SkSurface> SkSurface::MakeFromBackendTexture(GrContext*, const GrBackendTexture&,
513 GrSurfaceOrigin origin, int sampleCnt,
Greg Danielfaa095e2017-12-19 13:15:02 -0500514 SkColorType, sk_sp<SkColorSpace>,
Greg Daniel8ce79912019-02-05 10:08:43 -0500515 const SkSurfaceProps*,
516 TextureReleaseProc, ReleaseContext) {
Greg Danielfaa095e2017-12-19 13:15:02 -0500517 return nullptr;
518}
519
reede8f30622016-03-23 18:59:25 -0700520sk_sp<SkSurface> SkSurface::MakeFromBackendRenderTarget(GrContext*,
Greg Daniel94403452017-04-18 15:52:36 -0400521 const GrBackendRenderTarget&,
522 GrSurfaceOrigin origin,
Greg Danielfaa095e2017-12-19 13:15:02 -0500523 SkColorType,
524 sk_sp<SkColorSpace>,
Greg Daniel8ce79912019-02-05 10:08:43 -0500525 const SkSurfaceProps*,
526 RenderTargetReleaseProc, ReleaseContext) {
Greg Danielfaa095e2017-12-19 13:15:02 -0500527 return nullptr;
528}
529
Greg Daniel94403452017-04-18 15:52:36 -0400530sk_sp<SkSurface> SkSurface::MakeFromBackendTextureAsRenderTarget(GrContext*,
Greg Daniel94403452017-04-18 15:52:36 -0400531 const GrBackendTexture&,
532 GrSurfaceOrigin origin,
533 int sampleCnt,
Greg Danielfaa095e2017-12-19 13:15:02 -0500534 SkColorType,
535 sk_sp<SkColorSpace>,
536 const SkSurfaceProps*) {
537 return nullptr;
538}
539
reed4a8126e2014-09-22 07:29:03 -0700540#endif