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" |
| 9 | |
Greg Daniel | 7ef28f3 | 2017-04-20 16:41:55 +0000 | [diff] [blame] | 10 | #include "GrBackendSurface.h" |
robertphillips | 15c42ca | 2016-08-04 08:45:02 -0700 | [diff] [blame] | 11 | #include "GrContextPriv.h" |
Robert Phillips | 0ae6faa | 2017-03-21 16:22:00 -0400 | [diff] [blame] | 12 | #include "GrRenderTargetContextPriv.h" |
Robert Phillips | 646e429 | 2017-06-13 12:44:56 -0400 | [diff] [blame] | 13 | #include "GrTexture.h" |
Robert Phillips | 0ae6faa | 2017-03-21 16:22:00 -0400 | [diff] [blame] | 14 | |
reed@google.com | 5d4ba88 | 2012-07-31 15:45:27 +0000 | [diff] [blame] | 15 | #include "SkCanvas.h" |
Brian Osman | 4729914 | 2017-03-07 13:22:22 -0500 | [diff] [blame] | 16 | #include "SkColorSpace_Base.h" |
robertphillips@google.com | 97b6b07 | 2012-10-31 14:48:39 +0000 | [diff] [blame] | 17 | #include "SkGpuDevice.h" |
bsalomon | afe3005 | 2015-01-16 07:32:33 -0800 | [diff] [blame] | 18 | #include "SkImage_Base.h" |
reed | 8b26b99 | 2015-05-07 15:36:17 -0700 | [diff] [blame] | 19 | #include "SkImage_Gpu.h" |
bsalomon | afe3005 | 2015-01-16 07:32:33 -0800 | [diff] [blame] | 20 | #include "SkImagePriv.h" |
| 21 | #include "SkSurface_Base.h" |
reed@google.com | 5d4ba88 | 2012-07-31 15:45:27 +0000 | [diff] [blame] | 22 | |
reed | f037e0b | 2014-10-30 11:34:15 -0700 | [diff] [blame] | 23 | #if SK_SUPPORT_GPU |
| 24 | |
robertphillips | 24e9128 | 2016-04-29 06:46:36 -0700 | [diff] [blame] | 25 | SkSurface_Gpu::SkSurface_Gpu(sk_sp<SkGpuDevice> device) |
bsalomon | afe3005 | 2015-01-16 07:32:33 -0800 | [diff] [blame] | 26 | : INHERITED(device->width(), device->height(), &device->surfaceProps()) |
robertphillips | 24e9128 | 2016-04-29 06:46:36 -0700 | [diff] [blame] | 27 | , fDevice(std::move(device)) { |
Robert Phillips | 0ae6faa | 2017-03-21 16:22:00 -0400 | [diff] [blame] | 28 | SkASSERT(fDevice->accessRenderTargetContext()->asSurfaceProxy()->priv().isExact()); |
robertphillips@google.com | 97b6b07 | 2012-10-31 14:48:39 +0000 | [diff] [blame] | 29 | } |
reed@google.com | 5d4ba88 | 2012-07-31 15:45:27 +0000 | [diff] [blame] | 30 | |
robertphillips@google.com | 97b6b07 | 2012-10-31 14:48:39 +0000 | [diff] [blame] | 31 | SkSurface_Gpu::~SkSurface_Gpu() { |
reed@google.com | 5d4ba88 | 2012-07-31 15:45:27 +0000 | [diff] [blame] | 32 | } |
| 33 | |
joshualitt | 8179341 | 2015-07-08 12:54:04 -0700 | [diff] [blame] | 34 | static GrRenderTarget* prepare_rt_for_external_access(SkSurface_Gpu* surface, |
| 35 | SkSurface::BackendHandleAccess access) { |
reed | fa5e68e | 2015-06-29 07:37:01 -0700 | [diff] [blame] | 36 | switch (access) { |
joshualitt | 8179341 | 2015-07-08 12:54:04 -0700 | [diff] [blame] | 37 | case SkSurface::kFlushRead_BackendHandleAccess: |
reed | fa5e68e | 2015-06-29 07:37:01 -0700 | [diff] [blame] | 38 | break; |
joshualitt | 8179341 | 2015-07-08 12:54:04 -0700 | [diff] [blame] | 39 | case SkSurface::kFlushWrite_BackendHandleAccess: |
| 40 | case SkSurface::kDiscardWrite_BackendHandleAccess: |
reed | 884200e | 2015-06-29 09:00:20 -0700 | [diff] [blame] | 41 | // 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] | 42 | surface->notifyContentWillChange(SkSurface::kRetain_ContentChangeMode); |
reed | fa5e68e | 2015-06-29 07:37:01 -0700 | [diff] [blame] | 43 | break; |
reed | fa5e68e | 2015-06-29 07:37:01 -0700 | [diff] [blame] | 44 | } |
fmalita | e263908 | 2015-08-06 07:04:51 -0700 | [diff] [blame] | 45 | |
| 46 | // 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] | 47 | surface->getDevice()->flush(); |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 48 | GrRenderTargetContext* rtc = surface->getDevice()->accessRenderTargetContext(); |
| 49 | return rtc->accessRenderTarget(); |
joshualitt | 8179341 | 2015-07-08 12:54:04 -0700 | [diff] [blame] | 50 | } |
| 51 | |
| 52 | GrBackendObject SkSurface_Gpu::onGetTextureHandle(BackendHandleAccess access) { |
| 53 | GrRenderTarget* rt = prepare_rt_for_external_access(this, access); |
Robert Phillips | 833dcf4 | 2016-11-18 08:44:13 -0500 | [diff] [blame] | 54 | if (!rt) { |
| 55 | return 0; |
| 56 | } |
joshualitt | 8179341 | 2015-07-08 12:54:04 -0700 | [diff] [blame] | 57 | GrTexture* texture = rt->asTexture(); |
| 58 | if (texture) { |
| 59 | return texture->getTextureHandle(); |
| 60 | } |
| 61 | return 0; |
| 62 | } |
| 63 | |
| 64 | bool SkSurface_Gpu::onGetRenderTargetHandle(GrBackendObject* obj, BackendHandleAccess access) { |
| 65 | GrRenderTarget* rt = prepare_rt_for_external_access(this, access); |
Robert Phillips | 833dcf4 | 2016-11-18 08:44:13 -0500 | [diff] [blame] | 66 | if (!rt) { |
| 67 | return false; |
| 68 | } |
joshualitt | 8179341 | 2015-07-08 12:54:04 -0700 | [diff] [blame] | 69 | *obj = rt->getRenderTargetHandle(); |
| 70 | return true; |
reed | fa5e68e | 2015-06-29 07:37:01 -0700 | [diff] [blame] | 71 | } |
| 72 | |
reed@google.com | 5d4ba88 | 2012-07-31 15:45:27 +0000 | [diff] [blame] | 73 | SkCanvas* SkSurface_Gpu::onNewCanvas() { |
reed | 4a8126e | 2014-09-22 07:29:03 -0700 | [diff] [blame] | 74 | SkCanvas::InitFlags flags = SkCanvas::kDefault_InitFlags; |
bsalomon | b5b4974 | 2016-02-10 10:41:01 -0800 | [diff] [blame] | 75 | flags = static_cast<SkCanvas::InitFlags>(flags | SkCanvas::kConservativeRasterClip_InitFlag); |
reed | 4a8126e | 2014-09-22 07:29:03 -0700 | [diff] [blame] | 76 | |
robertphillips | 24e9128 | 2016-04-29 06:46:36 -0700 | [diff] [blame] | 77 | return new SkCanvas(fDevice.get(), flags); |
reed@google.com | 5d4ba88 | 2012-07-31 15:45:27 +0000 | [diff] [blame] | 78 | } |
| 79 | |
reed | e8f3062 | 2016-03-23 18:59:25 -0700 | [diff] [blame] | 80 | sk_sp<SkSurface> SkSurface_Gpu::onNewSurface(const SkImageInfo& info) { |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 81 | int sampleCount = fDevice->accessRenderTargetContext()->numColorSamples(); |
| 82 | GrSurfaceOrigin origin = fDevice->accessRenderTargetContext()->origin(); |
bsalomon | afe3005 | 2015-01-16 07:32:33 -0800 | [diff] [blame] | 83 | // TODO: Make caller specify this (change virtual signature of onNewSurface). |
bsalomon | 5ec26ae | 2016-02-25 08:33:02 -0800 | [diff] [blame] | 84 | static const SkBudgeted kBudgeted = SkBudgeted::kNo; |
reed | e8f3062 | 2016-03-23 18:59:25 -0700 | [diff] [blame] | 85 | return SkSurface::MakeRenderTarget(fDevice->context(), kBudgeted, info, sampleCount, |
robertphillips | 7e92276 | 2016-07-26 11:38:17 -0700 | [diff] [blame] | 86 | origin, &this->props()); |
reed@google.com | 5d4ba88 | 2012-07-31 15:45:27 +0000 | [diff] [blame] | 87 | } |
| 88 | |
Robert Phillips | ac6b1fa | 2017-03-20 08:38:50 -0400 | [diff] [blame] | 89 | sk_sp<SkImage> SkSurface_Gpu::onNewImageSnapshot() { |
Robert Phillips | e2f7d18 | 2016-12-15 09:23:05 -0500 | [diff] [blame] | 90 | GrRenderTargetContext* rtc = fDevice->accessRenderTargetContext(); |
| 91 | if (!rtc) { |
Robert Phillips | e60ad62 | 2016-11-17 10:22:48 -0500 | [diff] [blame] | 92 | return nullptr; |
| 93 | } |
| 94 | |
Robert Phillips | e2f7d18 | 2016-12-15 09:23:05 -0500 | [diff] [blame] | 95 | GrContext* ctx = fDevice->context(); |
| 96 | |
Robert Phillips | 0ae6faa | 2017-03-21 16:22:00 -0400 | [diff] [blame] | 97 | if (!rtc->asSurfaceProxy()) { |
| 98 | return nullptr; |
| 99 | } |
| 100 | |
| 101 | SkBudgeted budgeted = rtc->asSurfaceProxy()->isBudgeted(); |
| 102 | |
| 103 | sk_sp<GrTextureProxy> srcProxy = rtc->asTextureProxyRef(); |
bsalomon | b2c0133 | 2016-02-26 10:37:26 -0800 | [diff] [blame] | 104 | // If the original render target is a buffer originally created by the client, then we don't |
| 105 | // want to ever retarget the SkSurface at another buffer we create. Force a copy now to avoid |
| 106 | // copy-on-write. |
Mike Reed | 7eb01f8 | 2016-12-30 06:23:12 -0500 | [diff] [blame] | 107 | if (!srcProxy || rtc->priv().refsWrappedObjects()) { |
Robert Phillips | 81dd3e0 | 2017-06-23 11:59:24 -0400 | [diff] [blame^] | 108 | SkASSERT(rtc->origin() == rtc->asSurfaceProxy()->origin()); |
Robert Phillips | e2f7d18 | 2016-12-15 09:23:05 -0500 | [diff] [blame] | 109 | |
Robert Phillips | 81dd3e0 | 2017-06-23 11:59:24 -0400 | [diff] [blame^] | 110 | srcProxy = GrSurfaceProxy::Copy(ctx, rtc->asSurfaceProxy(), budgeted); |
bsalomon | f47b9a3 | 2016-02-22 11:02:58 -0800 | [diff] [blame] | 111 | } |
Robert Phillips | e2f7d18 | 2016-12-15 09:23:05 -0500 | [diff] [blame] | 112 | |
reed | 8b26b99 | 2015-05-07 15:36:17 -0700 | [diff] [blame] | 113 | const SkImageInfo info = fDevice->imageInfo(); |
reed | e8f3062 | 2016-03-23 18:59:25 -0700 | [diff] [blame] | 114 | sk_sp<SkImage> image; |
Robert Phillips | 0ae6faa | 2017-03-21 16:22:00 -0400 | [diff] [blame] | 115 | if (srcProxy) { |
| 116 | // The renderTargetContext coming out of SkGpuDevice should always be exact and the |
| 117 | // above copy creates a kExact surfaceContext. |
| 118 | SkASSERT(srcProxy->priv().isExact()); |
| 119 | image = sk_make_sp<SkImage_Gpu>(ctx, kNeedNewImageUniqueID, |
| 120 | info.alphaType(), std::move(srcProxy), |
| 121 | info.refColorSpace(), budgeted); |
reed | 8b26b99 | 2015-05-07 15:36:17 -0700 | [diff] [blame] | 122 | } |
reed | 4af267b | 2014-11-21 08:46:37 -0800 | [diff] [blame] | 123 | return image; |
reed@google.com | 5d4ba88 | 2012-07-31 15:45:27 +0000 | [diff] [blame] | 124 | } |
| 125 | |
kkinnunen | abcfab4 | 2015-02-22 22:53:44 -0800 | [diff] [blame] | 126 | // Create a new render target and, if necessary, copy the contents of the old |
| 127 | // render target into it. Note that this flushes the SkGpuDevice but |
robertphillips@google.com | 97b6b07 | 2012-10-31 14:48:39 +0000 | [diff] [blame] | 128 | // doesn't force an OpenGL flush. |
commit-bot@chromium.org | c4c9870 | 2013-04-22 14:28:01 +0000 | [diff] [blame] | 129 | void SkSurface_Gpu::onCopyOnWrite(ContentChangeMode mode) { |
Robert Phillips | 602b79c | 2017-06-23 11:26:28 -0400 | [diff] [blame] | 130 | GrRenderTargetContext* rtc = fDevice->accessRenderTargetContext(); |
| 131 | |
| 132 | // 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] | 133 | // image because onCopyOnWrite is only called when there is a cached image. |
Robert Phillips | ac6b1fa | 2017-03-20 08:38:50 -0400 | [diff] [blame] | 134 | sk_sp<SkImage> image(this->refCachedImage()); |
bsalomon | eaaaf0b | 2015-01-23 08:08:04 -0800 | [diff] [blame] | 135 | SkASSERT(image); |
Robert Phillips | 602b79c | 2017-06-23 11:26:28 -0400 | [diff] [blame] | 136 | |
| 137 | GrSurfaceProxy* imageProxy = ((SkImage_Base*) image.get())->peekProxy(); |
| 138 | SkASSERT(imageProxy); |
| 139 | |
| 140 | if (rtc->asSurfaceProxy()->underlyingUniqueID() == imageProxy->underlyingUniqueID()) { |
Robert Phillips | 6de9904 | 2017-01-31 11:31:39 -0500 | [diff] [blame] | 141 | fDevice->replaceRenderTargetContext(SkSurface::kRetain_ContentChangeMode == mode); |
commit-bot@chromium.org | 28361fa | 2014-03-28 16:08:05 +0000 | [diff] [blame] | 142 | } else if (kDiscard_ContentChangeMode == mode) { |
| 143 | this->SkSurface_Gpu::onDiscard(); |
robertphillips@google.com | 97b6b07 | 2012-10-31 14:48:39 +0000 | [diff] [blame] | 144 | } |
reed@google.com | 5d4ba88 | 2012-07-31 15:45:27 +0000 | [diff] [blame] | 145 | } |
| 146 | |
commit-bot@chromium.org | 28361fa | 2014-03-28 16:08:05 +0000 | [diff] [blame] | 147 | void SkSurface_Gpu::onDiscard() { |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 148 | fDevice->accessRenderTargetContext()->discard(); |
commit-bot@chromium.org | 28361fa | 2014-03-28 16:08:05 +0000 | [diff] [blame] | 149 | } |
| 150 | |
Greg Daniel | c64ee46 | 2017-06-15 16:59:49 -0400 | [diff] [blame] | 151 | bool SkSurface_Gpu::onFlush(int numSemaphores, GrBackendSemaphore* signalSemaphores) { |
| 152 | return fDevice->flushAndSignalSemaphores(numSemaphores, signalSemaphores); |
Greg Daniel | a5cb781 | 2017-06-16 09:45:32 -0400 | [diff] [blame] | 153 | } |
| 154 | |
Greg Daniel | c64ee46 | 2017-06-15 16:59:49 -0400 | [diff] [blame] | 155 | bool SkSurface_Gpu::onWait(int numSemaphores, const GrBackendSemaphore* waitSemaphores) { |
| 156 | return fDevice->wait(numSemaphores, waitSemaphores); |
ericrk | f7b8b8a | 2016-02-24 14:49:51 -0800 | [diff] [blame] | 157 | } |
| 158 | |
reed@google.com | 5d4ba88 | 2012-07-31 15:45:27 +0000 | [diff] [blame] | 159 | /////////////////////////////////////////////////////////////////////////////// |
| 160 | |
brianosman | 0e22eb8 | 2016-08-30 07:07:59 -0700 | [diff] [blame] | 161 | bool SkSurface_Gpu::Valid(const SkImageInfo& info) { |
| 162 | switch (info.colorType()) { |
| 163 | case kRGBA_F16_SkColorType: |
Matt Sarett | b6759dd | 2017-06-12 13:46:11 -0400 | [diff] [blame] | 164 | return info.colorSpace() && info.colorSpace()->gammaIsLinear(); |
brianosman | 0e22eb8 | 2016-08-30 07:07:59 -0700 | [diff] [blame] | 165 | case kRGBA_8888_SkColorType: |
| 166 | case kBGRA_8888_SkColorType: |
| 167 | return !info.colorSpace() || info.colorSpace()->gammaCloseToSRGB(); |
| 168 | default: |
| 169 | return !info.colorSpace(); |
| 170 | } |
| 171 | } |
| 172 | |
| 173 | bool SkSurface_Gpu::Valid(GrContext* context, GrPixelConfig config, SkColorSpace* colorSpace) { |
| 174 | switch (config) { |
| 175 | case kRGBA_half_GrPixelConfig: |
Matt Sarett | b6759dd | 2017-06-12 13:46:11 -0400 | [diff] [blame] | 176 | return colorSpace && colorSpace->gammaIsLinear(); |
brianosman | 0e22eb8 | 2016-08-30 07:07:59 -0700 | [diff] [blame] | 177 | case kSRGBA_8888_GrPixelConfig: |
| 178 | case kSBGRA_8888_GrPixelConfig: |
Matt Sarett | f388093 | 2017-03-24 10:06:03 -0400 | [diff] [blame] | 179 | return context->caps()->srgbSupport() && colorSpace && colorSpace->gammaCloseToSRGB(); |
brianosman | 0e22eb8 | 2016-08-30 07:07:59 -0700 | [diff] [blame] | 180 | case kRGBA_8888_GrPixelConfig: |
| 181 | case kBGRA_8888_GrPixelConfig: |
| 182 | // If we don't have sRGB support, we may get here with a color space. It still needs |
| 183 | // to be sRGB-like (so that the application will work correctly on sRGB devices.) |
| 184 | return !colorSpace || |
Matt Sarett | f388093 | 2017-03-24 10:06:03 -0400 | [diff] [blame] | 185 | (colorSpace->gammaCloseToSRGB() && !context->caps()->srgbSupport()); |
brianosman | 0e22eb8 | 2016-08-30 07:07:59 -0700 | [diff] [blame] | 186 | default: |
| 187 | return !colorSpace; |
| 188 | } |
| 189 | } |
| 190 | |
reed | e8f3062 | 2016-03-23 18:59:25 -0700 | [diff] [blame] | 191 | sk_sp<SkSurface> SkSurface::MakeRenderTarget(GrContext* ctx, SkBudgeted budgeted, |
| 192 | const SkImageInfo& info, int sampleCount, |
robertphillips | 7e92276 | 2016-07-26 11:38:17 -0700 | [diff] [blame] | 193 | GrSurfaceOrigin origin, const SkSurfaceProps* props) { |
brianosman | 0e22eb8 | 2016-08-30 07:07:59 -0700 | [diff] [blame] | 194 | if (!SkSurface_Gpu::Valid(info)) { |
| 195 | return nullptr; |
| 196 | } |
| 197 | |
robertphillips | 24e9128 | 2016-04-29 06:46:36 -0700 | [diff] [blame] | 198 | sk_sp<SkGpuDevice> device(SkGpuDevice::Make( |
robertphillips | 7e92276 | 2016-07-26 11:38:17 -0700 | [diff] [blame] | 199 | ctx, budgeted, info, sampleCount, origin, props, SkGpuDevice::kClear_InitContents)); |
bsalomon | afe3005 | 2015-01-16 07:32:33 -0800 | [diff] [blame] | 200 | if (!device) { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 201 | return nullptr; |
reed@google.com | 5d4ba88 | 2012-07-31 15:45:27 +0000 | [diff] [blame] | 202 | } |
robertphillips | 24e9128 | 2016-04-29 06:46:36 -0700 | [diff] [blame] | 203 | return sk_make_sp<SkSurface_Gpu>(std::move(device)); |
reed@google.com | 5d4ba88 | 2012-07-31 15:45:27 +0000 | [diff] [blame] | 204 | } |
reed | f037e0b | 2014-10-30 11:34:15 -0700 | [diff] [blame] | 205 | |
reed | e8f3062 | 2016-03-23 18:59:25 -0700 | [diff] [blame] | 206 | sk_sp<SkSurface> SkSurface::MakeFromBackendTexture(GrContext* context, |
| 207 | const GrBackendTextureDesc& desc, |
brianosman | dfe4f2e | 2016-07-21 13:28:36 -0700 | [diff] [blame] | 208 | sk_sp<SkColorSpace> colorSpace, |
reed | e8f3062 | 2016-03-23 18:59:25 -0700 | [diff] [blame] | 209 | const SkSurfaceProps* props) { |
robertphillips | 15c42ca | 2016-08-04 08:45:02 -0700 | [diff] [blame] | 210 | if (!context) { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 211 | return nullptr; |
bsalomon | e4579ad | 2015-04-08 08:38:40 -0700 | [diff] [blame] | 212 | } |
Greg Daniel | 7ef28f3 | 2017-04-20 16:41:55 +0000 | [diff] [blame] | 213 | GrBackendTexture tex(desc, context->contextPriv().getBackend()); |
| 214 | return MakeFromBackendTexture(context, tex, desc.fOrigin, desc.fSampleCnt, colorSpace, props); |
| 215 | } |
| 216 | |
| 217 | sk_sp<SkSurface> SkSurface::MakeFromBackendTexture(GrContext* context, const GrBackendTexture& tex, |
| 218 | GrSurfaceOrigin origin, int sampleCnt, |
| 219 | sk_sp<SkColorSpace> colorSpace, |
| 220 | const SkSurfaceProps* props) { |
| 221 | if (!context) { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 222 | return nullptr; |
bsalomon | e4579ad | 2015-04-08 08:38:40 -0700 | [diff] [blame] | 223 | } |
Greg Daniel | 7ef28f3 | 2017-04-20 16:41:55 +0000 | [diff] [blame] | 224 | if (!SkSurface_Gpu::Valid(context, tex.config(), colorSpace.get())) { |
brianosman | 0e22eb8 | 2016-08-30 07:07:59 -0700 | [diff] [blame] | 225 | return nullptr; |
| 226 | } |
robertphillips | 15c42ca | 2016-08-04 08:45:02 -0700 | [diff] [blame] | 227 | |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 228 | sk_sp<GrRenderTargetContext> rtc(context->contextPriv().makeBackendTextureRenderTargetContext( |
Greg Daniel | 7ef28f3 | 2017-04-20 16:41:55 +0000 | [diff] [blame] | 229 | tex, |
| 230 | origin, |
| 231 | sampleCnt, |
robertphillips | 15c42ca | 2016-08-04 08:45:02 -0700 | [diff] [blame] | 232 | std::move(colorSpace), |
Brian Osman | c1e3705 | 2017-03-09 14:19:20 -0500 | [diff] [blame] | 233 | props)); |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 234 | if (!rtc) { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 235 | return nullptr; |
bsalomon | e4579ad | 2015-04-08 08:38:40 -0700 | [diff] [blame] | 236 | } |
robertphillips | 15c42ca | 2016-08-04 08:45:02 -0700 | [diff] [blame] | 237 | |
Greg Daniel | 7ef28f3 | 2017-04-20 16:41:55 +0000 | [diff] [blame] | 238 | 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] | 239 | SkGpuDevice::kUninit_InitContents)); |
bsalomon | e4579ad | 2015-04-08 08:38:40 -0700 | [diff] [blame] | 240 | if (!device) { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 241 | return nullptr; |
bsalomon | e4579ad | 2015-04-08 08:38:40 -0700 | [diff] [blame] | 242 | } |
robertphillips | 24e9128 | 2016-04-29 06:46:36 -0700 | [diff] [blame] | 243 | return sk_make_sp<SkSurface_Gpu>(std::move(device)); |
bsalomon | e4579ad | 2015-04-08 08:38:40 -0700 | [diff] [blame] | 244 | } |
| 245 | |
reed | e8f3062 | 2016-03-23 18:59:25 -0700 | [diff] [blame] | 246 | sk_sp<SkSurface> SkSurface::MakeFromBackendRenderTarget(GrContext* context, |
| 247 | const GrBackendRenderTargetDesc& desc, |
brianosman | dfe4f2e | 2016-07-21 13:28:36 -0700 | [diff] [blame] | 248 | sk_sp<SkColorSpace> colorSpace, |
reed | e8f3062 | 2016-03-23 18:59:25 -0700 | [diff] [blame] | 249 | const SkSurfaceProps* props) { |
robertphillips | 24e9128 | 2016-04-29 06:46:36 -0700 | [diff] [blame] | 250 | if (!context) { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 251 | return nullptr; |
bsalomon | d3e259a | 2015-06-30 12:04:40 -0700 | [diff] [blame] | 252 | } |
Greg Daniel | bcf612b | 2017-05-01 13:50:58 +0000 | [diff] [blame] | 253 | |
| 254 | GrBackendRenderTarget backendRT(desc, context->contextPriv().getBackend()); |
| 255 | return MakeFromBackendRenderTarget(context, backendRT, desc.fOrigin, |
| 256 | std::move(colorSpace), props); |
| 257 | |
| 258 | } |
| 259 | |
| 260 | sk_sp<SkSurface> SkSurface::MakeFromBackendRenderTarget(GrContext* context, |
| 261 | const GrBackendRenderTarget& backendRT, |
| 262 | GrSurfaceOrigin origin, |
| 263 | sk_sp<SkColorSpace> colorSpace, |
| 264 | const SkSurfaceProps* props) { |
| 265 | if (!context) { |
| 266 | return nullptr; |
| 267 | } |
| 268 | if (!SkSurface_Gpu::Valid(context, backendRT.config(), colorSpace.get())) { |
brianosman | 0e22eb8 | 2016-08-30 07:07:59 -0700 | [diff] [blame] | 269 | return nullptr; |
| 270 | } |
robertphillips | 15c42ca | 2016-08-04 08:45:02 -0700 | [diff] [blame] | 271 | |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 272 | sk_sp<GrRenderTargetContext> rtc( |
Greg Daniel | bcf612b | 2017-05-01 13:50:58 +0000 | [diff] [blame] | 273 | context->contextPriv().makeBackendRenderTargetRenderTargetContext(backendRT, |
| 274 | origin, |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 275 | std::move(colorSpace), |
| 276 | props)); |
| 277 | if (!rtc) { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 278 | return nullptr; |
bsalomon | d3e259a | 2015-06-30 12:04:40 -0700 | [diff] [blame] | 279 | } |
robertphillips | 15c42ca | 2016-08-04 08:45:02 -0700 | [diff] [blame] | 280 | |
Greg Daniel | bcf612b | 2017-05-01 13:50:58 +0000 | [diff] [blame] | 281 | sk_sp<SkGpuDevice> device(SkGpuDevice::Make(context, std::move(rtc), |
| 282 | backendRT.width(), backendRT.height(), |
robertphillips | 24e9128 | 2016-04-29 06:46:36 -0700 | [diff] [blame] | 283 | SkGpuDevice::kUninit_InitContents)); |
bsalomon | d3e259a | 2015-06-30 12:04:40 -0700 | [diff] [blame] | 284 | if (!device) { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 285 | return nullptr; |
bsalomon | d3e259a | 2015-06-30 12:04:40 -0700 | [diff] [blame] | 286 | } |
robertphillips | 15c42ca | 2016-08-04 08:45:02 -0700 | [diff] [blame] | 287 | |
robertphillips | 24e9128 | 2016-04-29 06:46:36 -0700 | [diff] [blame] | 288 | return sk_make_sp<SkSurface_Gpu>(std::move(device)); |
bsalomon | d3e259a | 2015-06-30 12:04:40 -0700 | [diff] [blame] | 289 | } |
| 290 | |
reed | e8f3062 | 2016-03-23 18:59:25 -0700 | [diff] [blame] | 291 | sk_sp<SkSurface> SkSurface::MakeFromBackendTextureAsRenderTarget(GrContext* context, |
| 292 | const GrBackendTextureDesc& desc, |
brianosman | dfe4f2e | 2016-07-21 13:28:36 -0700 | [diff] [blame] | 293 | sk_sp<SkColorSpace> colorSpace, |
reed | e8f3062 | 2016-03-23 18:59:25 -0700 | [diff] [blame] | 294 | const SkSurfaceProps* props) { |
robertphillips | 24e9128 | 2016-04-29 06:46:36 -0700 | [diff] [blame] | 295 | if (!context) { |
ericrk | f7b8b8a | 2016-02-24 14:49:51 -0800 | [diff] [blame] | 296 | return nullptr; |
| 297 | } |
Greg Daniel | 7ef28f3 | 2017-04-20 16:41:55 +0000 | [diff] [blame] | 298 | GrBackendTexture tex(desc, context->contextPriv().getBackend()); |
| 299 | return MakeFromBackendTextureAsRenderTarget(context, tex, desc.fOrigin, desc.fSampleCnt, |
| 300 | std::move(colorSpace), props); |
| 301 | } |
| 302 | |
| 303 | sk_sp<SkSurface> SkSurface::MakeFromBackendTextureAsRenderTarget(GrContext* context, |
| 304 | const GrBackendTexture& tex, |
| 305 | GrSurfaceOrigin origin, |
| 306 | int sampleCnt, |
| 307 | sk_sp<SkColorSpace> colorSpace, |
| 308 | const SkSurfaceProps* props) { |
| 309 | if (!context) { |
| 310 | return nullptr; |
| 311 | } |
| 312 | if (!SkSurface_Gpu::Valid(context, tex.config(), colorSpace.get())) { |
brianosman | 0e22eb8 | 2016-08-30 07:07:59 -0700 | [diff] [blame] | 313 | return nullptr; |
| 314 | } |
robertphillips | 15c42ca | 2016-08-04 08:45:02 -0700 | [diff] [blame] | 315 | |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 316 | sk_sp<GrRenderTargetContext> rtc( |
| 317 | context->contextPriv().makeBackendTextureAsRenderTargetRenderTargetContext( |
Greg Daniel | 7ef28f3 | 2017-04-20 16:41:55 +0000 | [diff] [blame] | 318 | tex, |
| 319 | origin, |
| 320 | sampleCnt, |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 321 | std::move(colorSpace), |
| 322 | props)); |
| 323 | if (!rtc) { |
ericrk | f7b8b8a | 2016-02-24 14:49:51 -0800 | [diff] [blame] | 324 | return nullptr; |
| 325 | } |
robertphillips | 15c42ca | 2016-08-04 08:45:02 -0700 | [diff] [blame] | 326 | |
Greg Daniel | 7ef28f3 | 2017-04-20 16:41:55 +0000 | [diff] [blame] | 327 | 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] | 328 | SkGpuDevice::kUninit_InitContents)); |
ericrk | f7b8b8a | 2016-02-24 14:49:51 -0800 | [diff] [blame] | 329 | if (!device) { |
| 330 | return nullptr; |
| 331 | } |
robertphillips | 24e9128 | 2016-04-29 06:46:36 -0700 | [diff] [blame] | 332 | return sk_make_sp<SkSurface_Gpu>(std::move(device)); |
ericrk | f7b8b8a | 2016-02-24 14:49:51 -0800 | [diff] [blame] | 333 | } |
| 334 | |
reed | f037e0b | 2014-10-30 11:34:15 -0700 | [diff] [blame] | 335 | #endif |