blob: 8e18fb8e25f11182fbf95b7bb1161631b1ab2028 [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
Greg Daniel51316782017-08-02 15:10:09 +000011#include "GrBackendSemaphore.h"
Greg Daniel7ef28f32017-04-20 16:41:55 +000012#include "GrBackendSurface.h"
cdalton397536c2016-03-25 12:15:03 -070013#include "GrBuffer.h"
bsalomoneb1cb5c2015-05-22 08:01:09 -070014#include "GrCaps.h"
bsalomon@google.com558a75b2011-08-08 17:01:14 +000015#include "GrContext.h"
Robert Phillips6be756b2018-01-16 15:07:54 -050016#include "GrContextPriv.h"
bsalomon3582d3e2015-02-13 14:20:05 -080017#include "GrGpuResourcePriv.h"
egdaniel0e1853c2016-03-17 11:35:45 -070018#include "GrMesh.h"
kkinnunencabe20c2015-06-01 01:37:26 -070019#include "GrPathRendering.h"
bsalomoncb02b382015-08-12 11:14:50 -070020#include "GrPipeline.h"
Robert Phillipsfbcef6e2017-06-15 12:07:18 -040021#include "GrRenderTargetPriv.h"
bsalomon0ea80f42015-02-11 10:49:59 -080022#include "GrResourceCache.h"
egdanielec00d942015-09-14 12:56:10 -070023#include "GrResourceProvider.h"
Greg Daniel51316782017-08-02 15:10:09 +000024#include "GrSemaphore.h"
egdaniel8dc7c3a2015-04-16 11:22:42 -070025#include "GrStencilAttachment.h"
csmartdaltonc633abb2016-11-01 08:55:55 -070026#include "GrStencilSettings.h"
egdaniel6d901da2015-07-30 12:02:15 -070027#include "GrSurfacePriv.h"
jvanverth900bd4a2016-04-29 13:53:12 -070028#include "GrTexturePriv.h"
Robert Phillipsabf7b762018-03-21 12:13:37 -040029#include "GrTextureProxyPriv.h"
Brian Salomondcbb9d92017-07-19 10:53:20 -040030#include "GrTracing.h"
Brian Osman71a18892017-08-10 10:23:25 -040031#include "SkJSONWriter.h"
halcanary4dbbd042016-06-07 17:21:10 -070032#include "SkMathPriv.h"
bsalomoncb8979d2015-05-05 09:51:38 -070033
bsalomon@google.comd302f142011-03-03 13:54:13 +000034////////////////////////////////////////////////////////////////////////////////
reed@google.comac10a2d2010-12-22 21:39:39 +000035
bsalomon@google.com6e4e6502013-02-25 20:12:45 +000036GrGpu::GrGpu(GrContext* context)
joshualitt3322fa42014-11-07 08:48:51 -080037 : fResetTimestamp(kExpiredTimestamp+1)
bsalomon@google.com0a208a12013-06-28 18:57:35 +000038 , fResetBits(kAll_GrBackendState)
joshualitt3322fa42014-11-07 08:48:51 -080039 , fContext(context) {
reed@google.comac10a2d2010-12-22 21:39:39 +000040}
41
bsalomoned0bcad2015-05-04 10:36:42 -070042GrGpu::~GrGpu() {}
bsalomon1d89ddc2014-08-19 14:20:58 -070043
bsalomon6e2aad42016-04-01 11:54:31 -070044void GrGpu::disconnect(DisconnectType) {}
reed@google.comac10a2d2010-12-22 21:39:39 +000045
bsalomon@google.comd302f142011-03-03 13:54:13 +000046////////////////////////////////////////////////////////////////////////////////
reed@google.comac10a2d2010-12-22 21:39:39 +000047
Greg Daniel8f5bbda2018-06-08 17:22:23 -040048bool GrGpu::IsACopyNeededForRepeatWrapMode(const GrCaps* caps, GrTextureProxy* texProxy,
49 int width, int height,
50 GrSamplerState::Filter filter,
51 GrTextureProducer::CopyParams* copyParams,
52 SkScalar scaleAdjust[2]) {
53 if (!caps->npotTextureTileSupport() &&
Greg Daniel09c94002018-06-08 22:11:51 +000054 (!SkIsPow2(width) || !SkIsPow2(height))) {
55 SkASSERT(scaleAdjust);
56 copyParams->fWidth = GrNextPow2(width);
57 copyParams->fHeight = GrNextPow2(height);
58 SkASSERT(scaleAdjust);
59 scaleAdjust[0] = ((SkScalar)copyParams->fWidth) / width;
60 scaleAdjust[1] = ((SkScalar)copyParams->fHeight) / height;
Greg Daniel8f5bbda2018-06-08 17:22:23 -040061 switch (filter) {
Greg Daniel09c94002018-06-08 22:11:51 +000062 case GrSamplerState::Filter::kNearest:
63 copyParams->fFilter = GrSamplerState::Filter::kNearest;
64 break;
65 case GrSamplerState::Filter::kBilerp:
66 case GrSamplerState::Filter::kMipMap:
67 // We are only ever scaling up so no reason to ever indicate kMipMap.
68 copyParams->fFilter = GrSamplerState::Filter::kBilerp;
69 break;
70 }
71 return true;
72 }
Robert Phillipsabf7b762018-03-21 12:13:37 -040073
74 if (texProxy) {
75 // If the texture format itself doesn't support repeat wrap mode or mipmapping (and
76 // those capabilities are required) force a copy.
Brian Salomonfd98c2c2018-07-31 17:25:29 -040077 if (texProxy->hasRestrictedSampling()) {
Robert Phillipsabf7b762018-03-21 12:13:37 -040078 copyParams->fFilter = GrSamplerState::Filter::kNearest;
79 copyParams->fWidth = texProxy->width();
80 copyParams->fHeight = texProxy->height();
81 return true;
82 }
83 }
84
bsalomon100b8f82015-10-28 08:37:44 -070085 return false;
bsalomon045802d2015-10-20 07:58:01 -070086}
87
Greg Daniel8f5bbda2018-06-08 17:22:23 -040088bool GrGpu::IsACopyNeededForMips(const GrCaps* caps, const GrTextureProxy* texProxy,
89 GrSamplerState::Filter filter,
90 GrTextureProducer::CopyParams* copyParams) {
91 SkASSERT(texProxy);
92 bool willNeedMips = GrSamplerState::Filter::kMipMap == filter && caps->mipMapSupport();
93 // If the texture format itself doesn't support mipmapping (and those capabilities are required)
94 // force a copy.
95 if (willNeedMips && texProxy->mipMapped() == GrMipMapped::kNo) {
96 copyParams->fFilter = GrSamplerState::Filter::kNearest;
97 copyParams->fWidth = texProxy->width();
98 copyParams->fHeight = texProxy->height();
99 return true;
100 }
101
102 return false;
103}
104
Robert Phillips67d52cf2017-06-05 13:38:13 -0400105sk_sp<GrTexture> GrGpu::createTexture(const GrSurfaceDesc& origDesc, SkBudgeted budgeted,
Brian Salomon58389b92018-03-07 13:01:25 -0500106 const GrMipLevel texels[], int mipLevelCount) {
Brian Salomondcbb9d92017-07-19 10:53:20 -0400107 GR_CREATE_TRACE_MARKER_CONTEXT("GrGpu", "createTexture", fContext);
cblume55f2d2d2016-02-26 13:20:48 -0800108 GrSurfaceDesc desc = origDesc;
109
Brian Salomonbdecacf2018-02-02 20:32:49 -0500110 GrMipMapped mipMapped = mipLevelCount > 1 ? GrMipMapped::kYes : GrMipMapped::kNo;
111 if (!this->caps()->validateSurfaceDesc(desc, mipMapped)) {
halcanary96fcdcc2015-08-27 07:41:13 -0700112 return nullptr;
egdaniel8c9b6f12015-05-12 13:36:30 -0700113 }
114
Brian Salomonbdecacf2018-02-02 20:32:49 -0500115 bool isRT = desc.fFlags & kRenderTarget_GrSurfaceFlag;
116 if (isRT) {
117 desc.fSampleCnt = this->caps()->getRenderTargetSampleCount(desc.fSampleCnt, desc.fConfig);
118 }
Brian Salomond17b4a62017-05-23 16:53:47 -0400119 // Attempt to catch un- or wrongly initialized sample counts.
Brian Salomonbdecacf2018-02-02 20:32:49 -0500120 SkASSERT(desc.fSampleCnt > 0 && desc.fSampleCnt <= 64);
egdanielb0e1be22015-04-22 13:27:39 -0700121
Robert Phillips590533f2017-07-11 14:22:35 -0400122 if (mipLevelCount && (desc.fFlags & kPerformInitialClear_GrSurfaceFlag)) {
Brian Salomond17b4a62017-05-23 16:53:47 -0400123 return nullptr;
124 }
125
Robert Phillips92de6312017-05-23 07:43:48 -0400126 this->handleDirtyContext();
Brian Salomon58389b92018-03-07 13:01:25 -0500127 sk_sp<GrTexture> tex = this->onCreateTexture(desc, budgeted, texels, mipLevelCount);
bsalomonb12ea412015-02-02 21:19:50 -0800128 if (tex) {
Brian Salomonbdecacf2018-02-02 20:32:49 -0500129 if (!this->caps()->reuseScratchTextures() && !isRT) {
cblume55f2d2d2016-02-26 13:20:48 -0800130 tex->resourcePriv().removeScratchKey();
131 }
bsalomonb12ea412015-02-02 21:19:50 -0800132 fStats.incTextureCreates();
Robert Phillips590533f2017-07-11 14:22:35 -0400133 if (mipLevelCount) {
cblume55f2d2d2016-02-26 13:20:48 -0800134 if (texels[0].fPixels) {
135 fStats.incTextureUploads();
136 }
bsalomonb12ea412015-02-02 21:19:50 -0800137 }
138 }
bsalomon@google.com81c3f8d2011-08-03 15:18:33 +0000139 return tex;
140}
141
Robert Phillips646e4292017-06-13 12:44:56 -0400142sk_sp<GrTexture> GrGpu::createTexture(const GrSurfaceDesc& desc, SkBudgeted budgeted) {
Brian Salomon58389b92018-03-07 13:01:25 -0500143 return this->createTexture(desc, budgeted, nullptr, 0);
Robert Phillips646e4292017-06-13 12:44:56 -0400144}
145
Greg Daniel7ef28f32017-04-20 16:41:55 +0000146sk_sp<GrTexture> GrGpu::wrapBackendTexture(const GrBackendTexture& backendTex,
Greg Daniel2268ad22018-11-15 09:27:38 -0500147 GrWrapOwnership ownership,
148 bool purgeImmediately) {
bsalomon@google.come269f212011-11-07 13:29:52 +0000149 this->handleDirtyContext();
Greg Daniel7ef28f32017-04-20 16:41:55 +0000150 if (!this->caps()->isConfigTexturable(backendTex.config())) {
bsalomon5b30c6f2015-12-17 14:17:34 -0800151 return nullptr;
152 }
Brian Salomond17f6582017-07-19 18:28:58 -0400153 if (backendTex.width() > this->caps()->maxTextureSize() ||
154 backendTex.height() > this->caps()->maxTextureSize()) {
bsalomon5b30c6f2015-12-17 14:17:34 -0800155 return nullptr;
156 }
Brian Salomonff4ccaa2018-12-05 21:35:33 +0000157 return this->onWrapBackendTexture(backendTex, ownership, purgeImmediately);
Brian Salomond17f6582017-07-19 18:28:58 -0400158}
Eric Karl5c779752017-05-08 12:02:07 -0700159
Brian Salomond17f6582017-07-19 18:28:58 -0400160sk_sp<GrTexture> GrGpu::wrapRenderableBackendTexture(const GrBackendTexture& backendTex,
Robert Phillipsb0e93a22017-08-29 08:26:54 -0400161 int sampleCnt, GrWrapOwnership ownership) {
Brian Salomond17f6582017-07-19 18:28:58 -0400162 this->handleDirtyContext();
Brian Salomonbdecacf2018-02-02 20:32:49 -0500163 if (sampleCnt < 1) {
164 return nullptr;
165 }
Brian Salomond17f6582017-07-19 18:28:58 -0400166 if (!this->caps()->isConfigTexturable(backendTex.config()) ||
Brian Salomonbdecacf2018-02-02 20:32:49 -0500167 !this->caps()->getRenderTargetSampleCount(sampleCnt, backendTex.config())) {
Brian Salomond17f6582017-07-19 18:28:58 -0400168 return nullptr;
169 }
170
171 if (backendTex.width() > this->caps()->maxRenderTargetSize() ||
172 backendTex.height() > this->caps()->maxRenderTargetSize()) {
173 return nullptr;
174 }
Robert Phillipsc0192e32017-09-21 12:00:26 -0400175 sk_sp<GrTexture> tex = this->onWrapRenderableBackendTexture(backendTex, sampleCnt, ownership);
Greg Daniele3204862018-04-16 11:24:10 -0400176 SkASSERT(!tex || tex->asRenderTarget());
bungeman6bd52842016-10-27 09:30:08 -0700177 return tex;
bsalomon@google.come269f212011-11-07 13:29:52 +0000178}
179
Robert Phillipsb0e93a22017-08-29 08:26:54 -0400180sk_sp<GrRenderTarget> GrGpu::wrapBackendRenderTarget(const GrBackendRenderTarget& backendRT) {
Brian Salomonbdecacf2018-02-02 20:32:49 -0500181 if (0 == this->caps()->getRenderTargetSampleCount(backendRT.sampleCnt(), backendRT.config())) {
bsalomon5b30c6f2015-12-17 14:17:34 -0800182 return nullptr;
183 }
bsalomon@google.come269f212011-11-07 13:29:52 +0000184 this->handleDirtyContext();
Robert Phillipsb0e93a22017-08-29 08:26:54 -0400185 return this->onWrapBackendRenderTarget(backendRT);
bsalomon@google.come269f212011-11-07 13:29:52 +0000186}
187
Greg Daniel7ef28f32017-04-20 16:41:55 +0000188sk_sp<GrRenderTarget> GrGpu::wrapBackendTextureAsRenderTarget(const GrBackendTexture& tex,
Greg Daniel7ef28f32017-04-20 16:41:55 +0000189 int sampleCnt) {
Brian Salomonbdecacf2018-02-02 20:32:49 -0500190 if (0 == this->caps()->getRenderTargetSampleCount(sampleCnt, tex.config())) {
ericrkf7b8b8a2016-02-24 14:49:51 -0800191 return nullptr;
192 }
193 int maxSize = this->caps()->maxTextureSize();
Greg Daniel7ef28f32017-04-20 16:41:55 +0000194 if (tex.width() > maxSize || tex.height() > maxSize) {
ericrkf7b8b8a2016-02-24 14:49:51 -0800195 return nullptr;
196 }
Brian Salomonbdecacf2018-02-02 20:32:49 -0500197 this->handleDirtyContext();
Robert Phillipsb0e93a22017-08-29 08:26:54 -0400198 return this->onWrapBackendTextureAsRenderTarget(tex, sampleCnt);
ericrkf7b8b8a2016-02-24 14:49:51 -0800199}
200
cdaltone2e71c22016-04-07 18:13:29 -0700201GrBuffer* GrGpu::createBuffer(size_t size, GrBufferType intendedType,
cdalton1bf3e712016-04-19 10:00:02 -0700202 GrAccessPattern accessPattern, const void* data) {
bsalomon@google.coma7f84e12011-03-10 14:13:19 +0000203 this->handleDirtyContext();
cdalton1bf3e712016-04-19 10:00:02 -0700204 GrBuffer* buffer = this->onCreateBuffer(size, intendedType, accessPattern, data);
robertphillips1b8e1b52015-06-24 06:54:10 -0700205 if (!this->caps()->reuseScratchBuffers()) {
cdalton397536c2016-03-25 12:15:03 -0700206 buffer->resourcePriv().removeScratchKey();
robertphillips1b8e1b52015-06-24 06:54:10 -0700207 }
cdalton397536c2016-03-25 12:15:03 -0700208 return buffer;
jvanverth73063dc2015-12-03 09:15:47 -0800209}
210
Robert Phillipsb0e93a22017-08-29 08:26:54 -0400211bool GrGpu::copySurface(GrSurface* dst, GrSurfaceOrigin dstOrigin,
212 GrSurface* src, GrSurfaceOrigin srcOrigin,
Greg Daniel55fa6472018-03-16 16:13:10 -0400213 const SkIRect& srcRect, const SkIPoint& dstPoint,
214 bool canDiscardOutsideDstRect) {
Brian Salomondcbb9d92017-07-19 10:53:20 -0400215 GR_CREATE_TRACE_MARKER_CONTEXT("GrGpu", "copySurface", fContext);
joshualitt1cbdcde2015-08-21 11:53:29 -0700216 SkASSERT(dst && src);
217 this->handleDirtyContext();
Greg Daniel55fa6472018-03-16 16:13:10 -0400218 return this->onCopySurface(dst, dstOrigin, src, srcOrigin, srcRect, dstPoint,
219 canDiscardOutsideDstRect);
joshualitt1cbdcde2015-08-21 11:53:29 -0700220}
221
Brian Salomona6948702018-06-01 15:33:20 -0400222bool GrGpu::readPixels(GrSurface* surface, int left, int top, int width, int height,
223 GrColorType dstColorType, void* buffer, size_t rowBytes) {
Brian Salomonbf7b6202016-11-11 16:08:03 -0500224 SkASSERT(surface);
225
Brian Salomonc320b152018-02-20 14:05:36 -0500226 int bpp = GrColorTypeBytesPerPixel(dstColorType);
egdaniel6d901da2015-07-30 12:02:15 -0700227 if (!GrSurfacePriv::AdjustReadPixelParams(surface->width(), surface->height(), bpp,
228 &left, &top, &width, &height,
229 &buffer,
230 &rowBytes)) {
231 return false;
232 }
233
Brian Salomonbf7b6202016-11-11 16:08:03 -0500234 this->handleDirtyContext();
235
Brian Salomona6948702018-06-01 15:33:20 -0400236 return this->onReadPixels(surface, left, top, width, height, dstColorType, buffer, rowBytes);
bsalomon@google.coma7f84e12011-03-10 14:13:19 +0000237}
238
Brian Salomona9b04b92018-06-01 15:04:28 -0400239bool GrGpu::writePixels(GrSurface* surface, int left, int top, int width, int height,
240 GrColorType srcColorType, const GrMipLevel texels[], int mipLevelCount) {
Brian Salomonbf7b6202016-11-11 16:08:03 -0500241 SkASSERT(surface);
Robert Phillips590533f2017-07-11 14:22:35 -0400242 if (1 == mipLevelCount) {
Greg Daniel660cc992017-06-26 14:55:05 -0400243 // We require that if we are not mipped, then the write region is contained in the surface
244 SkIRect subRect = SkIRect::MakeXYWH(left, top, width, height);
245 SkIRect bounds = SkIRect::MakeWH(surface->width(), surface->height());
246 if (!bounds.contains(subRect)) {
247 return false;
248 }
249 } else if (0 != left || 0 != top || width != surface->width() || height != surface->height()) {
250 // We require that if the texels are mipped, than the write region is the entire surface
251 return false;
252 }
Robert Phillipsb7b7e5f2017-05-22 13:23:19 -0400253
Robert Phillips590533f2017-07-11 14:22:35 -0400254 for (int currentMipLevel = 0; currentMipLevel < mipLevelCount; currentMipLevel++) {
bsalomone699d0c2016-03-09 06:25:15 -0800255 if (!texels[currentMipLevel].fPixels ) {
256 return false;
cblume55f2d2d2016-02-26 13:20:48 -0800257 }
258 }
jvanverth2dc29942015-09-01 07:16:46 -0700259
bsalomon@google.com6f379512011-11-16 20:36:03 +0000260 this->handleDirtyContext();
Brian Salomona9b04b92018-06-01 15:04:28 -0400261 if (this->onWritePixels(surface, left, top, width, height, srcColorType, texels,
Brian Salomonc320b152018-02-20 14:05:36 -0500262 mipLevelCount)) {
jvanverth900bd4a2016-04-29 13:53:12 -0700263 SkIRect rect = SkIRect::MakeXYWH(left, top, width, height);
Brian Salomona9b04b92018-06-01 15:04:28 -0400264 this->didWriteToSurface(surface, kTopLeft_GrSurfaceOrigin, &rect, mipLevelCount);
bsalomonb12ea412015-02-02 21:19:50 -0800265 fStats.incTextureUploads();
266 return true;
267 }
268 return false;
bsalomon@google.com6f379512011-11-16 20:36:03 +0000269}
270
Brian Salomonc320b152018-02-20 14:05:36 -0500271bool GrGpu::transferPixels(GrTexture* texture, int left, int top, int width, int height,
272 GrColorType bufferColorType, GrBuffer* transferBuffer, size_t offset,
273 size_t rowBytes) {
cdalton397536c2016-03-25 12:15:03 -0700274 SkASSERT(transferBuffer);
jvanverth17aa0472016-01-05 10:41:27 -0800275
Greg Daniel660cc992017-06-26 14:55:05 -0400276 // We require that the write region is contained in the texture
277 SkIRect subRect = SkIRect::MakeXYWH(left, top, width, height);
278 SkIRect bounds = SkIRect::MakeWH(texture->width(), texture->height());
279 if (!bounds.contains(subRect)) {
280 return false;
281 }
282
jvanverth17aa0472016-01-05 10:41:27 -0800283 this->handleDirtyContext();
Brian Salomonc320b152018-02-20 14:05:36 -0500284 if (this->onTransferPixels(texture, left, top, width, height, bufferColorType, transferBuffer,
285 offset, rowBytes)) {
jvanverth900bd4a2016-04-29 13:53:12 -0700286 SkIRect rect = SkIRect::MakeXYWH(left, top, width, height);
Brian Salomon1fabd512018-02-09 09:54:25 -0500287 this->didWriteToSurface(texture, kTopLeft_GrSurfaceOrigin, &rect);
jvanverth17aa0472016-01-05 10:41:27 -0800288 fStats.incTransfersToTexture();
jvanverth84741b32016-09-30 08:39:02 -0700289
jvanverth17aa0472016-01-05 10:41:27 -0800290 return true;
291 }
292 return false;
293}
294
Brian Salomon930f9392018-06-20 16:25:26 -0400295bool GrGpu::regenerateMipMapLevels(GrTexture* texture) {
296 SkASSERT(texture);
297 SkASSERT(this->caps()->mipMapSupport());
298 SkASSERT(texture->texturePriv().mipMapped() == GrMipMapped::kYes);
299 SkASSERT(texture->texturePriv().mipMapsAreDirty());
300 SkASSERT(!texture->asRenderTarget() || !texture->asRenderTarget()->needsResolve());
301 if (this->onRegenerateMipMapLevels(texture)) {
302 texture->texturePriv().markMipMapsClean();
303 return true;
304 }
305 return false;
306}
307
Brian Salomon1fabd512018-02-09 09:54:25 -0500308void GrGpu::resolveRenderTarget(GrRenderTarget* target) {
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000309 SkASSERT(target);
bsalomon@google.com75f9f252012-01-31 13:35:56 +0000310 this->handleDirtyContext();
Brian Salomon1fabd512018-02-09 09:54:25 -0500311 this->onResolveRenderTarget(target);
bsalomon@google.com75f9f252012-01-31 13:35:56 +0000312}
313
Brian Salomon1fabd512018-02-09 09:54:25 -0500314void GrGpu::didWriteToSurface(GrSurface* surface, GrSurfaceOrigin origin, const SkIRect* bounds,
315 uint32_t mipLevels) const {
jvanverth900bd4a2016-04-29 13:53:12 -0700316 SkASSERT(surface);
317 // Mark any MIP chain and resolve buffer as dirty if and only if there is a non-empty bounds.
318 if (nullptr == bounds || !bounds->isEmpty()) {
319 if (GrRenderTarget* target = surface->asRenderTarget()) {
Brian Salomon1fabd512018-02-09 09:54:25 -0500320 SkIRect flippedBounds;
321 if (kBottomLeft_GrSurfaceOrigin == origin && bounds) {
322 flippedBounds = {bounds->fLeft, surface->height() - bounds->fBottom,
323 bounds->fRight, surface->height() - bounds->fTop};
324 bounds = &flippedBounds;
325 }
jvanverth900bd4a2016-04-29 13:53:12 -0700326 target->flagAsNeedingResolve(bounds);
327 }
328 GrTexture* texture = surface->asTexture();
329 if (texture && 1 == mipLevels) {
Greg Daniel0fc4d2d2017-10-12 11:23:36 -0400330 texture->texturePriv().markMipMapsDirty();
jvanverth900bd4a2016-04-29 13:53:12 -0700331 }
332 }
333}
334
Greg Daniel51316782017-08-02 15:10:09 +0000335GrSemaphoresSubmitted GrGpu::finishFlush(int numSemaphores,
336 GrBackendSemaphore backendSemaphores[]) {
Robert Phillips6be756b2018-01-16 15:07:54 -0500337 GrResourceProvider* resourceProvider = fContext->contextPriv().resourceProvider();
338
Greg Daniel51316782017-08-02 15:10:09 +0000339 if (this->caps()->fenceSyncSupport()) {
340 for (int i = 0; i < numSemaphores; ++i) {
341 sk_sp<GrSemaphore> semaphore;
342 if (backendSemaphores[i].isInitialized()) {
Robert Phillips6be756b2018-01-16 15:07:54 -0500343 semaphore = resourceProvider->wrapBackendSemaphore(
Greg Daniel17b7c052018-01-09 13:55:33 -0500344 backendSemaphores[i], GrResourceProvider::SemaphoreWrapType::kWillSignal,
345 kBorrow_GrWrapOwnership);
Greg Daniel51316782017-08-02 15:10:09 +0000346 } else {
Robert Phillips6be756b2018-01-16 15:07:54 -0500347 semaphore = resourceProvider->makeSemaphore(false);
Greg Daniel51316782017-08-02 15:10:09 +0000348 }
349 this->insertSemaphore(semaphore, false);
350
351 if (!backendSemaphores[i].isInitialized()) {
Brian Salomon1e576e72018-08-30 10:20:38 -0400352 backendSemaphores[i] = semaphore->backendSemaphore();
Greg Daniel51316782017-08-02 15:10:09 +0000353 }
354 }
355 }
356 this->onFinishFlush((numSemaphores > 0 && this->caps()->fenceSyncSupport()));
357 return this->caps()->fenceSyncSupport() ? GrSemaphoresSubmitted::kYes
358 : GrSemaphoresSubmitted::kNo;
359}
Brian Osman71a18892017-08-10 10:23:25 -0400360
Kevin Lubickf4def342018-10-04 12:52:50 -0400361#ifdef SK_ENABLE_DUMP_GPU
Brian Osman71a18892017-08-10 10:23:25 -0400362void GrGpu::dumpJSON(SkJSONWriter* writer) const {
363 writer->beginObject();
364
365 // TODO: Is there anything useful in the base class to dump here?
366
367 this->onDumpJSON(writer);
368
369 writer->endObject();
370}
Kevin Lubickf4def342018-10-04 12:52:50 -0400371#else
372void GrGpu::dumpJSON(SkJSONWriter* writer) const { }
373#endif
Robert Phillips646f6372018-09-25 09:31:10 -0400374
375#if GR_TEST_UTILS
376GrBackendTexture GrGpu::createTestingOnlyBackendTexture(const void* pixels, int w, int h,
377 SkColorType colorType, bool isRenderTarget,
378 GrMipMapped isMipped, size_t rowBytes) {
379 GrColorType grCT = SkColorTypeToGrColorType(colorType);
380
381 return this->createTestingOnlyBackendTexture(pixels, w, h, grCT, isRenderTarget, isMipped,
382 rowBytes);
383}
384#endif