robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [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 | #include "GrSurfaceProxy.h" |
Robert Phillips | b726d58 | 2017-03-09 16:36:32 -0500 | [diff] [blame] | 9 | #include "GrSurfaceProxyPriv.h" |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 10 | |
Robert Phillips | 784b7bf | 2016-12-09 13:35:02 -0500 | [diff] [blame] | 11 | #include "GrCaps.h" |
Robert Phillips | e2f7d18 | 2016-12-15 09:23:05 -0500 | [diff] [blame] | 12 | #include "GrContext.h" |
| 13 | #include "GrContextPriv.h" |
Robert Phillips | c7635fa | 2016-10-28 13:25:24 -0400 | [diff] [blame] | 14 | #include "GrGpuResourcePriv.h" |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 15 | #include "GrOpList.h" |
Brian Osman | 32342f0 | 2017-03-04 08:12:46 -0500 | [diff] [blame] | 16 | #include "GrResourceProvider.h" |
Robert Phillips | e2f7d18 | 2016-12-15 09:23:05 -0500 | [diff] [blame] | 17 | #include "GrSurfaceContext.h" |
Robert Phillips | a4c41b3 | 2017-03-15 13:02:45 -0400 | [diff] [blame] | 18 | #include "GrTexturePriv.h" |
Robert Phillips | 3743013 | 2016-11-09 06:50:43 -0500 | [diff] [blame] | 19 | #include "GrTextureRenderTargetProxy.h" |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 20 | |
Robert Phillips | 93f1633 | 2016-11-23 19:37:13 -0500 | [diff] [blame] | 21 | #include "SkMathPriv.h" |
| 22 | |
Robert Phillips | c7635fa | 2016-10-28 13:25:24 -0400 | [diff] [blame] | 23 | GrSurfaceProxy::GrSurfaceProxy(sk_sp<GrSurface> surface, SkBackingFit fit) |
| 24 | : INHERITED(std::move(surface)) |
| 25 | , fDesc(fTarget->desc()) |
| 26 | , fFit(fit) |
| 27 | , fBudgeted(fTarget->resourcePriv().isBudgeted()) |
Robert Phillips | c787e49 | 2017-02-28 11:26:32 -0500 | [diff] [blame] | 28 | , fFlags(0) |
Robert Phillips | 294870f | 2016-11-11 12:38:40 -0500 | [diff] [blame] | 29 | , fUniqueID(fTarget->uniqueID()) // Note: converting from unique resource ID to a proxy ID! |
Robert Phillips | 8bc06d0 | 2016-11-01 17:28:40 -0400 | [diff] [blame] | 30 | , fGpuMemorySize(kInvalidGpuMemorySize) |
Robert Phillips | c7635fa | 2016-10-28 13:25:24 -0400 | [diff] [blame] | 31 | , fLastOpList(nullptr) { |
| 32 | } |
| 33 | |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 34 | GrSurfaceProxy::~GrSurfaceProxy() { |
Robert Phillips | 4a39504 | 2017-04-24 16:27:17 +0000 | [diff] [blame] | 35 | if (fLastOpList) { |
| 36 | fLastOpList->clearTarget(); |
| 37 | } |
| 38 | SkSafeUnref(fLastOpList); |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 39 | } |
| 40 | |
Brian Osman | 32342f0 | 2017-03-04 08:12:46 -0500 | [diff] [blame] | 41 | GrSurface* GrSurfaceProxy::instantiate(GrResourceProvider* resourceProvider) { |
Robert Phillips | eaa8625 | 2016-11-08 13:49:39 +0000 | [diff] [blame] | 42 | if (fTarget) { |
| 43 | return fTarget; |
| 44 | } |
| 45 | |
| 46 | if (SkBackingFit::kApprox == fFit) { |
Brian Osman | 32342f0 | 2017-03-04 08:12:46 -0500 | [diff] [blame] | 47 | fTarget = resourceProvider->createApproxTexture(fDesc, fFlags); |
Robert Phillips | eaa8625 | 2016-11-08 13:49:39 +0000 | [diff] [blame] | 48 | } else { |
Robert Phillips | e78b725 | 2017-04-06 07:59:41 -0400 | [diff] [blame] | 49 | fTarget = resourceProvider->createTexture(fDesc, fBudgeted, fFlags).release(); |
Robert Phillips | eaa8625 | 2016-11-08 13:49:39 +0000 | [diff] [blame] | 50 | } |
| 51 | if (!fTarget) { |
| 52 | return nullptr; |
| 53 | } |
| 54 | |
Robert Phillips | a4c41b3 | 2017-03-15 13:02:45 -0400 | [diff] [blame] | 55 | fTarget->asTexture()->texturePriv().setMipColorMode(fMipColorMode); |
robertphillips | 1125a03 | 2016-11-16 11:17:17 -0800 | [diff] [blame] | 56 | this->INHERITED::transferRefs(); |
| 57 | |
Robert Phillips | eaa8625 | 2016-11-08 13:49:39 +0000 | [diff] [blame] | 58 | #ifdef SK_DEBUG |
| 59 | if (kInvalidGpuMemorySize != this->getRawGpuMemorySize_debugOnly()) { |
Robert Phillips | 784b7bf | 2016-12-09 13:35:02 -0500 | [diff] [blame] | 60 | SkASSERT(fTarget->gpuMemorySize() <= this->getRawGpuMemorySize_debugOnly()); |
Robert Phillips | eaa8625 | 2016-11-08 13:49:39 +0000 | [diff] [blame] | 61 | } |
| 62 | #endif |
| 63 | |
| 64 | return fTarget; |
| 65 | } |
| 66 | |
Robert Phillips | 784b7bf | 2016-12-09 13:35:02 -0500 | [diff] [blame] | 67 | int GrSurfaceProxy::worstCaseWidth(const GrCaps& caps) const { |
Robert Phillips | 93f1633 | 2016-11-23 19:37:13 -0500 | [diff] [blame] | 68 | if (fTarget) { |
| 69 | return fTarget->width(); |
| 70 | } |
| 71 | |
| 72 | if (SkBackingFit::kExact == fFit) { |
| 73 | return fDesc.fWidth; |
| 74 | } |
| 75 | |
Robert Phillips | 784b7bf | 2016-12-09 13:35:02 -0500 | [diff] [blame] | 76 | if (caps.reuseScratchTextures() || fDesc.fFlags & kRenderTarget_GrSurfaceFlag) { |
Brian Osman | 32342f0 | 2017-03-04 08:12:46 -0500 | [diff] [blame] | 77 | return SkTMax(GrResourceProvider::kMinScratchTextureSize, GrNextPow2(fDesc.fWidth)); |
Robert Phillips | 784b7bf | 2016-12-09 13:35:02 -0500 | [diff] [blame] | 78 | } |
| 79 | |
| 80 | return fDesc.fWidth; |
Robert Phillips | 93f1633 | 2016-11-23 19:37:13 -0500 | [diff] [blame] | 81 | } |
| 82 | |
Robert Phillips | 784b7bf | 2016-12-09 13:35:02 -0500 | [diff] [blame] | 83 | int GrSurfaceProxy::worstCaseHeight(const GrCaps& caps) const { |
Robert Phillips | 93f1633 | 2016-11-23 19:37:13 -0500 | [diff] [blame] | 84 | if (fTarget) { |
| 85 | return fTarget->height(); |
| 86 | } |
| 87 | |
| 88 | if (SkBackingFit::kExact == fFit) { |
| 89 | return fDesc.fHeight; |
| 90 | } |
| 91 | |
Robert Phillips | 784b7bf | 2016-12-09 13:35:02 -0500 | [diff] [blame] | 92 | if (caps.reuseScratchTextures() || fDesc.fFlags & kRenderTarget_GrSurfaceFlag) { |
Brian Osman | 32342f0 | 2017-03-04 08:12:46 -0500 | [diff] [blame] | 93 | return SkTMax(GrResourceProvider::kMinScratchTextureSize, GrNextPow2(fDesc.fHeight)); |
Robert Phillips | 784b7bf | 2016-12-09 13:35:02 -0500 | [diff] [blame] | 94 | } |
| 95 | |
| 96 | return fDesc.fHeight; |
Robert Phillips | 93f1633 | 2016-11-23 19:37:13 -0500 | [diff] [blame] | 97 | } |
| 98 | |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 99 | void GrSurfaceProxy::setLastOpList(GrOpList* opList) { |
| 100 | if (fLastOpList) { |
Robert Phillips | 4a39504 | 2017-04-24 16:27:17 +0000 | [diff] [blame] | 101 | // The non-MDB world never closes so we can't check this condition |
| 102 | #ifdef ENABLE_MDB |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 103 | SkASSERT(fLastOpList->isClosed()); |
Robert Phillips | df2bf21 | 2017-04-24 08:39:40 -0400 | [diff] [blame] | 104 | #endif |
Robert Phillips | 4a39504 | 2017-04-24 16:27:17 +0000 | [diff] [blame] | 105 | fLastOpList->clearTarget(); |
| 106 | } |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 107 | |
Robert Phillips | 4a39504 | 2017-04-24 16:27:17 +0000 | [diff] [blame] | 108 | SkRefCnt_SafeAssign(fLastOpList, opList); |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 109 | } |
Robert Phillips | 3743013 | 2016-11-09 06:50:43 -0500 | [diff] [blame] | 110 | |
Brian Osman | 45580d3 | 2016-11-23 09:37:01 -0500 | [diff] [blame] | 111 | GrRenderTargetOpList* GrSurfaceProxy::getLastRenderTargetOpList() { |
| 112 | return fLastOpList ? fLastOpList->asRenderTargetOpList() : nullptr; |
| 113 | } |
| 114 | |
| 115 | GrTextureOpList* GrSurfaceProxy::getLastTextureOpList() { |
| 116 | return fLastOpList ? fLastOpList->asTextureOpList() : nullptr; |
| 117 | } |
| 118 | |
Robert Phillips | 3743013 | 2016-11-09 06:50:43 -0500 | [diff] [blame] | 119 | sk_sp<GrSurfaceProxy> GrSurfaceProxy::MakeWrapped(sk_sp<GrSurface> surf) { |
Robert Phillips | bc7a4fb | 2017-01-23 15:30:35 -0500 | [diff] [blame] | 120 | if (!surf) { |
| 121 | return nullptr; |
| 122 | } |
| 123 | |
Robert Phillips | 3743013 | 2016-11-09 06:50:43 -0500 | [diff] [blame] | 124 | if (surf->asTexture()) { |
| 125 | if (surf->asRenderTarget()) { |
| 126 | return sk_sp<GrSurfaceProxy>(new GrTextureRenderTargetProxy(std::move(surf))); |
| 127 | } else { |
| 128 | return sk_sp<GrSurfaceProxy>(new GrTextureProxy(std::move(surf))); |
| 129 | } |
| 130 | } else { |
| 131 | SkASSERT(surf->asRenderTarget()); |
| 132 | |
| 133 | // Not texturable |
| 134 | return sk_sp<GrSurfaceProxy>(new GrRenderTargetProxy(std::move(surf))); |
| 135 | } |
| 136 | } |
| 137 | |
Robert Phillips | 63c6746 | 2017-02-15 14:19:01 -0500 | [diff] [blame] | 138 | sk_sp<GrTextureProxy> GrSurfaceProxy::MakeWrapped(sk_sp<GrTexture> tex) { |
| 139 | if (!tex) { |
| 140 | return nullptr; |
| 141 | } |
| 142 | |
| 143 | if (tex->asRenderTarget()) { |
| 144 | return sk_sp<GrTextureProxy>(new GrTextureRenderTargetProxy(std::move(tex))); |
| 145 | } else { |
| 146 | return sk_sp<GrTextureProxy>(new GrTextureProxy(std::move(tex))); |
| 147 | } |
| 148 | } |
| 149 | |
Brian Osman | 32342f0 | 2017-03-04 08:12:46 -0500 | [diff] [blame] | 150 | sk_sp<GrTextureProxy> GrSurfaceProxy::MakeDeferred(GrResourceProvider* resourceProvider, |
Robert Phillips | 3743013 | 2016-11-09 06:50:43 -0500 | [diff] [blame] | 151 | const GrSurfaceDesc& desc, |
| 152 | SkBackingFit fit, |
Robert Phillips | c787e49 | 2017-02-28 11:26:32 -0500 | [diff] [blame] | 153 | SkBudgeted budgeted, |
| 154 | uint32_t flags) { |
| 155 | SkASSERT(0 == flags || GrResourceProvider::kNoPendingIO_Flag == flags); |
| 156 | |
Robert Phillips | 26c90e0 | 2017-03-14 14:39:29 -0400 | [diff] [blame] | 157 | const GrCaps* caps = resourceProvider->caps(); |
| 158 | |
| 159 | // TODO: move this logic into GrResourceProvider! |
Robert Phillips | 8f741bb | 2017-01-31 17:25:29 -0500 | [diff] [blame] | 160 | // TODO: share this testing code with check_texture_creation_params |
Robert Phillips | 6520a69 | 2017-02-01 09:20:00 -0500 | [diff] [blame] | 161 | if (GrPixelConfigIsCompressed(desc.fConfig)) { |
| 162 | if (SkBackingFit::kApprox == fit || kBottomLeft_GrSurfaceOrigin == desc.fOrigin) { |
| 163 | // We don't allow scratch compressed textures and, apparently can't Y-flip compressed |
| 164 | // textures |
| 165 | return nullptr; |
| 166 | } |
| 167 | |
Robert Phillips | 26c90e0 | 2017-03-14 14:39:29 -0400 | [diff] [blame] | 168 | if (!caps->npotTextureTileSupport() && (!SkIsPow2(desc.fWidth) || !SkIsPow2(desc.fHeight))) { |
Robert Phillips | 6520a69 | 2017-02-01 09:20:00 -0500 | [diff] [blame] | 169 | return nullptr; |
| 170 | } |
Robert Phillips | 08c5ec7 | 2017-01-30 12:26:47 -0500 | [diff] [blame] | 171 | } |
| 172 | |
Robert Phillips | 26c90e0 | 2017-03-14 14:39:29 -0400 | [diff] [blame] | 173 | if (!caps->isConfigTexturable(desc.fConfig)) { |
Robert Phillips | 8f741bb | 2017-01-31 17:25:29 -0500 | [diff] [blame] | 174 | return nullptr; |
| 175 | } |
| 176 | |
| 177 | bool willBeRT = SkToBool(desc.fFlags & kRenderTarget_GrSurfaceFlag); |
Robert Phillips | 26c90e0 | 2017-03-14 14:39:29 -0400 | [diff] [blame] | 178 | if (willBeRT && !caps->isConfigRenderable(desc.fConfig, desc.fSampleCnt > 0)) { |
Robert Phillips | 8f741bb | 2017-01-31 17:25:29 -0500 | [diff] [blame] | 179 | return nullptr; |
| 180 | } |
| 181 | |
| 182 | // We currently do not support multisampled textures |
| 183 | if (!willBeRT && desc.fSampleCnt > 0) { |
| 184 | return nullptr; |
| 185 | } |
| 186 | |
| 187 | int maxSize; |
| 188 | if (willBeRT) { |
Robert Phillips | 26c90e0 | 2017-03-14 14:39:29 -0400 | [diff] [blame] | 189 | maxSize = caps->maxRenderTargetSize(); |
Robert Phillips | 8f741bb | 2017-01-31 17:25:29 -0500 | [diff] [blame] | 190 | } else { |
Robert Phillips | 26c90e0 | 2017-03-14 14:39:29 -0400 | [diff] [blame] | 191 | maxSize = caps->maxTextureSize(); |
Robert Phillips | 8f741bb | 2017-01-31 17:25:29 -0500 | [diff] [blame] | 192 | } |
| 193 | |
Robert Phillips | 78de212 | 2017-04-26 07:44:26 -0400 | [diff] [blame] | 194 | if (desc.fWidth > maxSize || desc.fHeight > maxSize || desc.fWidth <= 0 || desc.fHeight <= 0) { |
Robert Phillips | 8f741bb | 2017-01-31 17:25:29 -0500 | [diff] [blame] | 195 | return nullptr; |
| 196 | } |
| 197 | |
Robert Phillips | 6520a69 | 2017-02-01 09:20:00 -0500 | [diff] [blame] | 198 | GrSurfaceDesc copyDesc = desc; |
Robert Phillips | 26c90e0 | 2017-03-14 14:39:29 -0400 | [diff] [blame] | 199 | copyDesc.fSampleCnt = SkTMin(desc.fSampleCnt, caps->maxSampleCount()); |
Robert Phillips | 6520a69 | 2017-02-01 09:20:00 -0500 | [diff] [blame] | 200 | |
Robert Phillips | cd90104 | 2017-04-27 12:04:15 -0400 | [diff] [blame] | 201 | #ifdef SK_DISABLE_DEFERRED_PROXIES |
| 202 | sk_sp<GrTexture> tex; |
| 203 | |
| 204 | if (SkBackingFit::kApprox == fit) { |
| 205 | tex.reset(resourceProvider->createApproxTexture(copyDesc, flags)); |
| 206 | } else { |
| 207 | tex = resourceProvider->createTexture(copyDesc, budgeted, flags); |
| 208 | } |
| 209 | |
| 210 | if (!tex) { |
| 211 | return nullptr; |
| 212 | } |
| 213 | |
| 214 | return GrSurfaceProxy::MakeWrapped(std::move(tex)); |
| 215 | #else |
Robert Phillips | 8f741bb | 2017-01-31 17:25:29 -0500 | [diff] [blame] | 216 | if (willBeRT) { |
Robert Phillips | 3743013 | 2016-11-09 06:50:43 -0500 | [diff] [blame] | 217 | // We know anything we instantiate later from this deferred path will be |
| 218 | // both texturable and renderable |
Robert Phillips | 26c90e0 | 2017-03-14 14:39:29 -0400 | [diff] [blame] | 219 | return sk_sp<GrTextureProxy>(new GrTextureRenderTargetProxy(*caps, copyDesc, fit, |
Robert Phillips | c787e49 | 2017-02-28 11:26:32 -0500 | [diff] [blame] | 220 | budgeted, flags)); |
Robert Phillips | 3743013 | 2016-11-09 06:50:43 -0500 | [diff] [blame] | 221 | } |
| 222 | |
Robert Phillips | 2f49314 | 2017-03-02 18:18:38 -0500 | [diff] [blame] | 223 | return sk_sp<GrTextureProxy>(new GrTextureProxy(copyDesc, fit, budgeted, nullptr, 0, flags)); |
Robert Phillips | cd90104 | 2017-04-27 12:04:15 -0400 | [diff] [blame] | 224 | #endif |
Robert Phillips | 3743013 | 2016-11-09 06:50:43 -0500 | [diff] [blame] | 225 | } |
| 226 | |
Robert Phillips | 26c90e0 | 2017-03-14 14:39:29 -0400 | [diff] [blame] | 227 | sk_sp<GrTextureProxy> GrSurfaceProxy::MakeDeferred(GrResourceProvider* resourceProvider, |
Robert Phillips | 3743013 | 2016-11-09 06:50:43 -0500 | [diff] [blame] | 228 | const GrSurfaceDesc& desc, |
| 229 | SkBudgeted budgeted, |
| 230 | const void* srcData, |
| 231 | size_t rowBytes) { |
| 232 | if (srcData) { |
Robert Phillips | 45fdae1 | 2017-04-17 12:57:27 -0400 | [diff] [blame] | 233 | GrMipLevel mipLevel = { srcData, rowBytes }; |
| 234 | |
| 235 | return resourceProvider->createTextureProxy(desc, budgeted, mipLevel); |
Robert Phillips | 3743013 | 2016-11-09 06:50:43 -0500 | [diff] [blame] | 236 | } |
| 237 | |
Robert Phillips | 26c90e0 | 2017-03-14 14:39:29 -0400 | [diff] [blame] | 238 | return GrSurfaceProxy::MakeDeferred(resourceProvider, desc, SkBackingFit::kExact, budgeted); |
Robert Phillips | 3743013 | 2016-11-09 06:50:43 -0500 | [diff] [blame] | 239 | } |
| 240 | |
Greg Daniel | 7ef28f3 | 2017-04-20 16:41:55 +0000 | [diff] [blame] | 241 | sk_sp<GrTextureProxy> GrSurfaceProxy::MakeWrappedBackend(GrContext* context, |
| 242 | GrBackendTexture& backendTex, |
| 243 | GrSurfaceOrigin origin) { |
| 244 | sk_sp<GrTexture> tex(context->resourceProvider()->wrapBackendTexture( |
| 245 | backendTex, origin, kNone_GrBackendTextureFlag, 0)); |
Robert Phillips | 26caf89 | 2017-01-27 10:58:31 -0500 | [diff] [blame] | 246 | return GrSurfaceProxy::MakeWrapped(std::move(tex)); |
| 247 | } |
| 248 | |
Brian Osman | 45580d3 | 2016-11-23 09:37:01 -0500 | [diff] [blame] | 249 | #ifdef SK_DEBUG |
| 250 | void GrSurfaceProxy::validate(GrContext* context) const { |
| 251 | if (fTarget) { |
| 252 | SkASSERT(fTarget->getContext() == context); |
| 253 | } |
| 254 | |
| 255 | INHERITED::validate(); |
| 256 | } |
| 257 | #endif |
Robert Phillips | e2f7d18 | 2016-12-15 09:23:05 -0500 | [diff] [blame] | 258 | |
Robert Phillips | 63c6746 | 2017-02-15 14:19:01 -0500 | [diff] [blame] | 259 | sk_sp<GrTextureProxy> GrSurfaceProxy::Copy(GrContext* context, |
Robert Phillips | e2f7d18 | 2016-12-15 09:23:05 -0500 | [diff] [blame] | 260 | GrSurfaceProxy* src, |
| 261 | SkIRect srcRect, |
| 262 | SkBudgeted budgeted) { |
| 263 | if (!srcRect.intersect(SkIRect::MakeWH(src->width(), src->height()))) { |
| 264 | return nullptr; |
| 265 | } |
| 266 | |
| 267 | GrSurfaceDesc dstDesc = src->desc(); |
| 268 | dstDesc.fWidth = srcRect.width(); |
| 269 | dstDesc.fHeight = srcRect.height(); |
| 270 | |
| 271 | sk_sp<GrSurfaceContext> dstContext(context->contextPriv().makeDeferredSurfaceContext( |
| 272 | dstDesc, |
| 273 | SkBackingFit::kExact, |
| 274 | budgeted)); |
| 275 | if (!dstContext) { |
| 276 | return nullptr; |
| 277 | } |
| 278 | |
| 279 | if (!dstContext->copy(src, srcRect, SkIPoint::Make(0, 0))) { |
| 280 | return nullptr; |
| 281 | } |
| 282 | |
Robert Phillips | 63c6746 | 2017-02-15 14:19:01 -0500 | [diff] [blame] | 283 | return dstContext->asTextureProxyRef(); |
| 284 | } |
| 285 | |
| 286 | sk_sp<GrTextureProxy> GrSurfaceProxy::Copy(GrContext* context, GrSurfaceProxy* src, |
| 287 | SkBudgeted budgeted) { |
| 288 | return Copy(context, src, SkIRect::MakeWH(src->width(), src->height()), budgeted); |
Robert Phillips | e2f7d18 | 2016-12-15 09:23:05 -0500 | [diff] [blame] | 289 | } |
| 290 | |
Robert Phillips | d46697a | 2017-01-25 12:10:37 -0500 | [diff] [blame] | 291 | sk_sp<GrSurfaceContext> GrSurfaceProxy::TestCopy(GrContext* context, const GrSurfaceDesc& dstDesc, |
| 292 | GrSurfaceProxy* srcProxy) { |
Robert Phillips | e2f7d18 | 2016-12-15 09:23:05 -0500 | [diff] [blame] | 293 | |
| 294 | sk_sp<GrSurfaceContext> dstContext(context->contextPriv().makeDeferredSurfaceContext( |
| 295 | dstDesc, |
| 296 | SkBackingFit::kExact, |
Robert Phillips | d46697a | 2017-01-25 12:10:37 -0500 | [diff] [blame] | 297 | SkBudgeted::kYes)); |
Robert Phillips | e2f7d18 | 2016-12-15 09:23:05 -0500 | [diff] [blame] | 298 | if (!dstContext) { |
| 299 | return nullptr; |
| 300 | } |
| 301 | |
Robert Phillips | d46697a | 2017-01-25 12:10:37 -0500 | [diff] [blame] | 302 | if (!dstContext->copy(srcProxy)) { |
Robert Phillips | e2f7d18 | 2016-12-15 09:23:05 -0500 | [diff] [blame] | 303 | return nullptr; |
| 304 | } |
| 305 | |
Robert Phillips | d46697a | 2017-01-25 12:10:37 -0500 | [diff] [blame] | 306 | return dstContext; |
Robert Phillips | e2f7d18 | 2016-12-15 09:23:05 -0500 | [diff] [blame] | 307 | } |
Robert Phillips | b726d58 | 2017-03-09 16:36:32 -0500 | [diff] [blame] | 308 | |
Robert Phillips | 0ae6faa | 2017-03-21 16:22:00 -0400 | [diff] [blame] | 309 | void GrSurfaceProxyPriv::exactify() { |
| 310 | if (this->isExact()) { |
| 311 | return; |
| 312 | } |
| 313 | |
| 314 | SkASSERT(SkBackingFit::kApprox == fProxy->fFit); |
| 315 | |
| 316 | if (fProxy->fTarget) { |
| 317 | // The kApprox but already instantiated case. Setting the proxy's width & height to |
| 318 | // the instantiated width & height could have side-effects going forward, since we're |
| 319 | // obliterating the area of interest information. This call (exactify) only used |
| 320 | // when converting an SkSpecialImage to an SkImage so the proxy shouldn't be |
| 321 | // used for additional draws. |
| 322 | fProxy->fDesc.fWidth = fProxy->fTarget->width(); |
| 323 | fProxy->fDesc.fHeight = fProxy->fTarget->height(); |
| 324 | return; |
| 325 | } |
| 326 | |
| 327 | // The kApprox uninstantiated case. Making this proxy be exact should be okay. |
| 328 | // It could mess things up if prior decisions were based on the approximate size. |
| 329 | fProxy->fFit = SkBackingFit::kExact; |
| 330 | // If fGpuMemorySize is used when caching specialImages for the image filter DAG. If it has |
| 331 | // already been computed we want to leave it alone so that amount will be removed when |
| 332 | // the special image goes away. If it hasn't been computed yet it might as well compute the |
| 333 | // exact amount. |
| 334 | } |
| 335 | |