epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 1 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 2 | /* |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 3 | * Copyright 2010 Google Inc. |
| 4 | * |
| 5 | * Use of this source code is governed by a BSD-style license that can be |
| 6 | * found in the LICENSE file. |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 7 | */ |
| 8 | |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 9 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 10 | #include "GrGpu.h" |
bsalomon@google.com | 558a75b | 2011-08-08 17:01:14 +0000 | [diff] [blame] | 11 | |
bsalomon | eb1cb5c | 2015-05-22 08:01:09 -0700 | [diff] [blame] | 12 | #include "GrCaps.h" |
bsalomon@google.com | 558a75b | 2011-08-08 17:01:14 +0000 | [diff] [blame] | 13 | #include "GrContext.h" |
bsalomon | 3582d3e | 2015-02-13 14:20:05 -0800 | [diff] [blame] | 14 | #include "GrGpuResourcePriv.h" |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 15 | #include "GrIndexBuffer.h" |
kkinnunen | cabe20c | 2015-06-01 01:37:26 -0700 | [diff] [blame] | 16 | #include "GrPathRendering.h" |
bsalomon | cb02b38 | 2015-08-12 11:14:50 -0700 | [diff] [blame] | 17 | #include "GrPipeline.h" |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 18 | #include "GrResourceCache.h" |
egdaniel | ec00d94 | 2015-09-14 12:56:10 -0700 | [diff] [blame] | 19 | #include "GrResourceProvider.h" |
bsalomon | 6bc1b5f | 2015-02-23 09:06:38 -0800 | [diff] [blame] | 20 | #include "GrRenderTargetPriv.h" |
egdaniel | 8dc7c3a | 2015-04-16 11:22:42 -0700 | [diff] [blame] | 21 | #include "GrStencilAttachment.h" |
egdaniel | 6d901da | 2015-07-30 12:02:15 -0700 | [diff] [blame] | 22 | #include "GrSurfacePriv.h" |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 23 | #include "GrVertexBuffer.h" |
bsalomon | cb8979d | 2015-05-05 09:51:38 -0700 | [diff] [blame] | 24 | #include "GrVertices.h" |
| 25 | |
| 26 | GrVertices& GrVertices::operator =(const GrVertices& di) { |
| 27 | fPrimitiveType = di.fPrimitiveType; |
| 28 | fStartVertex = di.fStartVertex; |
| 29 | fStartIndex = di.fStartIndex; |
| 30 | fVertexCount = di.fVertexCount; |
| 31 | fIndexCount = di.fIndexCount; |
| 32 | |
| 33 | fInstanceCount = di.fInstanceCount; |
| 34 | fVerticesPerInstance = di.fVerticesPerInstance; |
| 35 | fIndicesPerInstance = di.fIndicesPerInstance; |
bsalomon | e64eb57 | 2015-05-07 11:35:55 -0700 | [diff] [blame] | 36 | fMaxInstancesPerDraw = di.fMaxInstancesPerDraw; |
bsalomon | cb8979d | 2015-05-05 09:51:38 -0700 | [diff] [blame] | 37 | |
| 38 | fVertexBuffer.reset(di.vertexBuffer()); |
| 39 | fIndexBuffer.reset(di.indexBuffer()); |
| 40 | |
| 41 | return *this; |
| 42 | } |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 43 | |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 44 | //////////////////////////////////////////////////////////////////////////////// |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 45 | |
bsalomon@google.com | 6e4e650 | 2013-02-25 20:12:45 +0000 | [diff] [blame] | 46 | GrGpu::GrGpu(GrContext* context) |
joshualitt | 3322fa4 | 2014-11-07 08:48:51 -0800 | [diff] [blame] | 47 | : fResetTimestamp(kExpiredTimestamp+1) |
bsalomon@google.com | 0a208a1 | 2013-06-28 18:57:35 +0000 | [diff] [blame] | 48 | , fResetBits(kAll_GrBackendState) |
joshualitt | 3322fa4 | 2014-11-07 08:48:51 -0800 | [diff] [blame] | 49 | , fContext(context) { |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 50 | } |
| 51 | |
bsalomon | ed0bcad | 2015-05-04 10:36:42 -0700 | [diff] [blame] | 52 | GrGpu::~GrGpu() {} |
bsalomon | 1d89ddc | 2014-08-19 14:20:58 -0700 | [diff] [blame] | 53 | |
robertphillips | e337130 | 2014-09-17 06:01:06 -0700 | [diff] [blame] | 54 | void GrGpu::contextAbandoned() {} |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 55 | |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 56 | //////////////////////////////////////////////////////////////////////////////// |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 57 | |
bsalomon | 045802d | 2015-10-20 07:58:01 -0700 | [diff] [blame] | 58 | bool GrGpu::makeCopyForTextureParams(int width, int height, const GrTextureParams& textureParams, |
| 59 | GrTextureParamsAdjuster::CopyParams* copyParams) const { |
bsalomon | 045802d | 2015-10-20 07:58:01 -0700 | [diff] [blame] | 60 | const GrCaps& caps = *this->caps(); |
| 61 | if (textureParams.isTiled() && !caps.npotTextureTileSupport() && |
| 62 | (!SkIsPow2(width) || !SkIsPow2(height))) { |
bsalomon | 100b8f8 | 2015-10-28 08:37:44 -0700 | [diff] [blame^] | 63 | copyParams->fWidth = GrNextPow2(width); |
| 64 | copyParams->fHeight = GrNextPow2(height); |
bsalomon | 045802d | 2015-10-20 07:58:01 -0700 | [diff] [blame] | 65 | switch (textureParams.filterMode()) { |
| 66 | case GrTextureParams::kNone_FilterMode: |
| 67 | copyParams->fFilter = GrTextureParams::kNone_FilterMode; |
| 68 | break; |
| 69 | case GrTextureParams::kBilerp_FilterMode: |
| 70 | case GrTextureParams::kMipMap_FilterMode: |
| 71 | // We are only ever scaling up so no reason to ever indicate kMipMap. |
| 72 | copyParams->fFilter = GrTextureParams::kBilerp_FilterMode; |
| 73 | break; |
| 74 | } |
bsalomon | 100b8f8 | 2015-10-28 08:37:44 -0700 | [diff] [blame^] | 75 | return true; |
bsalomon | 045802d | 2015-10-20 07:58:01 -0700 | [diff] [blame] | 76 | } |
bsalomon | 100b8f8 | 2015-10-28 08:37:44 -0700 | [diff] [blame^] | 77 | return false; |
bsalomon | 045802d | 2015-10-20 07:58:01 -0700 | [diff] [blame] | 78 | } |
| 79 | |
egdaniel | cf614fd | 2015-04-22 13:58:58 -0700 | [diff] [blame] | 80 | static GrSurfaceOrigin resolve_origin(GrSurfaceOrigin origin, bool renderTarget) { |
egdaniel | b0e1be2 | 2015-04-22 13:27:39 -0700 | [diff] [blame] | 81 | // By default, GrRenderTargets are GL's normal orientation so that they |
| 82 | // can be drawn to by the outside world without the client having |
| 83 | // to render upside down. |
| 84 | if (kDefault_GrSurfaceOrigin == origin) { |
| 85 | return renderTarget ? kBottomLeft_GrSurfaceOrigin : kTopLeft_GrSurfaceOrigin; |
| 86 | } else { |
| 87 | return origin; |
| 88 | } |
| 89 | } |
| 90 | |
egdaniel | b0e1be2 | 2015-04-22 13:27:39 -0700 | [diff] [blame] | 91 | GrTexture* GrGpu::createTexture(const GrSurfaceDesc& origDesc, bool budgeted, |
bsalomon@google.com | a7f84e1 | 2011-03-10 14:13:19 +0000 | [diff] [blame] | 92 | const void* srcData, size_t rowBytes) { |
egdaniel | b0e1be2 | 2015-04-22 13:27:39 -0700 | [diff] [blame] | 93 | GrSurfaceDesc desc = origDesc; |
| 94 | |
krajcevski | 9c0e629 | 2014-06-02 07:38:14 -0700 | [diff] [blame] | 95 | if (!this->caps()->isConfigTexturable(desc.fConfig)) { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 96 | return nullptr; |
robertphillips@google.com | d3eb336 | 2012-10-31 13:56:35 +0000 | [diff] [blame] | 97 | } |
krajcevski | 9c0e629 | 2014-06-02 07:38:14 -0700 | [diff] [blame] | 98 | |
bsalomon | db558dd | 2015-01-23 13:19:00 -0800 | [diff] [blame] | 99 | bool isRT = SkToBool(desc.fFlags & kRenderTarget_GrSurfaceFlag); |
| 100 | if (isRT && !this->caps()->isConfigRenderable(desc.fConfig, desc.fSampleCnt > 0)) { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 101 | return nullptr; |
commit-bot@chromium.org | 6b7938f | 2013-10-15 14:18:16 +0000 | [diff] [blame] | 102 | } |
robertphillips@google.com | d3eb336 | 2012-10-31 13:56:35 +0000 | [diff] [blame] | 103 | |
robertphillips | 6e83ac7 | 2015-08-13 05:19:14 -0700 | [diff] [blame] | 104 | // We currently do not support multisampled textures |
egdaniel | 8c9b6f1 | 2015-05-12 13:36:30 -0700 | [diff] [blame] | 105 | if (!isRT && desc.fSampleCnt > 0) { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 106 | return nullptr; |
egdaniel | 8c9b6f1 | 2015-05-12 13:36:30 -0700 | [diff] [blame] | 107 | } |
| 108 | |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 109 | GrTexture *tex = nullptr; |
egdaniel | b0e1be2 | 2015-04-22 13:27:39 -0700 | [diff] [blame] | 110 | |
| 111 | if (isRT) { |
| 112 | int maxRTSize = this->caps()->maxRenderTargetSize(); |
| 113 | if (desc.fWidth > maxRTSize || desc.fHeight > maxRTSize) { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 114 | return nullptr; |
egdaniel | b0e1be2 | 2015-04-22 13:27:39 -0700 | [diff] [blame] | 115 | } |
| 116 | } else { |
| 117 | int maxSize = this->caps()->maxTextureSize(); |
| 118 | if (desc.fWidth > maxSize || desc.fHeight > maxSize) { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 119 | return nullptr; |
egdaniel | b0e1be2 | 2015-04-22 13:27:39 -0700 | [diff] [blame] | 120 | } |
| 121 | } |
| 122 | |
| 123 | GrGpuResource::LifeCycle lifeCycle = budgeted ? GrGpuResource::kCached_LifeCycle : |
| 124 | GrGpuResource::kUncached_LifeCycle; |
| 125 | |
| 126 | desc.fSampleCnt = SkTMin(desc.fSampleCnt, this->caps()->maxSampleCount()); |
| 127 | // Attempt to catch un- or wrongly initialized sample counts; |
| 128 | SkASSERT(desc.fSampleCnt >= 0 && desc.fSampleCnt <= 64); |
| 129 | |
| 130 | desc.fOrigin = resolve_origin(desc.fOrigin, isRT); |
| 131 | |
krajcevski | 9c0e629 | 2014-06-02 07:38:14 -0700 | [diff] [blame] | 132 | if (GrPixelConfigIsCompressed(desc.fConfig)) { |
| 133 | // We shouldn't be rendering into this |
egdaniel | b0e1be2 | 2015-04-22 13:27:39 -0700 | [diff] [blame] | 134 | SkASSERT(!isRT); |
| 135 | SkASSERT(0 == desc.fSampleCnt); |
krajcevski | 9c0e629 | 2014-06-02 07:38:14 -0700 | [diff] [blame] | 136 | |
| 137 | if (!this->caps()->npotTextureTileSupport() && |
tfarina | f9dae78 | 2014-06-06 06:35:28 -0700 | [diff] [blame] | 138 | (!SkIsPow2(desc.fWidth) || !SkIsPow2(desc.fHeight))) { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 139 | return nullptr; |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 140 | } |
tfarina | f9dae78 | 2014-06-06 06:35:28 -0700 | [diff] [blame] | 141 | |
krajcevski | 9c0e629 | 2014-06-02 07:38:14 -0700 | [diff] [blame] | 142 | this->handleDirtyContext(); |
egdaniel | b0e1be2 | 2015-04-22 13:27:39 -0700 | [diff] [blame] | 143 | tex = this->onCreateCompressedTexture(desc, lifeCycle, srcData); |
krajcevski | 9c0e629 | 2014-06-02 07:38:14 -0700 | [diff] [blame] | 144 | } else { |
| 145 | this->handleDirtyContext(); |
egdaniel | b0e1be2 | 2015-04-22 13:27:39 -0700 | [diff] [blame] | 146 | tex = this->onCreateTexture(desc, lifeCycle, srcData, rowBytes); |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 147 | } |
bsalomon | db558dd | 2015-01-23 13:19:00 -0800 | [diff] [blame] | 148 | if (!this->caps()->reuseScratchTextures() && !isRT) { |
bsalomon | 3582d3e | 2015-02-13 14:20:05 -0800 | [diff] [blame] | 149 | tex->resourcePriv().removeScratchKey(); |
bsalomon | db558dd | 2015-01-23 13:19:00 -0800 | [diff] [blame] | 150 | } |
bsalomon | b12ea41 | 2015-02-02 21:19:50 -0800 | [diff] [blame] | 151 | if (tex) { |
| 152 | fStats.incTextureCreates(); |
| 153 | if (srcData) { |
| 154 | fStats.incTextureUploads(); |
| 155 | } |
| 156 | } |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 157 | return tex; |
| 158 | } |
| 159 | |
bsalomon | 6dc6f5f | 2015-06-18 09:12:16 -0700 | [diff] [blame] | 160 | GrTexture* GrGpu::wrapBackendTexture(const GrBackendTextureDesc& desc, GrWrapOwnership ownership) { |
bsalomon@google.com | e269f21 | 2011-11-07 13:29:52 +0000 | [diff] [blame] | 161 | this->handleDirtyContext(); |
bsalomon | 6dc6f5f | 2015-06-18 09:12:16 -0700 | [diff] [blame] | 162 | GrTexture* tex = this->onWrapBackendTexture(desc, ownership); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 163 | if (nullptr == tex) { |
| 164 | return nullptr; |
bsalomon@google.com | a14dd6d | 2012-01-03 21:08:12 +0000 | [diff] [blame] | 165 | } |
bsalomon@google.com | e269f21 | 2011-11-07 13:29:52 +0000 | [diff] [blame] | 166 | // TODO: defer this and attach dynamically |
| 167 | GrRenderTarget* tgt = tex->asRenderTarget(); |
egdaniel | ec00d94 | 2015-09-14 12:56:10 -0700 | [diff] [blame] | 168 | if (tgt && !fContext->resourceProvider()->attachStencilAttachment(tgt)) { |
bsalomon@google.com | e269f21 | 2011-11-07 13:29:52 +0000 | [diff] [blame] | 169 | tex->unref(); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 170 | return nullptr; |
bsalomon@google.com | e269f21 | 2011-11-07 13:29:52 +0000 | [diff] [blame] | 171 | } else { |
| 172 | return tex; |
| 173 | } |
| 174 | } |
| 175 | |
bsalomon | 6dc6f5f | 2015-06-18 09:12:16 -0700 | [diff] [blame] | 176 | GrRenderTarget* GrGpu::wrapBackendRenderTarget(const GrBackendRenderTargetDesc& desc, |
| 177 | GrWrapOwnership ownership) { |
bsalomon@google.com | e269f21 | 2011-11-07 13:29:52 +0000 | [diff] [blame] | 178 | this->handleDirtyContext(); |
bsalomon | 6dc6f5f | 2015-06-18 09:12:16 -0700 | [diff] [blame] | 179 | return this->onWrapBackendRenderTarget(desc, ownership); |
bsalomon@google.com | e269f21 | 2011-11-07 13:29:52 +0000 | [diff] [blame] | 180 | } |
| 181 | |
robertphillips@google.com | adacc70 | 2013-10-14 21:53:24 +0000 | [diff] [blame] | 182 | GrVertexBuffer* GrGpu::createVertexBuffer(size_t size, bool dynamic) { |
bsalomon@google.com | a7f84e1 | 2011-03-10 14:13:19 +0000 | [diff] [blame] | 183 | this->handleDirtyContext(); |
robertphillips | 1b8e1b5 | 2015-06-24 06:54:10 -0700 | [diff] [blame] | 184 | GrVertexBuffer* vb = this->onCreateVertexBuffer(size, dynamic); |
| 185 | if (!this->caps()->reuseScratchBuffers()) { |
| 186 | vb->resourcePriv().removeScratchKey(); |
| 187 | } |
| 188 | return vb; |
bsalomon@google.com | a7f84e1 | 2011-03-10 14:13:19 +0000 | [diff] [blame] | 189 | } |
| 190 | |
robertphillips@google.com | adacc70 | 2013-10-14 21:53:24 +0000 | [diff] [blame] | 191 | GrIndexBuffer* GrGpu::createIndexBuffer(size_t size, bool dynamic) { |
bsalomon@google.com | a7f84e1 | 2011-03-10 14:13:19 +0000 | [diff] [blame] | 192 | this->handleDirtyContext(); |
robertphillips | 1b8e1b5 | 2015-06-24 06:54:10 -0700 | [diff] [blame] | 193 | GrIndexBuffer* ib = this->onCreateIndexBuffer(size, dynamic); |
| 194 | if (!this->caps()->reuseScratchBuffers()) { |
| 195 | ib->resourcePriv().removeScratchKey(); |
| 196 | } |
| 197 | return ib; |
bsalomon@google.com | a7f84e1 | 2011-03-10 14:13:19 +0000 | [diff] [blame] | 198 | } |
| 199 | |
egdaniel | 51c8d40 | 2015-08-06 10:54:13 -0700 | [diff] [blame] | 200 | void GrGpu::clear(const SkIRect& rect, |
joshualitt | 3322fa4 | 2014-11-07 08:48:51 -0800 | [diff] [blame] | 201 | GrColor color, |
joshualitt | 3322fa4 | 2014-11-07 08:48:51 -0800 | [diff] [blame] | 202 | GrRenderTarget* renderTarget) { |
bsalomon | 89c6298 | 2014-11-03 12:08:42 -0800 | [diff] [blame] | 203 | SkASSERT(renderTarget); |
egdaniel | 51c8d40 | 2015-08-06 10:54:13 -0700 | [diff] [blame] | 204 | SkASSERT(SkIRect::MakeWH(renderTarget->width(), renderTarget->height()).contains(rect)); |
bsalomon@google.com | a7f84e1 | 2011-03-10 14:13:19 +0000 | [diff] [blame] | 205 | this->handleDirtyContext(); |
egdaniel | 51c8d40 | 2015-08-06 10:54:13 -0700 | [diff] [blame] | 206 | this->onClear(renderTarget, rect, color); |
bsalomon@google.com | a7f84e1 | 2011-03-10 14:13:19 +0000 | [diff] [blame] | 207 | } |
| 208 | |
joshualitt | 6db519c | 2014-10-29 08:48:18 -0700 | [diff] [blame] | 209 | void GrGpu::clearStencilClip(const SkIRect& rect, |
| 210 | bool insideClip, |
| 211 | GrRenderTarget* renderTarget) { |
joshualitt | d53a827 | 2014-11-10 16:03:14 -0800 | [diff] [blame] | 212 | SkASSERT(renderTarget); |
joshualitt | 6db519c | 2014-10-29 08:48:18 -0700 | [diff] [blame] | 213 | this->handleDirtyContext(); |
| 214 | this->onClearStencilClip(renderTarget, rect, insideClip); |
| 215 | } |
| 216 | |
joshualitt | 1cbdcde | 2015-08-21 11:53:29 -0700 | [diff] [blame] | 217 | bool GrGpu::copySurface(GrSurface* dst, |
| 218 | GrSurface* src, |
| 219 | const SkIRect& srcRect, |
| 220 | const SkIPoint& dstPoint) { |
| 221 | SkASSERT(dst && src); |
| 222 | this->handleDirtyContext(); |
| 223 | return this->onCopySurface(dst, src, srcRect, dstPoint); |
| 224 | } |
| 225 | |
bsalomon | f067451 | 2015-07-28 13:26:15 -0700 | [diff] [blame] | 226 | bool GrGpu::getReadPixelsInfo(GrSurface* srcSurface, int width, int height, size_t rowBytes, |
| 227 | GrPixelConfig readConfig, DrawPreference* drawPreference, |
| 228 | ReadPixelTempDrawInfo* tempDrawInfo) { |
| 229 | SkASSERT(drawPreference); |
| 230 | SkASSERT(tempDrawInfo); |
| 231 | SkASSERT(kGpuPrefersDraw_DrawPreference != *drawPreference); |
| 232 | |
egdaniel | 6d901da | 2015-07-30 12:02:15 -0700 | [diff] [blame] | 233 | // We currently do not support reading into a compressed buffer |
| 234 | if (GrPixelConfigIsCompressed(readConfig)) { |
| 235 | return false; |
| 236 | } |
| 237 | |
bsalomon | f067451 | 2015-07-28 13:26:15 -0700 | [diff] [blame] | 238 | if (!this->onGetReadPixelsInfo(srcSurface, width, height, rowBytes, readConfig, drawPreference, |
| 239 | tempDrawInfo)) { |
| 240 | return false; |
| 241 | } |
| 242 | |
| 243 | // Check to see if we're going to request that the caller draw when drawing is not possible. |
| 244 | if (!srcSurface->asTexture() || |
| 245 | !this->caps()->isConfigRenderable(tempDrawInfo->fTempSurfaceDesc.fConfig, false)) { |
| 246 | // If we don't have a fallback to a straight read then fail. |
| 247 | if (kRequireDraw_DrawPreference == *drawPreference) { |
| 248 | return false; |
| 249 | } |
| 250 | *drawPreference = kNoDraw_DrawPreference; |
| 251 | } |
| 252 | |
| 253 | return true; |
| 254 | } |
| 255 | bool GrGpu::getWritePixelsInfo(GrSurface* dstSurface, int width, int height, size_t rowBytes, |
| 256 | GrPixelConfig srcConfig, DrawPreference* drawPreference, |
| 257 | WritePixelTempDrawInfo* tempDrawInfo) { |
| 258 | SkASSERT(drawPreference); |
| 259 | SkASSERT(tempDrawInfo); |
| 260 | SkASSERT(kGpuPrefersDraw_DrawPreference != *drawPreference); |
| 261 | |
jvanverth | 2dc2994 | 2015-09-01 07:16:46 -0700 | [diff] [blame] | 262 | if (GrPixelConfigIsCompressed(dstSurface->desc().fConfig) && |
| 263 | dstSurface->desc().fConfig != srcConfig) { |
| 264 | return false; |
| 265 | } |
| 266 | |
bsalomon | f067451 | 2015-07-28 13:26:15 -0700 | [diff] [blame] | 267 | if (this->caps()->useDrawInsteadOfPartialRenderTargetWrite() && |
| 268 | SkToBool(dstSurface->asRenderTarget()) && |
| 269 | (width < dstSurface->width() || height < dstSurface->height())) { |
| 270 | ElevateDrawPreference(drawPreference, kRequireDraw_DrawPreference); |
| 271 | } |
| 272 | |
| 273 | if (!this->onGetWritePixelsInfo(dstSurface, width, height, rowBytes, srcConfig, drawPreference, |
| 274 | tempDrawInfo)) { |
| 275 | return false; |
| 276 | } |
| 277 | |
| 278 | // Check to see if we're going to request that the caller draw when drawing is not possible. |
| 279 | if (!dstSurface->asRenderTarget() || |
| 280 | !this->caps()->isConfigTexturable(tempDrawInfo->fTempSurfaceDesc.fConfig)) { |
| 281 | // If we don't have a fallback to a straight upload then fail. |
| 282 | if (kRequireDraw_DrawPreference == *drawPreference || |
| 283 | !this->caps()->isConfigTexturable(srcConfig)) { |
| 284 | return false; |
| 285 | } |
| 286 | *drawPreference = kNoDraw_DrawPreference; |
| 287 | } |
| 288 | return true; |
| 289 | } |
| 290 | |
bsalomon | 6cb3cbe | 2015-07-30 07:34:27 -0700 | [diff] [blame] | 291 | bool GrGpu::readPixels(GrSurface* surface, |
bsalomon@google.com | 669fdc4 | 2011-04-05 17:08:27 +0000 | [diff] [blame] | 292 | int left, int top, int width, int height, |
bsalomon@google.com | c698097 | 2011-11-02 19:57:21 +0000 | [diff] [blame] | 293 | GrPixelConfig config, void* buffer, |
senorblanco@chromium.org | 3cb406b | 2013-02-05 19:50:46 +0000 | [diff] [blame] | 294 | size_t rowBytes) { |
bsalomon@google.com | a7f84e1 | 2011-03-10 14:13:19 +0000 | [diff] [blame] | 295 | this->handleDirtyContext(); |
egdaniel | 6d901da | 2015-07-30 12:02:15 -0700 | [diff] [blame] | 296 | |
| 297 | // We cannot read pixels into a compressed buffer |
| 298 | if (GrPixelConfigIsCompressed(config)) { |
| 299 | return false; |
| 300 | } |
| 301 | |
| 302 | size_t bpp = GrBytesPerPixel(config); |
| 303 | if (!GrSurfacePriv::AdjustReadPixelParams(surface->width(), surface->height(), bpp, |
| 304 | &left, &top, &width, &height, |
| 305 | &buffer, |
| 306 | &rowBytes)) { |
| 307 | return false; |
| 308 | } |
| 309 | |
| 310 | return this->onReadPixels(surface, |
| 311 | left, top, width, height, |
| 312 | config, buffer, |
| 313 | rowBytes); |
bsalomon@google.com | a7f84e1 | 2011-03-10 14:13:19 +0000 | [diff] [blame] | 314 | } |
| 315 | |
bsalomon | 6cb3cbe | 2015-07-30 07:34:27 -0700 | [diff] [blame] | 316 | bool GrGpu::writePixels(GrSurface* surface, |
| 317 | int left, int top, int width, int height, |
| 318 | GrPixelConfig config, const void* buffer, |
| 319 | size_t rowBytes) { |
jvanverth | 2dc2994 | 2015-09-01 07:16:46 -0700 | [diff] [blame] | 320 | if (!buffer) { |
| 321 | return false; |
| 322 | } |
| 323 | |
bsalomon@google.com | 6f37951 | 2011-11-16 20:36:03 +0000 | [diff] [blame] | 324 | this->handleDirtyContext(); |
bsalomon | 6cb3cbe | 2015-07-30 07:34:27 -0700 | [diff] [blame] | 325 | if (this->onWritePixels(surface, left, top, width, height, config, buffer, rowBytes)) { |
bsalomon | b12ea41 | 2015-02-02 21:19:50 -0800 | [diff] [blame] | 326 | fStats.incTextureUploads(); |
| 327 | return true; |
| 328 | } |
| 329 | return false; |
bsalomon@google.com | 6f37951 | 2011-11-16 20:36:03 +0000 | [diff] [blame] | 330 | } |
| 331 | |
bsalomon@google.com | 75f9f25 | 2012-01-31 13:35:56 +0000 | [diff] [blame] | 332 | void GrGpu::resolveRenderTarget(GrRenderTarget* target) { |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 333 | SkASSERT(target); |
bsalomon@google.com | 75f9f25 | 2012-01-31 13:35:56 +0000 | [diff] [blame] | 334 | this->handleDirtyContext(); |
| 335 | this->onResolveRenderTarget(target); |
| 336 | } |
| 337 | |
bsalomon@google.com | a7f84e1 | 2011-03-10 14:13:19 +0000 | [diff] [blame] | 338 | //////////////////////////////////////////////////////////////////////////////// |
| 339 | |
bsalomon | cb8979d | 2015-05-05 09:51:38 -0700 | [diff] [blame] | 340 | void GrGpu::draw(const DrawArgs& args, const GrVertices& vertices) { |
bsalomon@google.com | a7f84e1 | 2011-03-10 14:13:19 +0000 | [diff] [blame] | 341 | this->handleDirtyContext(); |
bsalomon | cb02b38 | 2015-08-12 11:14:50 -0700 | [diff] [blame] | 342 | if (GrXferBarrierType barrierType = args.fPipeline->xferBarrierType(*this->caps())) { |
| 343 | this->xferBarrier(args.fPipeline->getRenderTarget(), barrierType); |
| 344 | } |
| 345 | |
bsalomon | e64eb57 | 2015-05-07 11:35:55 -0700 | [diff] [blame] | 346 | GrVertices::Iterator iter; |
| 347 | const GrNonInstancedVertices* verts = iter.init(vertices); |
| 348 | do { |
| 349 | this->onDraw(args, *verts); |
joshualitt | 336cda3 | 2015-09-09 08:29:47 -0700 | [diff] [blame] | 350 | fStats.incNumDraws(); |
bsalomon | e64eb57 | 2015-05-07 11:35:55 -0700 | [diff] [blame] | 351 | } while ((verts = iter.next())); |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 352 | } |