blob: 4e0464a4ce6cb74f0e2c734b5fef8b1f3685e391 [file] [log] [blame]
reed@google.comac10a2d2010-12-22 21:39:39 +00001/*
epoger@google.comec3ed6a2011-07-28 14:26:00 +00002 * Copyright 2010 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.
reed@google.comac10a2d2010-12-22 21:39:39 +00006 */
7
epoger@google.comec3ed6a2011-07-28 14:26:00 +00008
reed@google.comac10a2d2010-12-22 21:39:39 +00009#include "GrGpu.h"
bsalomon@google.com558a75b2011-08-08 17:01:14 +000010
bsalomoneb1cb5c2015-05-22 08:01:09 -070011#include "GrCaps.h"
bsalomon@google.com558a75b2011-08-08 17:01:14 +000012#include "GrContext.h"
bsalomon3582d3e2015-02-13 14:20:05 -080013#include "GrGpuResourcePriv.h"
reed@google.comac10a2d2010-12-22 21:39:39 +000014#include "GrIndexBuffer.h"
kkinnunencabe20c2015-06-01 01:37:26 -070015#include "GrPathRendering.h"
bsalomoncb02b382015-08-12 11:14:50 -070016#include "GrPipeline.h"
bsalomon0ea80f42015-02-11 10:49:59 -080017#include "GrResourceCache.h"
egdanielec00d942015-09-14 12:56:10 -070018#include "GrResourceProvider.h"
bsalomon6bc1b5f2015-02-23 09:06:38 -080019#include "GrRenderTargetPriv.h"
egdaniel8dc7c3a2015-04-16 11:22:42 -070020#include "GrStencilAttachment.h"
egdaniel6d901da2015-07-30 12:02:15 -070021#include "GrSurfacePriv.h"
jvanverth73063dc2015-12-03 09:15:47 -080022#include "GrTransferBuffer.h"
bsalomon@google.com81c3f8d2011-08-03 15:18:33 +000023#include "GrVertexBuffer.h"
bsalomoncb8979d2015-05-05 09:51:38 -070024#include "GrVertices.h"
cblume55f2d2d2016-02-26 13:20:48 -080025#include "SkTypes.h"
bsalomoncb8979d2015-05-05 09:51:38 -070026
27GrVertices& GrVertices::operator =(const GrVertices& di) {
28 fPrimitiveType = di.fPrimitiveType;
29 fStartVertex = di.fStartVertex;
30 fStartIndex = di.fStartIndex;
31 fVertexCount = di.fVertexCount;
32 fIndexCount = di.fIndexCount;
33
34 fInstanceCount = di.fInstanceCount;
35 fVerticesPerInstance = di.fVerticesPerInstance;
36 fIndicesPerInstance = di.fIndicesPerInstance;
bsalomone64eb572015-05-07 11:35:55 -070037 fMaxInstancesPerDraw = di.fMaxInstancesPerDraw;
bsalomoncb8979d2015-05-05 09:51:38 -070038
39 fVertexBuffer.reset(di.vertexBuffer());
40 fIndexBuffer.reset(di.indexBuffer());
41
42 return *this;
43}
bsalomon@google.com1c13c962011-02-14 16:51:21 +000044
bsalomon@google.comd302f142011-03-03 13:54:13 +000045////////////////////////////////////////////////////////////////////////////////
reed@google.comac10a2d2010-12-22 21:39:39 +000046
bsalomon@google.com6e4e6502013-02-25 20:12:45 +000047GrGpu::GrGpu(GrContext* context)
joshualitt3322fa42014-11-07 08:48:51 -080048 : fResetTimestamp(kExpiredTimestamp+1)
bsalomon@google.com0a208a12013-06-28 18:57:35 +000049 , fResetBits(kAll_GrBackendState)
joshualitt3322fa42014-11-07 08:48:51 -080050 , fContext(context) {
reed@google.comac10a2d2010-12-22 21:39:39 +000051}
52
bsalomoned0bcad2015-05-04 10:36:42 -070053GrGpu::~GrGpu() {}
bsalomon1d89ddc2014-08-19 14:20:58 -070054
robertphillipse3371302014-09-17 06:01:06 -070055void GrGpu::contextAbandoned() {}
reed@google.comac10a2d2010-12-22 21:39:39 +000056
bsalomon@google.comd302f142011-03-03 13:54:13 +000057////////////////////////////////////////////////////////////////////////////////
reed@google.comac10a2d2010-12-22 21:39:39 +000058
bsalomon045802d2015-10-20 07:58:01 -070059bool GrGpu::makeCopyForTextureParams(int width, int height, const GrTextureParams& textureParams,
bsalomon89fe56b2015-10-29 10:49:28 -070060 GrTextureProducer::CopyParams* copyParams) const {
bsalomon045802d2015-10-20 07:58:01 -070061 const GrCaps& caps = *this->caps();
62 if (textureParams.isTiled() && !caps.npotTextureTileSupport() &&
63 (!SkIsPow2(width) || !SkIsPow2(height))) {
bsalomon100b8f82015-10-28 08:37:44 -070064 copyParams->fWidth = GrNextPow2(width);
65 copyParams->fHeight = GrNextPow2(height);
bsalomon045802d2015-10-20 07:58:01 -070066 switch (textureParams.filterMode()) {
67 case GrTextureParams::kNone_FilterMode:
68 copyParams->fFilter = GrTextureParams::kNone_FilterMode;
69 break;
70 case GrTextureParams::kBilerp_FilterMode:
71 case GrTextureParams::kMipMap_FilterMode:
72 // We are only ever scaling up so no reason to ever indicate kMipMap.
73 copyParams->fFilter = GrTextureParams::kBilerp_FilterMode;
74 break;
75 }
bsalomon100b8f82015-10-28 08:37:44 -070076 return true;
bsalomon045802d2015-10-20 07:58:01 -070077 }
bsalomon100b8f82015-10-28 08:37:44 -070078 return false;
bsalomon045802d2015-10-20 07:58:01 -070079}
80
egdanielcf614fd2015-04-22 13:58:58 -070081static GrSurfaceOrigin resolve_origin(GrSurfaceOrigin origin, bool renderTarget) {
egdanielb0e1be22015-04-22 13:27:39 -070082 // By default, GrRenderTargets are GL's normal orientation so that they
83 // can be drawn to by the outside world without the client having
84 // to render upside down.
85 if (kDefault_GrSurfaceOrigin == origin) {
86 return renderTarget ? kBottomLeft_GrSurfaceOrigin : kTopLeft_GrSurfaceOrigin;
87 } else {
88 return origin;
89 }
90}
91
cblume55f2d2d2016-02-26 13:20:48 -080092/**
93 * Prior to creating a texture, make sure the type of texture being created is
94 * supported by calling check_texture_creation_params.
95 *
96 * @param caps The capabilities of the GL device.
97 * @param desc The descriptor of the texture to create.
98 * @param isRT Indicates if the texture can be a render target.
99 */
100static bool check_texture_creation_params(const GrCaps& caps, const GrSurfaceDesc& desc,
101 bool* isRT) {
102 if (!caps.isConfigTexturable(desc.fConfig)) {
103 return false;
robertphillips@google.comd3eb3362012-10-31 13:56:35 +0000104 }
krajcevski9c0e6292014-06-02 07:38:14 -0700105
cblume55f2d2d2016-02-26 13:20:48 -0800106 *isRT = SkToBool(desc.fFlags & kRenderTarget_GrSurfaceFlag);
107 if (*isRT && !caps.isConfigRenderable(desc.fConfig, desc.fSampleCnt > 0)) {
108 return false;
commit-bot@chromium.org6b7938f2013-10-15 14:18:16 +0000109 }
robertphillips@google.comd3eb3362012-10-31 13:56:35 +0000110
robertphillips6e83ac72015-08-13 05:19:14 -0700111 // We currently do not support multisampled textures
cblume55f2d2d2016-02-26 13:20:48 -0800112 if (!*isRT && desc.fSampleCnt > 0) {
113 return false;
114 }
115
116 if (*isRT) {
117 int maxRTSize = caps.maxRenderTargetSize();
118 if (desc.fWidth > maxRTSize || desc.fHeight > maxRTSize) {
119 return false;
120 }
121 } else {
122 int maxSize = caps.maxTextureSize();
123 if (desc.fWidth > maxSize || desc.fHeight > maxSize) {
124 return false;
125 }
126 }
127 return true;
128}
129
130GrTexture* GrGpu::createTexture(const GrSurfaceDesc& origDesc, SkBudgeted budgeted,
131 const SkTArray<GrMipLevel>& texels) {
132 GrSurfaceDesc desc = origDesc;
133
134 const GrCaps* caps = this->caps();
135 bool isRT = false;
136 bool textureCreationParamsValid = check_texture_creation_params(*caps, desc, &isRT);
137 if (!textureCreationParamsValid) {
halcanary96fcdcc2015-08-27 07:41:13 -0700138 return nullptr;
egdaniel8c9b6f12015-05-12 13:36:30 -0700139 }
140
cblume55f2d2d2016-02-26 13:20:48 -0800141 desc.fSampleCnt = SkTMin(desc.fSampleCnt, caps->maxSampleCount());
142 // Attempt to catch un- or wrongly intialized sample counts;
egdanielb0e1be22015-04-22 13:27:39 -0700143 SkASSERT(desc.fSampleCnt >= 0 && desc.fSampleCnt <= 64);
144
145 desc.fOrigin = resolve_origin(desc.fOrigin, isRT);
146
cblume55f2d2d2016-02-26 13:20:48 -0800147 GrTexture* tex = nullptr;
148 GrGpuResource::LifeCycle lifeCycle = SkBudgeted::kYes == budgeted ?
149 GrGpuResource::kCached_LifeCycle :
150 GrGpuResource::kUncached_LifeCycle;
151
krajcevski9c0e6292014-06-02 07:38:14 -0700152 if (GrPixelConfigIsCompressed(desc.fConfig)) {
153 // We shouldn't be rendering into this
egdanielb0e1be22015-04-22 13:27:39 -0700154 SkASSERT(!isRT);
155 SkASSERT(0 == desc.fSampleCnt);
krajcevski9c0e6292014-06-02 07:38:14 -0700156
cblume55f2d2d2016-02-26 13:20:48 -0800157 if (!caps->npotTextureTileSupport() &&
tfarinaf9dae782014-06-06 06:35:28 -0700158 (!SkIsPow2(desc.fWidth) || !SkIsPow2(desc.fHeight))) {
halcanary96fcdcc2015-08-27 07:41:13 -0700159 return nullptr;
bsalomon@google.com81c3f8d2011-08-03 15:18:33 +0000160 }
tfarinaf9dae782014-06-06 06:35:28 -0700161
krajcevski9c0e6292014-06-02 07:38:14 -0700162 this->handleDirtyContext();
cblume55f2d2d2016-02-26 13:20:48 -0800163 tex = this->onCreateCompressedTexture(desc, lifeCycle, texels);
krajcevski9c0e6292014-06-02 07:38:14 -0700164 } else {
165 this->handleDirtyContext();
cblume55f2d2d2016-02-26 13:20:48 -0800166 tex = this->onCreateTexture(desc, lifeCycle, texels);
bsalomondb558dd2015-01-23 13:19:00 -0800167 }
bsalomonb12ea412015-02-02 21:19:50 -0800168 if (tex) {
cblume55f2d2d2016-02-26 13:20:48 -0800169 if (!caps->reuseScratchTextures() && !isRT) {
170 tex->resourcePriv().removeScratchKey();
171 }
bsalomonb12ea412015-02-02 21:19:50 -0800172 fStats.incTextureCreates();
cblume55f2d2d2016-02-26 13:20:48 -0800173 if (!texels.empty()) {
174 if (texels[0].fPixels) {
175 fStats.incTextureUploads();
176 }
bsalomonb12ea412015-02-02 21:19:50 -0800177 }
178 }
bsalomon@google.com81c3f8d2011-08-03 15:18:33 +0000179 return tex;
180}
181
cblume55f2d2d2016-02-26 13:20:48 -0800182GrTexture* GrGpu::createTexture(const GrSurfaceDesc& desc, SkBudgeted budgeted,
183 const void* srcData, size_t rowBytes) {
184 GrMipLevel level;
185 level.fPixels = srcData;
186 level.fRowBytes = rowBytes;
187 SkSTArray<1, GrMipLevel> levels;
188 levels.push_back(level);
189
190 return this->createTexture(desc, budgeted, levels);
191}
192
bsalomon6dc6f5f2015-06-18 09:12:16 -0700193GrTexture* GrGpu::wrapBackendTexture(const GrBackendTextureDesc& desc, GrWrapOwnership ownership) {
bsalomon@google.come269f212011-11-07 13:29:52 +0000194 this->handleDirtyContext();
bsalomon5b30c6f2015-12-17 14:17:34 -0800195 if (!this->caps()->isConfigTexturable(desc.fConfig)) {
196 return nullptr;
197 }
198 if ((desc.fFlags & kRenderTarget_GrBackendTextureFlag) &&
199 !this->caps()->isConfigRenderable(desc.fConfig, desc.fSampleCnt > 0)) {
200 return nullptr;
201 }
ericrkf7b8b8a2016-02-24 14:49:51 -0800202 int maxSize = this->caps()->maxTextureSize();
203 if (desc.fWidth > maxSize || desc.fHeight > maxSize) {
204 return nullptr;
205 }
bsalomon6dc6f5f2015-06-18 09:12:16 -0700206 GrTexture* tex = this->onWrapBackendTexture(desc, ownership);
halcanary96fcdcc2015-08-27 07:41:13 -0700207 if (nullptr == tex) {
208 return nullptr;
bsalomon@google.coma14dd6d2012-01-03 21:08:12 +0000209 }
bsalomon@google.come269f212011-11-07 13:29:52 +0000210 // TODO: defer this and attach dynamically
211 GrRenderTarget* tgt = tex->asRenderTarget();
egdanielec00d942015-09-14 12:56:10 -0700212 if (tgt && !fContext->resourceProvider()->attachStencilAttachment(tgt)) {
bsalomon@google.come269f212011-11-07 13:29:52 +0000213 tex->unref();
halcanary96fcdcc2015-08-27 07:41:13 -0700214 return nullptr;
bsalomon@google.come269f212011-11-07 13:29:52 +0000215 } else {
216 return tex;
217 }
218}
219
bsalomon6dc6f5f2015-06-18 09:12:16 -0700220GrRenderTarget* GrGpu::wrapBackendRenderTarget(const GrBackendRenderTargetDesc& desc,
221 GrWrapOwnership ownership) {
bsalomon5b30c6f2015-12-17 14:17:34 -0800222 if (!this->caps()->isConfigRenderable(desc.fConfig, desc.fSampleCnt > 0)) {
223 return nullptr;
224 }
bsalomon@google.come269f212011-11-07 13:29:52 +0000225 this->handleDirtyContext();
bsalomon6dc6f5f2015-06-18 09:12:16 -0700226 return this->onWrapBackendRenderTarget(desc, ownership);
bsalomon@google.come269f212011-11-07 13:29:52 +0000227}
228
ericrkf7b8b8a2016-02-24 14:49:51 -0800229GrRenderTarget* GrGpu::wrapBackendTextureAsRenderTarget(const GrBackendTextureDesc& desc,
230 GrWrapOwnership ownership) {
231 this->handleDirtyContext();
232 if (!(desc.fFlags & kRenderTarget_GrBackendTextureFlag)) {
233 return nullptr;
234 }
235 if (!this->caps()->isConfigRenderable(desc.fConfig, desc.fSampleCnt > 0)) {
236 return nullptr;
237 }
238 int maxSize = this->caps()->maxTextureSize();
239 if (desc.fWidth > maxSize || desc.fHeight > maxSize) {
240 return nullptr;
241 }
242 return this->onWrapBackendTextureAsRenderTarget(desc, ownership);
243}
244
robertphillips@google.comadacc702013-10-14 21:53:24 +0000245GrVertexBuffer* GrGpu::createVertexBuffer(size_t size, bool dynamic) {
bsalomon@google.coma7f84e12011-03-10 14:13:19 +0000246 this->handleDirtyContext();
robertphillips1b8e1b52015-06-24 06:54:10 -0700247 GrVertexBuffer* vb = this->onCreateVertexBuffer(size, dynamic);
248 if (!this->caps()->reuseScratchBuffers()) {
249 vb->resourcePriv().removeScratchKey();
250 }
251 return vb;
bsalomon@google.coma7f84e12011-03-10 14:13:19 +0000252}
253
robertphillips@google.comadacc702013-10-14 21:53:24 +0000254GrIndexBuffer* GrGpu::createIndexBuffer(size_t size, bool dynamic) {
bsalomon@google.coma7f84e12011-03-10 14:13:19 +0000255 this->handleDirtyContext();
robertphillips1b8e1b52015-06-24 06:54:10 -0700256 GrIndexBuffer* ib = this->onCreateIndexBuffer(size, dynamic);
257 if (!this->caps()->reuseScratchBuffers()) {
258 ib->resourcePriv().removeScratchKey();
259 }
260 return ib;
bsalomon@google.coma7f84e12011-03-10 14:13:19 +0000261}
262
jvanverth73063dc2015-12-03 09:15:47 -0800263GrTransferBuffer* GrGpu::createTransferBuffer(size_t size, TransferType type) {
264 this->handleDirtyContext();
265 GrTransferBuffer* tb = this->onCreateTransferBuffer(size, type);
266 return tb;
267}
268
egdaniel51c8d402015-08-06 10:54:13 -0700269void GrGpu::clear(const SkIRect& rect,
joshualitt3322fa42014-11-07 08:48:51 -0800270 GrColor color,
joshualitt3322fa42014-11-07 08:48:51 -0800271 GrRenderTarget* renderTarget) {
bsalomon89c62982014-11-03 12:08:42 -0800272 SkASSERT(renderTarget);
egdaniel51c8d402015-08-06 10:54:13 -0700273 SkASSERT(SkIRect::MakeWH(renderTarget->width(), renderTarget->height()).contains(rect));
bsalomon@google.coma7f84e12011-03-10 14:13:19 +0000274 this->handleDirtyContext();
egdaniel51c8d402015-08-06 10:54:13 -0700275 this->onClear(renderTarget, rect, color);
bsalomon@google.coma7f84e12011-03-10 14:13:19 +0000276}
277
joshualitt6db519c2014-10-29 08:48:18 -0700278void GrGpu::clearStencilClip(const SkIRect& rect,
279 bool insideClip,
280 GrRenderTarget* renderTarget) {
joshualittd53a8272014-11-10 16:03:14 -0800281 SkASSERT(renderTarget);
joshualitt6db519c2014-10-29 08:48:18 -0700282 this->handleDirtyContext();
283 this->onClearStencilClip(renderTarget, rect, insideClip);
284}
285
joshualitt1cbdcde2015-08-21 11:53:29 -0700286bool GrGpu::copySurface(GrSurface* dst,
287 GrSurface* src,
288 const SkIRect& srcRect,
289 const SkIPoint& dstPoint) {
290 SkASSERT(dst && src);
291 this->handleDirtyContext();
292 return this->onCopySurface(dst, src, srcRect, dstPoint);
293}
294
bsalomonf0674512015-07-28 13:26:15 -0700295bool GrGpu::getReadPixelsInfo(GrSurface* srcSurface, int width, int height, size_t rowBytes,
296 GrPixelConfig readConfig, DrawPreference* drawPreference,
297 ReadPixelTempDrawInfo* tempDrawInfo) {
298 SkASSERT(drawPreference);
299 SkASSERT(tempDrawInfo);
300 SkASSERT(kGpuPrefersDraw_DrawPreference != *drawPreference);
301
egdaniel6d901da2015-07-30 12:02:15 -0700302 // We currently do not support reading into a compressed buffer
303 if (GrPixelConfigIsCompressed(readConfig)) {
304 return false;
305 }
306
bsalomonf0674512015-07-28 13:26:15 -0700307 if (!this->onGetReadPixelsInfo(srcSurface, width, height, rowBytes, readConfig, drawPreference,
308 tempDrawInfo)) {
309 return false;
310 }
311
312 // Check to see if we're going to request that the caller draw when drawing is not possible.
313 if (!srcSurface->asTexture() ||
314 !this->caps()->isConfigRenderable(tempDrawInfo->fTempSurfaceDesc.fConfig, false)) {
315 // If we don't have a fallback to a straight read then fail.
316 if (kRequireDraw_DrawPreference == *drawPreference) {
317 return false;
318 }
319 *drawPreference = kNoDraw_DrawPreference;
320 }
321
322 return true;
323}
cblumeed828002016-02-16 13:00:01 -0800324bool GrGpu::getWritePixelsInfo(GrSurface* dstSurface, int width, int height,
bsalomonf0674512015-07-28 13:26:15 -0700325 GrPixelConfig srcConfig, DrawPreference* drawPreference,
326 WritePixelTempDrawInfo* tempDrawInfo) {
327 SkASSERT(drawPreference);
328 SkASSERT(tempDrawInfo);
329 SkASSERT(kGpuPrefersDraw_DrawPreference != *drawPreference);
330
jvanverth2dc29942015-09-01 07:16:46 -0700331 if (GrPixelConfigIsCompressed(dstSurface->desc().fConfig) &&
332 dstSurface->desc().fConfig != srcConfig) {
333 return false;
334 }
335
bsalomonbabafcc2016-02-16 11:36:47 -0800336 if (SkToBool(dstSurface->asRenderTarget())) {
337 if (this->caps()->useDrawInsteadOfAllRenderTargetWrites()) {
338 ElevateDrawPreference(drawPreference, kRequireDraw_DrawPreference);
339 } else if (this->caps()->useDrawInsteadOfPartialRenderTargetWrite() &&
340 (width < dstSurface->width() || height < dstSurface->height())) {
341 ElevateDrawPreference(drawPreference, kRequireDraw_DrawPreference);
342 }
bsalomonf0674512015-07-28 13:26:15 -0700343 }
344
cblumeed828002016-02-16 13:00:01 -0800345 if (!this->onGetWritePixelsInfo(dstSurface, width, height, srcConfig, drawPreference,
bsalomonf0674512015-07-28 13:26:15 -0700346 tempDrawInfo)) {
347 return false;
348 }
349
350 // Check to see if we're going to request that the caller draw when drawing is not possible.
351 if (!dstSurface->asRenderTarget() ||
352 !this->caps()->isConfigTexturable(tempDrawInfo->fTempSurfaceDesc.fConfig)) {
353 // If we don't have a fallback to a straight upload then fail.
354 if (kRequireDraw_DrawPreference == *drawPreference ||
355 !this->caps()->isConfigTexturable(srcConfig)) {
356 return false;
357 }
358 *drawPreference = kNoDraw_DrawPreference;
359 }
360 return true;
361}
362
bsalomon6cb3cbe2015-07-30 07:34:27 -0700363bool GrGpu::readPixels(GrSurface* surface,
bsalomon@google.com669fdc42011-04-05 17:08:27 +0000364 int left, int top, int width, int height,
bsalomon@google.comc6980972011-11-02 19:57:21 +0000365 GrPixelConfig config, void* buffer,
senorblanco@chromium.org3cb406b2013-02-05 19:50:46 +0000366 size_t rowBytes) {
bsalomon@google.coma7f84e12011-03-10 14:13:19 +0000367 this->handleDirtyContext();
egdaniel6d901da2015-07-30 12:02:15 -0700368
369 // We cannot read pixels into a compressed buffer
370 if (GrPixelConfigIsCompressed(config)) {
371 return false;
372 }
373
374 size_t bpp = GrBytesPerPixel(config);
375 if (!GrSurfacePriv::AdjustReadPixelParams(surface->width(), surface->height(), bpp,
376 &left, &top, &width, &height,
377 &buffer,
378 &rowBytes)) {
379 return false;
380 }
381
382 return this->onReadPixels(surface,
383 left, top, width, height,
384 config, buffer,
385 rowBytes);
bsalomon@google.coma7f84e12011-03-10 14:13:19 +0000386}
387
bsalomon6cb3cbe2015-07-30 07:34:27 -0700388bool GrGpu::writePixels(GrSurface* surface,
389 int left, int top, int width, int height,
cblume55f2d2d2016-02-26 13:20:48 -0800390 GrPixelConfig config, const SkTArray<GrMipLevel>& texels) {
391 if (!surface) {
392 return false;
393 }
394 bool validMipDataFound = false;
395 for (int currentMipLevel = 0; currentMipLevel < texels.count(); currentMipLevel++) {
396 if (texels[currentMipLevel].fPixels != nullptr) {
397 validMipDataFound = true;
398 break;
399 }
400 }
401 if (!validMipDataFound) {
jvanverth2dc29942015-09-01 07:16:46 -0700402 return false;
403 }
404
bsalomon@google.com6f379512011-11-16 20:36:03 +0000405 this->handleDirtyContext();
cblume55f2d2d2016-02-26 13:20:48 -0800406 if (this->onWritePixels(surface, left, top, width, height, config, texels)) {
bsalomonb12ea412015-02-02 21:19:50 -0800407 fStats.incTextureUploads();
408 return true;
409 }
410 return false;
bsalomon@google.com6f379512011-11-16 20:36:03 +0000411}
412
cblume55f2d2d2016-02-26 13:20:48 -0800413bool GrGpu::writePixels(GrSurface* surface,
414 int left, int top, int width, int height,
415 GrPixelConfig config, const void* buffer,
416 size_t rowBytes) {
417 GrMipLevel mipLevel;
418 mipLevel.fPixels = buffer;
419 mipLevel.fRowBytes = rowBytes;
420 SkSTArray<1, GrMipLevel> texels;
421 texels.push_back(mipLevel);
422
423 return this->writePixels(surface, left, top, width, height, config, texels);
424}
425
jvanverth17aa0472016-01-05 10:41:27 -0800426bool GrGpu::transferPixels(GrSurface* surface,
427 int left, int top, int width, int height,
428 GrPixelConfig config, GrTransferBuffer* buffer,
429 size_t offset, size_t rowBytes) {
430 SkASSERT(buffer);
431
432 this->handleDirtyContext();
cblume61214052016-01-26 09:10:48 -0800433 if (this->onTransferPixels(surface, left, top, width, height, config,
jvanverth17aa0472016-01-05 10:41:27 -0800434 buffer, offset, rowBytes)) {
435 fStats.incTransfersToTexture();
436 return true;
437 }
438 return false;
439}
440
bsalomon@google.com75f9f252012-01-31 13:35:56 +0000441void GrGpu::resolveRenderTarget(GrRenderTarget* target) {
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000442 SkASSERT(target);
bsalomon@google.com75f9f252012-01-31 13:35:56 +0000443 this->handleDirtyContext();
444 this->onResolveRenderTarget(target);
445}
446
bsalomon@google.coma7f84e12011-03-10 14:13:19 +0000447////////////////////////////////////////////////////////////////////////////////
448
bsalomoncb8979d2015-05-05 09:51:38 -0700449void GrGpu::draw(const DrawArgs& args, const GrVertices& vertices) {
bsalomon@google.coma7f84e12011-03-10 14:13:19 +0000450 this->handleDirtyContext();
bsalomoncb02b382015-08-12 11:14:50 -0700451 if (GrXferBarrierType barrierType = args.fPipeline->xferBarrierType(*this->caps())) {
452 this->xferBarrier(args.fPipeline->getRenderTarget(), barrierType);
453 }
454
bsalomone64eb572015-05-07 11:35:55 -0700455 GrVertices::Iterator iter;
456 const GrNonInstancedVertices* verts = iter.init(vertices);
457 do {
458 this->onDraw(args, *verts);
joshualitt336cda32015-09-09 08:29:47 -0700459 fStats.incNumDraws();
bsalomone64eb572015-05-07 11:35:55 -0700460 } while ((verts = iter.next()));
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000461}
ethannicholas22793252016-01-30 09:59:10 -0800462