reed@google.com | 5d4ba88 | 2012-07-31 15:45:27 +0000 | [diff] [blame] | 1 | /* |
| 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 | |
bsalomon | afe3005 | 2015-01-16 07:32:33 -0800 | [diff] [blame] | 8 | #include "SkSurface_Gpu.h" |
Greg Daniel | 7ef28f3 | 2017-04-20 16:41:55 +0000 | [diff] [blame] | 9 | #include "GrBackendSurface.h" |
Brian Salomon | c7fe0f7 | 2018-05-11 10:14:21 -0400 | [diff] [blame] | 10 | #include "GrCaps.h" |
robertphillips | 15c42ca | 2016-08-04 08:45:02 -0700 | [diff] [blame] | 11 | #include "GrContextPriv.h" |
Robert Phillips | 2890fbf | 2017-07-26 15:48:41 -0400 | [diff] [blame] | 12 | #include "GrRenderTarget.h" |
Robert Phillips | 0ae6faa | 2017-03-21 16:22:00 -0400 | [diff] [blame] | 13 | #include "GrRenderTargetContextPriv.h" |
Greg Daniel | a070ed7 | 2018-04-26 16:31:38 -0400 | [diff] [blame] | 14 | #include "GrRenderTargetProxyPriv.h" |
Robert Phillips | 646e429 | 2017-06-13 12:44:56 -0400 | [diff] [blame] | 15 | #include "GrTexture.h" |
reed@google.com | 5d4ba88 | 2012-07-31 15:45:27 +0000 | [diff] [blame] | 16 | #include "SkCanvas.h" |
Robert Phillips | ad8a43f | 2017-08-30 12:06:35 -0400 | [diff] [blame] | 17 | #include "SkDeferredDisplayList.h" |
robertphillips@google.com | 97b6b07 | 2012-10-31 14:48:39 +0000 | [diff] [blame] | 18 | #include "SkGpuDevice.h" |
Brian Salomon | c7fe0f7 | 2018-05-11 10:14:21 -0400 | [diff] [blame] | 19 | #include "SkImagePriv.h" |
bsalomon | afe3005 | 2015-01-16 07:32:33 -0800 | [diff] [blame] | 20 | #include "SkImage_Base.h" |
reed | 8b26b99 | 2015-05-07 15:36:17 -0700 | [diff] [blame] | 21 | #include "SkImage_Gpu.h" |
Robert Phillips | ad8a43f | 2017-08-30 12:06:35 -0400 | [diff] [blame] | 22 | #include "SkSurfaceCharacterization.h" |
Brian Salomon | c7fe0f7 | 2018-05-11 10:14:21 -0400 | [diff] [blame] | 23 | #include "SkSurface_Base.h" |
reed@google.com | 5d4ba88 | 2012-07-31 15:45:27 +0000 | [diff] [blame] | 24 | |
reed | f037e0b | 2014-10-30 11:34:15 -0700 | [diff] [blame] | 25 | #if SK_SUPPORT_GPU |
| 26 | |
robertphillips | 24e9128 | 2016-04-29 06:46:36 -0700 | [diff] [blame] | 27 | SkSurface_Gpu::SkSurface_Gpu(sk_sp<SkGpuDevice> device) |
bsalomon | afe3005 | 2015-01-16 07:32:33 -0800 | [diff] [blame] | 28 | : INHERITED(device->width(), device->height(), &device->surfaceProps()) |
robertphillips | 24e9128 | 2016-04-29 06:46:36 -0700 | [diff] [blame] | 29 | , fDevice(std::move(device)) { |
Robert Phillips | 0ae6faa | 2017-03-21 16:22:00 -0400 | [diff] [blame] | 30 | SkASSERT(fDevice->accessRenderTargetContext()->asSurfaceProxy()->priv().isExact()); |
robertphillips@google.com | 97b6b07 | 2012-10-31 14:48:39 +0000 | [diff] [blame] | 31 | } |
reed@google.com | 5d4ba88 | 2012-07-31 15:45:27 +0000 | [diff] [blame] | 32 | |
robertphillips@google.com | 97b6b07 | 2012-10-31 14:48:39 +0000 | [diff] [blame] | 33 | SkSurface_Gpu::~SkSurface_Gpu() { |
reed@google.com | 5d4ba88 | 2012-07-31 15:45:27 +0000 | [diff] [blame] | 34 | } |
| 35 | |
joshualitt | 8179341 | 2015-07-08 12:54:04 -0700 | [diff] [blame] | 36 | static GrRenderTarget* prepare_rt_for_external_access(SkSurface_Gpu* surface, |
| 37 | SkSurface::BackendHandleAccess access) { |
reed | fa5e68e | 2015-06-29 07:37:01 -0700 | [diff] [blame] | 38 | switch (access) { |
joshualitt | 8179341 | 2015-07-08 12:54:04 -0700 | [diff] [blame] | 39 | case SkSurface::kFlushRead_BackendHandleAccess: |
reed | fa5e68e | 2015-06-29 07:37:01 -0700 | [diff] [blame] | 40 | break; |
joshualitt | 8179341 | 2015-07-08 12:54:04 -0700 | [diff] [blame] | 41 | case SkSurface::kFlushWrite_BackendHandleAccess: |
| 42 | case SkSurface::kDiscardWrite_BackendHandleAccess: |
reed | 884200e | 2015-06-29 09:00:20 -0700 | [diff] [blame] | 43 | // for now we don't special-case on Discard, but we may in the future. |
joshualitt | 8179341 | 2015-07-08 12:54:04 -0700 | [diff] [blame] | 44 | surface->notifyContentWillChange(SkSurface::kRetain_ContentChangeMode); |
reed | fa5e68e | 2015-06-29 07:37:01 -0700 | [diff] [blame] | 45 | break; |
reed | fa5e68e | 2015-06-29 07:37:01 -0700 | [diff] [blame] | 46 | } |
fmalita | e263908 | 2015-08-06 07:04:51 -0700 | [diff] [blame] | 47 | |
| 48 | // Grab the render target *after* firing notifications, as it may get switched if CoW kicks in. |
robertphillips | ea70c4b | 2016-07-20 08:54:31 -0700 | [diff] [blame] | 49 | surface->getDevice()->flush(); |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 50 | GrRenderTargetContext* rtc = surface->getDevice()->accessRenderTargetContext(); |
| 51 | return rtc->accessRenderTarget(); |
joshualitt | 8179341 | 2015-07-08 12:54:04 -0700 | [diff] [blame] | 52 | } |
| 53 | |
Robert Phillips | 8caf85f | 2018-04-05 09:30:38 -0400 | [diff] [blame] | 54 | GrBackendTexture SkSurface_Gpu::onGetBackendTexture(BackendHandleAccess access) { |
| 55 | GrRenderTarget* rt = prepare_rt_for_external_access(this, access); |
| 56 | if (!rt) { |
| 57 | return GrBackendTexture(); // invalid |
| 58 | } |
| 59 | GrTexture* texture = rt->asTexture(); |
| 60 | if (texture) { |
| 61 | return texture->getBackendTexture(); |
| 62 | } |
| 63 | return GrBackendTexture(); // invalid |
| 64 | } |
| 65 | |
| 66 | GrBackendRenderTarget SkSurface_Gpu::onGetBackendRenderTarget(BackendHandleAccess access) { |
| 67 | GrRenderTarget* rt = prepare_rt_for_external_access(this, access); |
| 68 | if (!rt) { |
| 69 | return GrBackendRenderTarget(); // invalid |
| 70 | } |
| 71 | |
| 72 | return rt->getBackendRenderTarget(); |
| 73 | } |
| 74 | |
reed@google.com | 5d4ba88 | 2012-07-31 15:45:27 +0000 | [diff] [blame] | 75 | SkCanvas* SkSurface_Gpu::onNewCanvas() { |
reed | 4a8126e | 2014-09-22 07:29:03 -0700 | [diff] [blame] | 76 | SkCanvas::InitFlags flags = SkCanvas::kDefault_InitFlags; |
bsalomon | b5b4974 | 2016-02-10 10:41:01 -0800 | [diff] [blame] | 77 | flags = static_cast<SkCanvas::InitFlags>(flags | SkCanvas::kConservativeRasterClip_InitFlag); |
reed | 4a8126e | 2014-09-22 07:29:03 -0700 | [diff] [blame] | 78 | |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 79 | return new SkCanvas(fDevice, flags); |
reed@google.com | 5d4ba88 | 2012-07-31 15:45:27 +0000 | [diff] [blame] | 80 | } |
| 81 | |
reed | e8f3062 | 2016-03-23 18:59:25 -0700 | [diff] [blame] | 82 | sk_sp<SkSurface> SkSurface_Gpu::onNewSurface(const SkImageInfo& info) { |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 83 | int sampleCount = fDevice->accessRenderTargetContext()->numColorSamples(); |
| 84 | GrSurfaceOrigin origin = fDevice->accessRenderTargetContext()->origin(); |
bsalomon | afe3005 | 2015-01-16 07:32:33 -0800 | [diff] [blame] | 85 | // TODO: Make caller specify this (change virtual signature of onNewSurface). |
bsalomon | 5ec26ae | 2016-02-25 08:33:02 -0800 | [diff] [blame] | 86 | static const SkBudgeted kBudgeted = SkBudgeted::kNo; |
reed | e8f3062 | 2016-03-23 18:59:25 -0700 | [diff] [blame] | 87 | return SkSurface::MakeRenderTarget(fDevice->context(), kBudgeted, info, sampleCount, |
robertphillips | 7e92276 | 2016-07-26 11:38:17 -0700 | [diff] [blame] | 88 | origin, &this->props()); |
reed@google.com | 5d4ba88 | 2012-07-31 15:45:27 +0000 | [diff] [blame] | 89 | } |
| 90 | |
Robert Phillips | ac6b1fa | 2017-03-20 08:38:50 -0400 | [diff] [blame] | 91 | sk_sp<SkImage> SkSurface_Gpu::onNewImageSnapshot() { |
Robert Phillips | e2f7d18 | 2016-12-15 09:23:05 -0500 | [diff] [blame] | 92 | GrRenderTargetContext* rtc = fDevice->accessRenderTargetContext(); |
| 93 | if (!rtc) { |
Robert Phillips | e60ad62 | 2016-11-17 10:22:48 -0500 | [diff] [blame] | 94 | return nullptr; |
| 95 | } |
| 96 | |
Robert Phillips | e2f7d18 | 2016-12-15 09:23:05 -0500 | [diff] [blame] | 97 | GrContext* ctx = fDevice->context(); |
| 98 | |
Robert Phillips | 0ae6faa | 2017-03-21 16:22:00 -0400 | [diff] [blame] | 99 | if (!rtc->asSurfaceProxy()) { |
| 100 | return nullptr; |
| 101 | } |
| 102 | |
| 103 | SkBudgeted budgeted = rtc->asSurfaceProxy()->isBudgeted(); |
| 104 | |
| 105 | sk_sp<GrTextureProxy> srcProxy = rtc->asTextureProxyRef(); |
bsalomon | b2c0133 | 2016-02-26 10:37:26 -0800 | [diff] [blame] | 106 | // If the original render target is a buffer originally created by the client, then we don't |
| 107 | // want to ever retarget the SkSurface at another buffer we create. Force a copy now to avoid |
| 108 | // copy-on-write. |
Mike Reed | 7eb01f8 | 2016-12-30 06:23:12 -0500 | [diff] [blame] | 109 | if (!srcProxy || rtc->priv().refsWrappedObjects()) { |
Robert Phillips | 81dd3e0 | 2017-06-23 11:59:24 -0400 | [diff] [blame] | 110 | SkASSERT(rtc->origin() == rtc->asSurfaceProxy()->origin()); |
Robert Phillips | e2f7d18 | 2016-12-15 09:23:05 -0500 | [diff] [blame] | 111 | |
Greg Daniel | 45d6303 | 2017-10-30 13:41:26 -0400 | [diff] [blame] | 112 | srcProxy = GrSurfaceProxy::Copy(ctx, rtc->asSurfaceProxy(), rtc->mipMapped(), budgeted); |
bsalomon | f47b9a3 | 2016-02-22 11:02:58 -0800 | [diff] [blame] | 113 | } |
Robert Phillips | e2f7d18 | 2016-12-15 09:23:05 -0500 | [diff] [blame] | 114 | |
reed | 8b26b99 | 2015-05-07 15:36:17 -0700 | [diff] [blame] | 115 | const SkImageInfo info = fDevice->imageInfo(); |
reed | e8f3062 | 2016-03-23 18:59:25 -0700 | [diff] [blame] | 116 | sk_sp<SkImage> image; |
Robert Phillips | 0ae6faa | 2017-03-21 16:22:00 -0400 | [diff] [blame] | 117 | if (srcProxy) { |
| 118 | // The renderTargetContext coming out of SkGpuDevice should always be exact and the |
| 119 | // above copy creates a kExact surfaceContext. |
| 120 | SkASSERT(srcProxy->priv().isExact()); |
Brian Salomon | 8a8dd33 | 2018-05-24 14:08:31 -0400 | [diff] [blame] | 121 | image = sk_make_sp<SkImage_Gpu>(sk_ref_sp(ctx), kNeedNewImageUniqueID, info.alphaType(), |
| 122 | std::move(srcProxy), info.refColorSpace(), budgeted); |
reed | 8b26b99 | 2015-05-07 15:36:17 -0700 | [diff] [blame] | 123 | } |
reed | 4af267b | 2014-11-21 08:46:37 -0800 | [diff] [blame] | 124 | return image; |
reed@google.com | 5d4ba88 | 2012-07-31 15:45:27 +0000 | [diff] [blame] | 125 | } |
| 126 | |
Mike Reed | 4c790bd | 2018-02-08 14:10:40 -0500 | [diff] [blame] | 127 | void SkSurface_Gpu::onWritePixels(const SkPixmap& src, int x, int y) { |
| 128 | fDevice->writePixels(src, x, y); |
| 129 | } |
| 130 | |
kkinnunen | abcfab4 | 2015-02-22 22:53:44 -0800 | [diff] [blame] | 131 | // Create a new render target and, if necessary, copy the contents of the old |
| 132 | // render target into it. Note that this flushes the SkGpuDevice but |
robertphillips@google.com | 97b6b07 | 2012-10-31 14:48:39 +0000 | [diff] [blame] | 133 | // doesn't force an OpenGL flush. |
commit-bot@chromium.org | c4c9870 | 2013-04-22 14:28:01 +0000 | [diff] [blame] | 134 | void SkSurface_Gpu::onCopyOnWrite(ContentChangeMode mode) { |
Robert Phillips | 602b79c | 2017-06-23 11:26:28 -0400 | [diff] [blame] | 135 | GrRenderTargetContext* rtc = fDevice->accessRenderTargetContext(); |
| 136 | |
| 137 | // are we sharing our backing proxy with the image? Note this call should never create a new |
bsalomon | eaaaf0b | 2015-01-23 08:08:04 -0800 | [diff] [blame] | 138 | // image because onCopyOnWrite is only called when there is a cached image. |
Robert Phillips | ac6b1fa | 2017-03-20 08:38:50 -0400 | [diff] [blame] | 139 | sk_sp<SkImage> image(this->refCachedImage()); |
bsalomon | eaaaf0b | 2015-01-23 08:08:04 -0800 | [diff] [blame] | 140 | SkASSERT(image); |
Robert Phillips | 602b79c | 2017-06-23 11:26:28 -0400 | [diff] [blame] | 141 | |
| 142 | GrSurfaceProxy* imageProxy = ((SkImage_Base*) image.get())->peekProxy(); |
| 143 | SkASSERT(imageProxy); |
| 144 | |
| 145 | if (rtc->asSurfaceProxy()->underlyingUniqueID() == imageProxy->underlyingUniqueID()) { |
Robert Phillips | 6de9904 | 2017-01-31 11:31:39 -0500 | [diff] [blame] | 146 | fDevice->replaceRenderTargetContext(SkSurface::kRetain_ContentChangeMode == mode); |
commit-bot@chromium.org | 28361fa | 2014-03-28 16:08:05 +0000 | [diff] [blame] | 147 | } else if (kDiscard_ContentChangeMode == mode) { |
| 148 | this->SkSurface_Gpu::onDiscard(); |
robertphillips@google.com | 97b6b07 | 2012-10-31 14:48:39 +0000 | [diff] [blame] | 149 | } |
reed@google.com | 5d4ba88 | 2012-07-31 15:45:27 +0000 | [diff] [blame] | 150 | } |
| 151 | |
commit-bot@chromium.org | 28361fa | 2014-03-28 16:08:05 +0000 | [diff] [blame] | 152 | void SkSurface_Gpu::onDiscard() { |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 153 | fDevice->accessRenderTargetContext()->discard(); |
commit-bot@chromium.org | 28361fa | 2014-03-28 16:08:05 +0000 | [diff] [blame] | 154 | } |
| 155 | |
Greg Daniel | 5131678 | 2017-08-02 15:10:09 +0000 | [diff] [blame] | 156 | GrSemaphoresSubmitted SkSurface_Gpu::onFlush(int numSemaphores, |
| 157 | GrBackendSemaphore signalSemaphores[]) { |
Greg Daniel | c64ee46 | 2017-06-15 16:59:49 -0400 | [diff] [blame] | 158 | return fDevice->flushAndSignalSemaphores(numSemaphores, signalSemaphores); |
Greg Daniel | a5cb781 | 2017-06-16 09:45:32 -0400 | [diff] [blame] | 159 | } |
| 160 | |
Greg Daniel | c64ee46 | 2017-06-15 16:59:49 -0400 | [diff] [blame] | 161 | bool SkSurface_Gpu::onWait(int numSemaphores, const GrBackendSemaphore* waitSemaphores) { |
| 162 | return fDevice->wait(numSemaphores, waitSemaphores); |
ericrk | f7b8b8a | 2016-02-24 14:49:51 -0800 | [diff] [blame] | 163 | } |
| 164 | |
Robert Phillips | be77a02 | 2018-04-03 17:17:05 -0400 | [diff] [blame] | 165 | bool SkSurface_Gpu::onCharacterize(SkSurfaceCharacterization* characterization) const { |
Robert Phillips | ad8a43f | 2017-08-30 12:06:35 -0400 | [diff] [blame] | 166 | GrRenderTargetContext* rtc = fDevice->accessRenderTargetContext(); |
Robert Phillips | 8def8bf | 2017-11-30 08:46:03 -0500 | [diff] [blame] | 167 | GrContext* ctx = fDevice->context(); |
Robert Phillips | ad8a43f | 2017-08-30 12:06:35 -0400 | [diff] [blame] | 168 | |
Robert Phillips | 8d1e67e | 2017-12-04 13:48:14 -0500 | [diff] [blame] | 169 | int maxResourceCount; |
| 170 | size_t maxResourceBytes; |
| 171 | ctx->getResourceCacheLimits(&maxResourceCount, &maxResourceBytes); |
| 172 | |
Robert Phillips | e8fabb2 | 2018-02-04 14:33:21 -0500 | [diff] [blame] | 173 | bool mipmapped = rtc->asTextureProxy() ? GrMipMapped::kYes == rtc->asTextureProxy()->mipMapped() |
| 174 | : false; |
| 175 | |
Robert Phillips | be77a02 | 2018-04-03 17:17:05 -0400 | [diff] [blame] | 176 | // TODO: the addition of colorType to the surfaceContext should remove this calculation |
| 177 | SkColorType ct; |
| 178 | if (!GrPixelConfigToColorType(rtc->colorSpaceInfo().config(), &ct)) { |
| 179 | return false; |
| 180 | } |
| 181 | |
Greg Daniel | a070ed7 | 2018-04-26 16:31:38 -0400 | [diff] [blame] | 182 | bool usesGLFBO0 = rtc->asRenderTargetProxy()->rtPriv().glRTFBOIDIs0(); |
| 183 | // We should never get in the situation where we have a texture render target that is also |
| 184 | // backend by FBO 0. |
| 185 | SkASSERT(!usesGLFBO0 || !SkToBool(rtc->asTextureProxy())); |
| 186 | |
Robert Phillips | be77a02 | 2018-04-03 17:17:05 -0400 | [diff] [blame] | 187 | SkImageInfo ii = SkImageInfo::Make(rtc->width(), rtc->height(), ct, kPremul_SkAlphaType, |
| 188 | rtc->colorSpaceInfo().refColorSpace()); |
| 189 | |
| 190 | characterization->set(ctx->threadSafeProxy(), maxResourceBytes, ii, rtc->origin(), |
| 191 | rtc->colorSpaceInfo().config(), rtc->fsaaType(), rtc->numStencilSamples(), |
| 192 | SkSurfaceCharacterization::Textureable(SkToBool(rtc->asTextureProxy())), |
Greg Daniel | a070ed7 | 2018-04-26 16:31:38 -0400 | [diff] [blame] | 193 | SkSurfaceCharacterization::MipMapped(mipmapped), |
| 194 | SkSurfaceCharacterization::UsesGLFBO0(usesGLFBO0), this->props()); |
Robert Phillips | 8def8bf | 2017-11-30 08:46:03 -0500 | [diff] [blame] | 195 | |
Robert Phillips | ad8a43f | 2017-08-30 12:06:35 -0400 | [diff] [blame] | 196 | return true; |
| 197 | } |
| 198 | |
Robert Phillips | be77a02 | 2018-04-03 17:17:05 -0400 | [diff] [blame] | 199 | bool SkSurface_Gpu::isCompatible(const SkSurfaceCharacterization& characterization) const { |
Robert Phillips | ad8a43f | 2017-08-30 12:06:35 -0400 | [diff] [blame] | 200 | GrRenderTargetContext* rtc = fDevice->accessRenderTargetContext(); |
Robert Phillips | 8def8bf | 2017-11-30 08:46:03 -0500 | [diff] [blame] | 201 | GrContext* ctx = fDevice->context(); |
Robert Phillips | ad8a43f | 2017-08-30 12:06:35 -0400 | [diff] [blame] | 202 | |
Robert Phillips | be77a02 | 2018-04-03 17:17:05 -0400 | [diff] [blame] | 203 | if (!characterization.isValid()) { |
Robert Phillips | fc711a2 | 2018-02-13 17:03:00 -0500 | [diff] [blame] | 204 | return false; |
| 205 | } |
| 206 | |
Robert Phillips | 8d1e67e | 2017-12-04 13:48:14 -0500 | [diff] [blame] | 207 | // As long as the current state if the context allows for greater or equal resources, |
| 208 | // we allow the DDL to be replayed. |
Robert Phillips | fc711a2 | 2018-02-13 17:03:00 -0500 | [diff] [blame] | 209 | // DDL TODO: should we just remove the resource check and ignore the cache limits on playback? |
Robert Phillips | 8d1e67e | 2017-12-04 13:48:14 -0500 | [diff] [blame] | 210 | int maxResourceCount; |
| 211 | size_t maxResourceBytes; |
| 212 | ctx->getResourceCacheLimits(&maxResourceCount, &maxResourceBytes); |
| 213 | |
Robert Phillips | be77a02 | 2018-04-03 17:17:05 -0400 | [diff] [blame] | 214 | if (characterization.isTextureable()) { |
Robert Phillips | e8fabb2 | 2018-02-04 14:33:21 -0500 | [diff] [blame] | 215 | if (!rtc->asTextureProxy()) { |
| 216 | // If the characterization was textureable we require the replay dest to also be |
| 217 | // textureable. If the characterized surface wasn't textureable we allow the replay |
| 218 | // dest to be textureable. |
| 219 | return false; |
| 220 | } |
| 221 | |
Robert Phillips | be77a02 | 2018-04-03 17:17:05 -0400 | [diff] [blame] | 222 | if (characterization.isMipMapped() && |
| 223 | GrMipMapped::kNo == rtc->asTextureProxy()->mipMapped()) { |
Robert Phillips | e8fabb2 | 2018-02-04 14:33:21 -0500 | [diff] [blame] | 224 | // Fail if the DDL's surface was mipmapped but the replay surface is not. |
| 225 | // Allow drawing to proceed if the DDL was not mipmapped but the replay surface is. |
| 226 | return false; |
| 227 | } |
| 228 | } |
| 229 | |
Greg Daniel | a070ed7 | 2018-04-26 16:31:38 -0400 | [diff] [blame] | 230 | if (characterization.usesGLFBO0() != rtc->asRenderTargetProxy()->rtPriv().glRTFBOIDIs0()) { |
| 231 | return false; |
| 232 | } |
| 233 | |
Robert Phillips | be77a02 | 2018-04-03 17:17:05 -0400 | [diff] [blame] | 234 | // TODO: the addition of colorType to the surfaceContext should remove this calculation |
| 235 | SkColorType rtcColorType; |
| 236 | if (!GrPixelConfigToColorType(rtc->colorSpaceInfo().config(), &rtcColorType)) { |
| 237 | return false; |
| 238 | } |
| 239 | |
| 240 | return characterization.contextInfo() && characterization.contextInfo()->matches(ctx) && |
| 241 | characterization.cacheMaxResourceBytes() <= maxResourceBytes && |
| 242 | characterization.origin() == rtc->origin() && |
| 243 | characterization.config() == rtc->colorSpaceInfo().config() && |
| 244 | characterization.width() == rtc->width() && |
| 245 | characterization.height() == rtc->height() && |
| 246 | characterization.colorType() == rtcColorType && |
| 247 | characterization.fsaaType() == rtc->fsaaType() && |
| 248 | characterization.stencilCount() == rtc->numStencilSamples() && |
| 249 | SkColorSpace::Equals(characterization.colorSpace(), |
| 250 | rtc->colorSpaceInfo().colorSpace()) && |
| 251 | characterization.surfaceProps() == rtc->surfaceProps(); |
Robert Phillips | ad8a43f | 2017-08-30 12:06:35 -0400 | [diff] [blame] | 252 | } |
| 253 | |
Robert Phillips | d5f9cdd | 2018-01-31 09:29:48 -0500 | [diff] [blame] | 254 | bool SkSurface_Gpu::onDraw(const SkDeferredDisplayList* ddl) { |
Robert Phillips | fc711a2 | 2018-02-13 17:03:00 -0500 | [diff] [blame] | 255 | if (!ddl || !this->isCompatible(ddl->characterization())) { |
Robert Phillips | 7ffbcf9 | 2017-12-04 12:52:46 -0500 | [diff] [blame] | 256 | return false; |
Robert Phillips | ad8a43f | 2017-08-30 12:06:35 -0400 | [diff] [blame] | 257 | } |
| 258 | |
Robert Phillips | 6200036 | 2018-02-01 09:10:04 -0500 | [diff] [blame] | 259 | GrRenderTargetContext* rtc = fDevice->accessRenderTargetContext(); |
| 260 | GrContext* ctx = fDevice->context(); |
| 261 | |
| 262 | ctx->contextPriv().copyOpListsFromDDL(ddl, rtc->asRenderTargetProxy()); |
| 263 | return true; |
Robert Phillips | ad8a43f | 2017-08-30 12:06:35 -0400 | [diff] [blame] | 264 | } |
| 265 | |
| 266 | |
reed@google.com | 5d4ba88 | 2012-07-31 15:45:27 +0000 | [diff] [blame] | 267 | /////////////////////////////////////////////////////////////////////////////// |
| 268 | |
brianosman | 0e22eb8 | 2016-08-30 07:07:59 -0700 | [diff] [blame] | 269 | bool SkSurface_Gpu::Valid(const SkImageInfo& info) { |
| 270 | switch (info.colorType()) { |
| 271 | case kRGBA_F16_SkColorType: |
Mike Klein | 3785471 | 2018-06-26 11:43:06 -0400 | [diff] [blame] | 272 | case kRGBA_F32_SkColorType: |
brianosman | 0e22eb8 | 2016-08-30 07:07:59 -0700 | [diff] [blame] | 273 | case kRGBA_8888_SkColorType: |
| 274 | case kBGRA_8888_SkColorType: |
Brian Osman | 2b23c4b | 2018-06-01 12:25:08 -0400 | [diff] [blame] | 275 | return true; |
brianosman | 0e22eb8 | 2016-08-30 07:07:59 -0700 | [diff] [blame] | 276 | default: |
| 277 | return !info.colorSpace(); |
| 278 | } |
| 279 | } |
| 280 | |
Robert Phillips | be77a02 | 2018-04-03 17:17:05 -0400 | [diff] [blame] | 281 | bool SkSurface_Gpu::Valid(const GrCaps* caps, GrPixelConfig config, SkColorSpace* colorSpace) { |
brianosman | 0e22eb8 | 2016-08-30 07:07:59 -0700 | [diff] [blame] | 282 | switch (config) { |
brianosman | 0e22eb8 | 2016-08-30 07:07:59 -0700 | [diff] [blame] | 283 | case kSRGBA_8888_GrPixelConfig: |
| 284 | case kSBGRA_8888_GrPixelConfig: |
Brian Osman | 2b23c4b | 2018-06-01 12:25:08 -0400 | [diff] [blame] | 285 | return caps->srgbSupport(); |
| 286 | case kRGBA_half_GrPixelConfig: |
Mike Klein | 3785471 | 2018-06-26 11:43:06 -0400 | [diff] [blame] | 287 | case kRGBA_float_GrPixelConfig: |
brianosman | 0e22eb8 | 2016-08-30 07:07:59 -0700 | [diff] [blame] | 288 | case kRGBA_8888_GrPixelConfig: |
| 289 | case kBGRA_8888_GrPixelConfig: |
Brian Osman | 2b23c4b | 2018-06-01 12:25:08 -0400 | [diff] [blame] | 290 | return true; |
brianosman | 0e22eb8 | 2016-08-30 07:07:59 -0700 | [diff] [blame] | 291 | default: |
| 292 | return !colorSpace; |
| 293 | } |
| 294 | } |
| 295 | |
Robert Phillips | 6b6fcc7 | 2018-03-30 13:57:00 -0400 | [diff] [blame] | 296 | sk_sp<SkSurface> SkSurface::MakeRenderTarget(GrContext* context, |
| 297 | const SkSurfaceCharacterization& c, |
| 298 | SkBudgeted budgeted) { |
Robert Phillips | be77a02 | 2018-04-03 17:17:05 -0400 | [diff] [blame] | 299 | if (!context || !c.isValid()) { |
Robert Phillips | 6b6fcc7 | 2018-03-30 13:57:00 -0400 | [diff] [blame] | 300 | return nullptr; |
| 301 | } |
| 302 | |
Greg Daniel | a070ed7 | 2018-04-26 16:31:38 -0400 | [diff] [blame] | 303 | if (c.usesGLFBO0()) { |
| 304 | // If we are making the surface we will never use FBO0. |
| 305 | return nullptr; |
| 306 | } |
| 307 | |
Brian Salomon | c7fe0f7 | 2018-05-11 10:14:21 -0400 | [diff] [blame] | 308 | if (!SkSurface_Gpu::Valid(context->contextPriv().caps(), c.config(), c.colorSpace())) { |
Robert Phillips | 6b6fcc7 | 2018-03-30 13:57:00 -0400 | [diff] [blame] | 309 | return nullptr; |
| 310 | } |
| 311 | |
Robert Phillips | be77a02 | 2018-04-03 17:17:05 -0400 | [diff] [blame] | 312 | // In order to ensure compatibility we have to match the backend format (i.e. the GrPixelConfig |
| 313 | // of the characterization) |
| 314 | GrSurfaceDesc desc; |
| 315 | desc.fFlags = kRenderTarget_GrSurfaceFlag; |
| 316 | desc.fWidth = c.width(); |
| 317 | desc.fHeight = c.height(); |
| 318 | desc.fConfig = c.config(); |
| 319 | desc.fSampleCnt = c.stencilCount(); |
Robert Phillips | 6b6fcc7 | 2018-03-30 13:57:00 -0400 | [diff] [blame] | 320 | |
Robert Phillips | be77a02 | 2018-04-03 17:17:05 -0400 | [diff] [blame] | 321 | sk_sp<GrSurfaceContext> sc( |
| 322 | context->contextPriv().makeDeferredSurfaceContext(desc, c.origin(), |
| 323 | GrMipMapped(c.isMipMapped()), |
| 324 | SkBackingFit::kExact, budgeted, |
| 325 | c.refColorSpace(), |
| 326 | &c.surfaceProps())); |
| 327 | if (!sc || !sc->asRenderTargetContext()) { |
| 328 | return nullptr; |
| 329 | } |
| 330 | |
| 331 | sk_sp<SkGpuDevice> device(SkGpuDevice::Make(context, sk_ref_sp(sc->asRenderTargetContext()), |
| 332 | c.width(), c.height(), |
| 333 | SkGpuDevice::kClear_InitContents)); |
| 334 | if (!device) { |
| 335 | return nullptr; |
| 336 | } |
| 337 | |
| 338 | sk_sp<SkSurface> s = sk_make_sp<SkSurface_Gpu>(std::move(device)); |
| 339 | #ifdef SK_DEBUG |
| 340 | if (s) { |
| 341 | SkSurface_Gpu* gpuSurface = static_cast<SkSurface_Gpu*>(s.get()); |
| 342 | SkASSERT(gpuSurface->isCompatible(c)); |
| 343 | } |
| 344 | #endif |
| 345 | |
| 346 | return s; |
Robert Phillips | 6b6fcc7 | 2018-03-30 13:57:00 -0400 | [diff] [blame] | 347 | } |
| 348 | |
| 349 | |
reed | e8f3062 | 2016-03-23 18:59:25 -0700 | [diff] [blame] | 350 | sk_sp<SkSurface> SkSurface::MakeRenderTarget(GrContext* ctx, SkBudgeted budgeted, |
| 351 | const SkImageInfo& info, int sampleCount, |
Greg Daniel | e252f08 | 2017-10-23 16:05:23 -0400 | [diff] [blame] | 352 | GrSurfaceOrigin origin, const SkSurfaceProps* props, |
| 353 | bool shouldCreateWithMips) { |
Greg Daniel | f47069c | 2017-10-24 11:57:01 -0400 | [diff] [blame] | 354 | if (!ctx) { |
| 355 | return nullptr; |
| 356 | } |
brianosman | 0e22eb8 | 2016-08-30 07:07:59 -0700 | [diff] [blame] | 357 | if (!SkSurface_Gpu::Valid(info)) { |
| 358 | return nullptr; |
| 359 | } |
Brian Salomon | bdecacf | 2018-02-02 20:32:49 -0500 | [diff] [blame] | 360 | sampleCount = SkTMax(1, sampleCount); |
Greg Daniel | e252f08 | 2017-10-23 16:05:23 -0400 | [diff] [blame] | 361 | GrMipMapped mipMapped = shouldCreateWithMips ? GrMipMapped::kYes : GrMipMapped::kNo; |
| 362 | |
Brian Salomon | c7fe0f7 | 2018-05-11 10:14:21 -0400 | [diff] [blame] | 363 | if (!ctx->contextPriv().caps()->mipMapSupport()) { |
Greg Daniel | f47069c | 2017-10-24 11:57:01 -0400 | [diff] [blame] | 364 | mipMapped = GrMipMapped::kNo; |
| 365 | } |
| 366 | |
robertphillips | 24e9128 | 2016-04-29 06:46:36 -0700 | [diff] [blame] | 367 | sk_sp<SkGpuDevice> device(SkGpuDevice::Make( |
Greg Daniel | e252f08 | 2017-10-23 16:05:23 -0400 | [diff] [blame] | 368 | ctx, budgeted, info, sampleCount, origin, props, mipMapped, |
| 369 | SkGpuDevice::kClear_InitContents)); |
bsalomon | afe3005 | 2015-01-16 07:32:33 -0800 | [diff] [blame] | 370 | if (!device) { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 371 | return nullptr; |
reed@google.com | 5d4ba88 | 2012-07-31 15:45:27 +0000 | [diff] [blame] | 372 | } |
robertphillips | 24e9128 | 2016-04-29 06:46:36 -0700 | [diff] [blame] | 373 | return sk_make_sp<SkSurface_Gpu>(std::move(device)); |
reed@google.com | 5d4ba88 | 2012-07-31 15:45:27 +0000 | [diff] [blame] | 374 | } |
reed | f037e0b | 2014-10-30 11:34:15 -0700 | [diff] [blame] | 375 | |
Robert Phillips | d5f9cdd | 2018-01-31 09:29:48 -0500 | [diff] [blame] | 376 | sk_sp<SkSurface> SkSurface_Gpu::MakeWrappedRenderTarget(GrContext* context, |
| 377 | sk_sp<GrRenderTargetContext> rtc) { |
| 378 | if (!context) { |
| 379 | return nullptr; |
| 380 | } |
| 381 | |
Brian Salomon | f777897 | 2018-03-08 10:13:17 -0500 | [diff] [blame] | 382 | int w = rtc->width(); |
| 383 | int h = rtc->height(); |
| 384 | sk_sp<SkGpuDevice> device( |
| 385 | SkGpuDevice::Make(context, std::move(rtc), w, h, SkGpuDevice::kUninit_InitContents)); |
Robert Phillips | d5f9cdd | 2018-01-31 09:29:48 -0500 | [diff] [blame] | 386 | if (!device) { |
| 387 | return nullptr; |
| 388 | } |
| 389 | |
| 390 | return sk_make_sp<SkSurface_Gpu>(std::move(device)); |
| 391 | } |
| 392 | |
Greg Daniel | faa095e | 2017-12-19 13:15:02 -0500 | [diff] [blame] | 393 | bool validate_backend_texture(GrContext* ctx, const GrBackendTexture& tex, GrPixelConfig* config, |
| 394 | int sampleCnt, SkColorType ct, sk_sp<SkColorSpace> cs, |
| 395 | bool texturable) { |
Greg Daniel | 66aebf3 | 2018-04-09 09:15:56 -0400 | [diff] [blame] | 396 | if (!tex.isValid()) { |
| 397 | return false; |
| 398 | } |
Greg Daniel | faa095e | 2017-12-19 13:15:02 -0500 | [diff] [blame] | 399 | // TODO: Create a SkImageColorInfo struct for color, alpha, and color space so we don't need to |
| 400 | // create a fake image info here. |
| 401 | SkImageInfo info = SkImageInfo::Make(1, 1, ct, kPremul_SkAlphaType, cs); |
| 402 | |
| 403 | if (!SkSurface_Gpu::Valid(info)) { |
| 404 | return false; |
| 405 | } |
| 406 | |
Brian Salomon | c7fe0f7 | 2018-05-11 10:14:21 -0400 | [diff] [blame] | 407 | if (!ctx->contextPriv().caps()->validateBackendTexture(tex, ct, config)) { |
Greg Daniel | faa095e | 2017-12-19 13:15:02 -0500 | [diff] [blame] | 408 | return false; |
| 409 | } |
| 410 | |
Brian Salomon | bdecacf | 2018-02-02 20:32:49 -0500 | [diff] [blame] | 411 | // We don't require that the client gave us an exact valid sample cnt. However, it must be |
| 412 | // less than the max supported sample count and 1 if MSAA is unsupported for the color type. |
Brian Salomon | c7fe0f7 | 2018-05-11 10:14:21 -0400 | [diff] [blame] | 413 | if (!ctx->contextPriv().caps()->getRenderTargetSampleCount(sampleCnt, *config)) { |
Greg Daniel | faa095e | 2017-12-19 13:15:02 -0500 | [diff] [blame] | 414 | return false; |
| 415 | } |
| 416 | |
Brian Salomon | c7fe0f7 | 2018-05-11 10:14:21 -0400 | [diff] [blame] | 417 | if (texturable && !ctx->contextPriv().caps()->isConfigTexturable(*config)) { |
Greg Daniel | faa095e | 2017-12-19 13:15:02 -0500 | [diff] [blame] | 418 | return false; |
| 419 | } |
| 420 | return true; |
| 421 | } |
| 422 | |
| 423 | sk_sp<SkSurface> SkSurface::MakeFromBackendTexture(GrContext* context, const GrBackendTexture& tex, |
| 424 | GrSurfaceOrigin origin, int sampleCnt, |
| 425 | SkColorType colorType, |
| 426 | sk_sp<SkColorSpace> colorSpace, |
| 427 | const SkSurfaceProps* props) { |
| 428 | if (!context) { |
| 429 | return nullptr; |
| 430 | } |
Brian Salomon | bdecacf | 2018-02-02 20:32:49 -0500 | [diff] [blame] | 431 | sampleCnt = SkTMax(1, sampleCnt); |
Greg Daniel | faa095e | 2017-12-19 13:15:02 -0500 | [diff] [blame] | 432 | GrBackendTexture texCopy = tex; |
| 433 | if (!validate_backend_texture(context, texCopy, &texCopy.fConfig, |
| 434 | sampleCnt, colorType, colorSpace, true)) { |
| 435 | return nullptr; |
| 436 | } |
| 437 | |
Brian Salomon | 5370677 | 2018-03-19 14:18:08 -0400 | [diff] [blame] | 438 | if (!context) { |
| 439 | return nullptr; |
| 440 | } |
Brian Salomon | c7fe0f7 | 2018-05-11 10:14:21 -0400 | [diff] [blame] | 441 | if (!SkSurface_Gpu::Valid(context->contextPriv().caps(), texCopy.config(), colorSpace.get())) { |
Brian Salomon | 5370677 | 2018-03-19 14:18:08 -0400 | [diff] [blame] | 442 | return nullptr; |
| 443 | } |
| 444 | sampleCnt = SkTMax(1, sampleCnt); |
| 445 | |
| 446 | sk_sp<GrRenderTargetContext> rtc(context->contextPriv().makeBackendTextureRenderTargetContext( |
| 447 | texCopy, |
| 448 | origin, |
| 449 | sampleCnt, |
| 450 | std::move(colorSpace), |
| 451 | props)); |
| 452 | if (!rtc) { |
| 453 | return nullptr; |
| 454 | } |
| 455 | |
| 456 | sk_sp<SkGpuDevice> device(SkGpuDevice::Make(context, std::move(rtc), texCopy.width(), |
| 457 | texCopy.height(), |
| 458 | SkGpuDevice::kUninit_InitContents)); |
| 459 | if (!device) { |
| 460 | return nullptr; |
| 461 | } |
| 462 | return sk_make_sp<SkSurface_Gpu>(std::move(device)); |
Greg Daniel | faa095e | 2017-12-19 13:15:02 -0500 | [diff] [blame] | 463 | } |
| 464 | |
Greg Daniel | faa095e | 2017-12-19 13:15:02 -0500 | [diff] [blame] | 465 | bool validate_backend_render_target(GrContext* ctx, const GrBackendRenderTarget& rt, |
| 466 | GrPixelConfig* config, SkColorType ct, sk_sp<SkColorSpace> cs) { |
| 467 | // TODO: Create a SkImageColorInfo struct for color, alpha, and color space so we don't need to |
| 468 | // create a fake image info here. |
| 469 | SkImageInfo info = SkImageInfo::Make(1, 1, ct, kPremul_SkAlphaType, cs); |
| 470 | |
| 471 | if (!SkSurface_Gpu::Valid(info)) { |
| 472 | return false; |
| 473 | } |
| 474 | |
Brian Salomon | c7fe0f7 | 2018-05-11 10:14:21 -0400 | [diff] [blame] | 475 | if (!ctx->contextPriv().caps()->validateBackendRenderTarget(rt, ct, config)) { |
Greg Daniel | faa095e | 2017-12-19 13:15:02 -0500 | [diff] [blame] | 476 | return false; |
| 477 | } |
| 478 | |
Brian Salomon | bdecacf | 2018-02-02 20:32:49 -0500 | [diff] [blame] | 479 | if (rt.sampleCnt() > 1) { |
Brian Salomon | c7fe0f7 | 2018-05-11 10:14:21 -0400 | [diff] [blame] | 480 | if (ctx->contextPriv().caps()->maxRenderTargetSampleCount(*config) <= 1) { |
Brian Salomon | bdecacf | 2018-02-02 20:32:49 -0500 | [diff] [blame] | 481 | return false; |
| 482 | } |
Brian Salomon | c7fe0f7 | 2018-05-11 10:14:21 -0400 | [diff] [blame] | 483 | } else if (!ctx->contextPriv().caps()->isConfigRenderable(*config)) { |
Greg Daniel | faa095e | 2017-12-19 13:15:02 -0500 | [diff] [blame] | 484 | return false; |
| 485 | } |
| 486 | |
| 487 | return true; |
| 488 | } |
| 489 | |
| 490 | sk_sp<SkSurface> SkSurface::MakeFromBackendRenderTarget(GrContext* context, |
| 491 | const GrBackendRenderTarget& rt, |
| 492 | GrSurfaceOrigin origin, |
| 493 | SkColorType colorType, |
| 494 | sk_sp<SkColorSpace> colorSpace, |
| 495 | const SkSurfaceProps* props) { |
| 496 | if (!context) { |
| 497 | return nullptr; |
| 498 | } |
Brian Salomon | 49edccd | 2018-03-23 15:31:32 -0400 | [diff] [blame] | 499 | |
Greg Daniel | faa095e | 2017-12-19 13:15:02 -0500 | [diff] [blame] | 500 | GrBackendRenderTarget rtCopy = rt; |
| 501 | if (!validate_backend_render_target(context, rtCopy, &rtCopy.fConfig, colorType, colorSpace)) { |
| 502 | return nullptr; |
| 503 | } |
Brian Salomon | c7fe0f7 | 2018-05-11 10:14:21 -0400 | [diff] [blame] | 504 | if (!SkSurface_Gpu::Valid(context->contextPriv().caps(), rtCopy.config(), colorSpace.get())) { |
Brian Salomon | 49edccd | 2018-03-23 15:31:32 -0400 | [diff] [blame] | 505 | return nullptr; |
| 506 | } |
Greg Daniel | faa095e | 2017-12-19 13:15:02 -0500 | [diff] [blame] | 507 | |
Brian Salomon | 49edccd | 2018-03-23 15:31:32 -0400 | [diff] [blame] | 508 | if (!context) { |
| 509 | return nullptr; |
| 510 | } |
| 511 | |
| 512 | sk_sp<GrRenderTargetContext> rtc( |
| 513 | context->contextPriv().makeBackendRenderTargetRenderTargetContext( |
| 514 | rtCopy, origin, std::move(colorSpace), props)); |
| 515 | if (!rtc) { |
| 516 | return nullptr; |
| 517 | } |
| 518 | |
| 519 | sk_sp<SkGpuDevice> device(SkGpuDevice::Make(context, std::move(rtc), rtCopy.width(), |
| 520 | rtCopy.height(), |
| 521 | SkGpuDevice::kUninit_InitContents)); |
| 522 | if (!device) { |
| 523 | return nullptr; |
| 524 | } |
| 525 | |
| 526 | return sk_make_sp<SkSurface_Gpu>(std::move(device)); |
Greg Daniel | faa095e | 2017-12-19 13:15:02 -0500 | [diff] [blame] | 527 | } |
| 528 | |
reed | e8f3062 | 2016-03-23 18:59:25 -0700 | [diff] [blame] | 529 | sk_sp<SkSurface> SkSurface::MakeFromBackendTextureAsRenderTarget(GrContext* context, |
Greg Daniel | 7ef28f3 | 2017-04-20 16:41:55 +0000 | [diff] [blame] | 530 | const GrBackendTexture& tex, |
| 531 | GrSurfaceOrigin origin, |
| 532 | int sampleCnt, |
Brian Salomon | cb88470 | 2018-03-19 14:01:21 -0400 | [diff] [blame] | 533 | SkColorType colorType, |
Greg Daniel | 7ef28f3 | 2017-04-20 16:41:55 +0000 | [diff] [blame] | 534 | sk_sp<SkColorSpace> colorSpace, |
| 535 | const SkSurfaceProps* props) { |
| 536 | if (!context) { |
| 537 | return nullptr; |
| 538 | } |
Justin Novosad | 21a99d4 | 2018-07-17 16:53:43 -0400 | [diff] [blame] | 539 | |
Brian Salomon | bdecacf | 2018-02-02 20:32:49 -0500 | [diff] [blame] | 540 | sampleCnt = SkTMax(1, sampleCnt); |
Brian Salomon | cb88470 | 2018-03-19 14:01:21 -0400 | [diff] [blame] | 541 | GrBackendTexture texCopy = tex; |
| 542 | if (!validate_backend_texture(context, texCopy, &texCopy.fConfig, |
| 543 | sampleCnt, colorType, colorSpace, false)) { |
| 544 | return nullptr; |
| 545 | } |
robertphillips | 15c42ca | 2016-08-04 08:45:02 -0700 | [diff] [blame] | 546 | |
Justin Novosad | 21a99d4 | 2018-07-17 16:53:43 -0400 | [diff] [blame] | 547 | if (!SkSurface_Gpu::Valid(context->contextPriv().caps(), texCopy.config(), colorSpace.get())) { |
| 548 | return nullptr; |
| 549 | } |
| 550 | |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 551 | sk_sp<GrRenderTargetContext> rtc( |
| 552 | context->contextPriv().makeBackendTextureAsRenderTargetRenderTargetContext( |
Brian Salomon | cb88470 | 2018-03-19 14:01:21 -0400 | [diff] [blame] | 553 | texCopy, |
| 554 | origin, |
| 555 | sampleCnt, |
| 556 | std::move(colorSpace), |
| 557 | props)); |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 558 | if (!rtc) { |
ericrk | f7b8b8a | 2016-02-24 14:49:51 -0800 | [diff] [blame] | 559 | return nullptr; |
| 560 | } |
robertphillips | 15c42ca | 2016-08-04 08:45:02 -0700 | [diff] [blame] | 561 | |
Greg Daniel | 7ef28f3 | 2017-04-20 16:41:55 +0000 | [diff] [blame] | 562 | sk_sp<SkGpuDevice> device(SkGpuDevice::Make(context, std::move(rtc), tex.width(), tex.height(), |
robertphillips | 24e9128 | 2016-04-29 06:46:36 -0700 | [diff] [blame] | 563 | SkGpuDevice::kUninit_InitContents)); |
ericrk | f7b8b8a | 2016-02-24 14:49:51 -0800 | [diff] [blame] | 564 | if (!device) { |
| 565 | return nullptr; |
| 566 | } |
robertphillips | 24e9128 | 2016-04-29 06:46:36 -0700 | [diff] [blame] | 567 | return sk_make_sp<SkSurface_Gpu>(std::move(device)); |
ericrk | f7b8b8a | 2016-02-24 14:49:51 -0800 | [diff] [blame] | 568 | } |
| 569 | |
reed | f037e0b | 2014-10-30 11:34:15 -0700 | [diff] [blame] | 570 | #endif |