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