blob: 2ccfdfd64ad652d75d8820042ed7ee09fcb3a45f [file] [log] [blame]
bsalomondc47ff72015-05-26 12:16:59 -07001/*
2 * Copyright 2015 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
Mike Kleinc0bd9f92019-04-23 12:05:21 -05008#include "include/gpu/GrBackendSurface.h"
9#include "include/gpu/GrContextOptions.h"
10#include "include/gpu/GrSurface.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050011#include "include/private/GrTypesPriv.h"
12#include "src/gpu/GrCaps.h"
Greg Danielf91aeb22019-06-18 09:58:02 -040013#include "src/gpu/GrSurfaceProxy.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050014#include "src/gpu/GrWindowRectangles.h"
15#include "src/utils/SkJSONWriter.h"
bsalomondc47ff72015-05-26 12:16:59 -070016
bsalomondc47ff72015-05-26 12:16:59 -070017GrCaps::GrCaps(const GrContextOptions& options) {
18 fMipMapSupport = false;
19 fNPOTTextureTileSupport = false;
brianosmana6359362016-03-21 06:55:37 -070020 fSRGBSupport = false;
brianosman35b784d2016-05-05 11:52:53 -070021 fSRGBWriteControl = false;
bsalomondc47ff72015-05-26 12:16:59 -070022 fReuseScratchTextures = true;
robertphillips1b8e1b52015-06-24 06:54:10 -070023 fReuseScratchBuffers = true;
bsalomondc47ff72015-05-26 12:16:59 -070024 fGpuTracingSupport = false;
bsalomondc47ff72015-05-26 12:16:59 -070025 fOversizedStencilSupport = false;
26 fTextureBarrierSupport = false;
Robert Phillips7f861922018-01-30 13:13:42 +000027 fSampleLocationsSupport = false;
csmartdalton2b5f2cb2016-06-10 14:06:32 -070028 fMultisampleDisableSupport = false;
Chris Dalton1d616352017-05-31 12:51:23 -060029 fInstanceAttribSupport = false;
Chris Dalton6ce447a2019-06-23 18:07:38 -060030 fMixedSamplesSupport = false;
Chris Dalton27059d32018-01-23 14:06:50 -070031 fUsePrimitiveRestart = false;
csmartdalton485a1202016-07-13 10:16:32 -070032 fPreferClientSideDynamicBuffers = false;
Chris Dalton344e9032017-12-11 15:42:09 -070033 fPreferFullscreenClears = false;
bsalomon7dea7b72015-08-19 08:26:51 -070034 fMustClearUploadedBufferData = false;
Kevin Lubick61a5f0a2019-03-28 09:47:15 -040035 fShouldInitializeTextures = false;
Greg Danielb2acf0a2018-09-12 09:17:11 -040036 fSupportsAHardwareBufferImages = false;
jvanverth84741b32016-09-30 08:39:02 -070037 fFenceSyncSupport = false;
Brian Salomon9ff5acb2019-05-08 09:04:47 -040038 fSemaphoreSupport = false;
Brian Osman2c2bc112017-02-28 10:02:49 -050039 fCrossContextTextureSupport = false;
Brian Osman499bf1a2018-09-17 11:32:42 -040040 fHalfFloatVertexAttributeSupport = false;
Brian Salomonf7232642018-09-19 08:58:08 -040041 fDynamicStateArrayGeometryProcessorTextureSupport = false;
Michael Ludwiga21d1962019-01-11 15:26:22 -050042 fPerformPartialClearsAsDraws = false;
43 fPerformColorClearsAsDraws = false;
44 fPerformStencilClearsAsDraws = false;
Chris Daltona8fbeba2019-03-30 00:31:23 -060045 fAllowCoverageCounting = false;
Brian Salomone05ba5a2019-04-08 11:59:07 -040046 fTransferBufferSupport = false;
Brian Salomon1047a492019-07-02 12:25:21 -040047 fWritePixelsRowBytesSupport = false;
48 fReadPixelsRowBytesSupport = false;
Chris Daltona8fbeba2019-03-30 00:31:23 -060049 fDriverBlacklistCCPR = false;
Chris Dalton7c012082019-07-22 00:45:52 -040050 fDriverBlacklistMSAACCPR = false;
bsalomondc47ff72015-05-26 12:16:59 -070051
bsalomondc47ff72015-05-26 12:16:59 -070052 fBlendEquationSupport = kBasic_BlendEquationSupport;
cdalton1dd05422015-06-12 09:01:18 -070053 fAdvBlendEqBlacklist = 0;
54
bsalomondc47ff72015-05-26 12:16:59 -070055 fMapBufferFlags = kNone_MapFlags;
56
bsalomon7dbd45d2016-03-23 10:40:53 -070057 fMaxVertexAttributes = 0;
egdanielff1d5472015-09-10 08:37:20 -070058 fMaxRenderTargetSize = 1;
Chris Dalton2612bae2018-02-22 13:41:37 -070059 fMaxPreferredRenderTargetSize = 1;
egdanielff1d5472015-09-10 08:37:20 -070060 fMaxTextureSize = 1;
csmartdalton9bc11872016-08-09 12:42:47 -070061 fMaxWindowRectangles = 0;
Chris Daltona1638a52019-06-24 11:54:24 -060062 fInternalMultisampleCount = 0;
bsalomondc47ff72015-05-26 12:16:59 -070063
robertphillipscaef3452015-11-11 13:18:11 -080064 fSuppressPrints = options.fSuppressPrints;
Brian Osman195c05b2017-08-30 15:14:04 -040065#if GR_TEST_UTILS
Jim Van Verthfbdc0802017-05-02 16:15:53 -040066 fWireframeMode = options.fWireframeMode;
Brian Osman195c05b2017-08-30 15:14:04 -040067#else
68 fWireframeMode = false;
69#endif
cdalton397536c2016-03-25 12:15:03 -070070 fBufferMapThreshold = options.fBufferMapThreshold;
Eric Karl5c779752017-05-08 12:02:07 -070071 fAvoidStencilBuffers = false;
Greg Daniel4374e962018-09-28 15:09:47 -040072 fAvoidWritePixelsFastPath = false;
robertphillips63926682015-08-20 09:39:02 -070073
74 fPreferVRAMUseOverFlushes = true;
Adrienne Walkerab7181d2018-05-14 14:02:03 -070075
Chris Dalton0dffbab2019-03-27 13:08:50 -060076 fPreferTrianglesOverSampleMask = false;
77
Michael Ludwigf23a1522018-12-10 11:36:13 -050078 // Default to true, allow older versions of OpenGL to disable explicitly
79 fClampToBorderSupport = true;
80
Adrienne Walkerab7181d2018-05-14 14:02:03 -070081 fDriverBugWorkarounds = options.fDriverBugWorkarounds;
bsalomondc47ff72015-05-26 12:16:59 -070082}
83
bsalomon4ee6bd82015-05-27 13:23:23 -070084void GrCaps::applyOptionsOverrides(const GrContextOptions& options) {
csmartdalton28341fa2016-08-17 10:00:21 -070085 this->onApplyOptionsOverrides(options);
Brian Salomon01b476a2018-01-23 11:06:41 -050086 if (options.fDisableDriverCorrectnessWorkarounds) {
Chris Daltona8fbeba2019-03-30 00:31:23 -060087 SkASSERT(!fDriverBlacklistCCPR);
Chris Dalton7c012082019-07-22 00:45:52 -040088 SkASSERT(!fDriverBlacklistMSAACCPR);
Brian Salomon01b476a2018-01-23 11:06:41 -050089 SkASSERT(!fAvoidStencilBuffers);
90 SkASSERT(!fAdvBlendEqBlacklist);
Michael Ludwiga21d1962019-01-11 15:26:22 -050091 SkASSERT(!fPerformColorClearsAsDraws);
92 SkASSERT(!fPerformStencilClearsAsDraws);
93 // Don't check the partial-clear workaround, since that is a backend limitation, not a
94 // driver workaround (it just so happens the fallbacks are the same).
95 }
96 if (GrContextOptions::Enable::kNo == options.fUseDrawInsteadOfClear) {
97 fPerformColorClearsAsDraws = false;
98 fPerformStencilClearsAsDraws = false;
99 } else if (GrContextOptions::Enable::kYes == options.fUseDrawInsteadOfClear) {
100 fPerformColorClearsAsDraws = true;
101 fPerformStencilClearsAsDraws = true;
Brian Salomon01b476a2018-01-23 11:06:41 -0500102 }
103
Chris Daltona8fbeba2019-03-30 00:31:23 -0600104 fAllowCoverageCounting = !options.fDisableCoverageCountingPaths;
105
bsalomon4ee6bd82015-05-27 13:23:23 -0700106 fMaxTextureSize = SkTMin(fMaxTextureSize, options.fMaxTextureSizeOverride);
Brian Osman195c05b2017-08-30 15:14:04 -0400107 fMaxTileSize = fMaxTextureSize;
108#if GR_TEST_UTILS
bsalomon8c07b7a2015-11-02 11:36:52 -0800109 // If the max tile override is zero, it means we should use the max texture size.
Brian Osman195c05b2017-08-30 15:14:04 -0400110 if (options.fMaxTileSizeOverride && options.fMaxTileSizeOverride < fMaxTextureSize) {
bsalomon8c07b7a2015-11-02 11:36:52 -0800111 fMaxTileSize = options.fMaxTileSizeOverride;
112 }
Chris Dalton040238b2017-12-18 14:22:34 -0700113 if (options.fSuppressGeometryShaders) {
114 fShaderCaps->fGeometryShaderSupport = false;
115 }
Brian Salomona3e29962019-07-16 11:52:08 -0400116 if (options.fClearAllTextures) {
117 fShouldInitializeTextures = true;
118 }
Brian Osman195c05b2017-08-30 15:14:04 -0400119#endif
Chris Dalton1e6c5b82019-06-17 14:16:49 -0600120
csmartdalton28341fa2016-08-17 10:00:21 -0700121 if (fMaxWindowRectangles > GrWindowRectangles::kMaxWindows) {
csmartdalton7535f412016-08-23 06:51:00 -0700122 SkDebugf("WARNING: capping window rectangles at %i. HW advertises support for %i.\n",
123 GrWindowRectangles::kMaxWindows, fMaxWindowRectangles);
csmartdalton28341fa2016-08-17 10:00:21 -0700124 fMaxWindowRectangles = GrWindowRectangles::kMaxWindows;
125 }
Chris Dalton1e6c5b82019-06-17 14:16:49 -0600126
Chris Daltona1638a52019-06-24 11:54:24 -0600127 fInternalMultisampleCount = options.fInternalMultisampleCount;
Chris Dalton1e6c5b82019-06-17 14:16:49 -0600128
Eric Karl5c779752017-05-08 12:02:07 -0700129 fAvoidStencilBuffers = options.fAvoidStencilBuffers;
Adrienne Walkerab7181d2018-05-14 14:02:03 -0700130
131 fDriverBugWorkarounds.applyOverrides(options.fDriverBugWorkarounds);
bsalomon4ee6bd82015-05-27 13:23:23 -0700132}
133
Kevin Lubickf4def342018-10-04 12:52:50 -0400134
135#ifdef SK_ENABLE_DUMP_GPU
Robert Phillipsbac46722019-08-01 15:09:17 -0400136#include "src/gpu/GrTestUtils.h"
Kevin Lubickf4def342018-10-04 12:52:50 -0400137
bsalomondc47ff72015-05-26 12:16:59 -0700138static SkString map_flags_to_string(uint32_t flags) {
139 SkString str;
140 if (GrCaps::kNone_MapFlags == flags) {
141 str = "none";
142 } else {
143 SkASSERT(GrCaps::kCanMap_MapFlag & flags);
144 SkDEBUGCODE(flags &= ~GrCaps::kCanMap_MapFlag);
145 str = "can_map";
146
147 if (GrCaps::kSubset_MapFlag & flags) {
148 str.append(" partial");
149 } else {
150 str.append(" full");
151 }
152 SkDEBUGCODE(flags &= ~GrCaps::kSubset_MapFlag);
Brian Salomon105d7c22019-04-16 13:46:14 -0400153 if (GrCaps::kAsyncRead_MapFlag & flags) {
154 str.append(" async_read");
155 } else {
156 str.append(" sync_read");
157 }
158 SkDEBUGCODE(flags &= ~GrCaps::kAsyncRead_MapFlag);
bsalomondc47ff72015-05-26 12:16:59 -0700159 }
160 SkASSERT(0 == flags); // Make sure we handled all the flags.
161 return str;
162}
163
Brian Osman71a18892017-08-10 10:23:25 -0400164void GrCaps::dumpJSON(SkJSONWriter* writer) const {
165 writer->beginObject();
jvanverth84741b32016-09-30 08:39:02 -0700166
Brian Osman71a18892017-08-10 10:23:25 -0400167 writer->appendBool("MIP Map Support", fMipMapSupport);
168 writer->appendBool("NPOT Texture Tile Support", fNPOTTextureTileSupport);
169 writer->appendBool("sRGB Support", fSRGBSupport);
170 writer->appendBool("sRGB Write Control", fSRGBWriteControl);
Brian Osman71a18892017-08-10 10:23:25 -0400171 writer->appendBool("Reuse Scratch Textures", fReuseScratchTextures);
172 writer->appendBool("Reuse Scratch Buffers", fReuseScratchBuffers);
173 writer->appendBool("Gpu Tracing Support", fGpuTracingSupport);
174 writer->appendBool("Oversized Stencil Support", fOversizedStencilSupport);
175 writer->appendBool("Texture Barrier Support", fTextureBarrierSupport);
Robert Phillips7f861922018-01-30 13:13:42 +0000176 writer->appendBool("Sample Locations Support", fSampleLocationsSupport);
Brian Osman71a18892017-08-10 10:23:25 -0400177 writer->appendBool("Multisample disable support", fMultisampleDisableSupport);
178 writer->appendBool("Instance Attrib Support", fInstanceAttribSupport);
Chris Dalton6ce447a2019-06-23 18:07:38 -0600179 writer->appendBool("Mixed Samples Support", fMixedSamplesSupport);
Chris Dalton27059d32018-01-23 14:06:50 -0700180 writer->appendBool("Use primitive restart", fUsePrimitiveRestart);
Brian Osman71a18892017-08-10 10:23:25 -0400181 writer->appendBool("Prefer client-side dynamic buffers", fPreferClientSideDynamicBuffers);
Chris Dalton344e9032017-12-11 15:42:09 -0700182 writer->appendBool("Prefer fullscreen clears", fPreferFullscreenClears);
Brian Osman71a18892017-08-10 10:23:25 -0400183 writer->appendBool("Must clear buffer memory", fMustClearUploadedBufferData);
Kevin Lubick61a5f0a2019-03-28 09:47:15 -0400184 writer->appendBool("Should initialize textures", fShouldInitializeTextures);
Greg Danielb2acf0a2018-09-12 09:17:11 -0400185 writer->appendBool("Supports importing AHardwareBuffers", fSupportsAHardwareBufferImages);
Brian Osman71a18892017-08-10 10:23:25 -0400186 writer->appendBool("Fence sync support", fFenceSyncSupport);
Brian Salomon9ff5acb2019-05-08 09:04:47 -0400187 writer->appendBool("Semaphore support", fSemaphoreSupport);
Brian Osman71a18892017-08-10 10:23:25 -0400188 writer->appendBool("Cross context texture support", fCrossContextTextureSupport);
Brian Osman499bf1a2018-09-17 11:32:42 -0400189 writer->appendBool("Half float vertex attribute support", fHalfFloatVertexAttributeSupport);
Brian Salomonf7232642018-09-19 08:58:08 -0400190 writer->appendBool("Specify GeometryProcessor textures as a dynamic state array",
191 fDynamicStateArrayGeometryProcessorTextureSupport);
Michael Ludwiga21d1962019-01-11 15:26:22 -0500192 writer->appendBool("Use draws for partial clears", fPerformPartialClearsAsDraws);
193 writer->appendBool("Use draws for color clears", fPerformColorClearsAsDraws);
194 writer->appendBool("Use draws for stencil clip clears", fPerformStencilClearsAsDraws);
Chris Daltona8fbeba2019-03-30 00:31:23 -0600195 writer->appendBool("Allow coverage counting shortcuts", fAllowCoverageCounting);
Brian Salomone05ba5a2019-04-08 11:59:07 -0400196 writer->appendBool("Supports transfer buffers", fTransferBufferSupport);
Brian Salomon1047a492019-07-02 12:25:21 -0400197 writer->appendBool("Write pixels row bytes support", fWritePixelsRowBytesSupport);
198 writer->appendBool("Read pixels row bytes support", fReadPixelsRowBytesSupport);
Chris Daltona8fbeba2019-03-30 00:31:23 -0600199 writer->appendBool("Blacklist CCPR on current driver [workaround]", fDriverBlacklistCCPR);
Chris Dalton7c012082019-07-22 00:45:52 -0400200 writer->appendBool("Blacklist MSAA version of CCPR on current driver [workaround]",
201 fDriverBlacklistMSAACCPR);
Michael Ludwiga21d1962019-01-11 15:26:22 -0500202 writer->appendBool("Clamp-to-border", fClampToBorderSupport);
Brian Osman71a18892017-08-10 10:23:25 -0400203
Brian Osman71a18892017-08-10 10:23:25 -0400204 writer->appendBool("Prefer VRAM Use over flushes [workaround]", fPreferVRAMUseOverFlushes);
Chris Dalton0dffbab2019-03-27 13:08:50 -0600205 writer->appendBool("Prefer more triangles over sample mask [MSAA only]",
206 fPreferTrianglesOverSampleMask);
Robert Phillipsf2ec0242018-03-01 16:51:25 -0500207 writer->appendBool("Avoid stencil buffers [workaround]", fAvoidStencilBuffers);
robertphillips63926682015-08-20 09:39:02 -0700208
cdalton1dd05422015-06-12 09:01:18 -0700209 if (this->advancedBlendEquationSupport()) {
Brian Osman71a18892017-08-10 10:23:25 -0400210 writer->appendHexU32("Advanced Blend Equation Blacklist", fAdvBlendEqBlacklist);
cdalton1dd05422015-06-12 09:01:18 -0700211 }
bsalomondc47ff72015-05-26 12:16:59 -0700212
Brian Osman71a18892017-08-10 10:23:25 -0400213 writer->appendS32("Max Vertex Attributes", fMaxVertexAttributes);
214 writer->appendS32("Max Texture Size", fMaxTextureSize);
215 writer->appendS32("Max Render Target Size", fMaxRenderTargetSize);
Chris Dalton2612bae2018-02-22 13:41:37 -0700216 writer->appendS32("Max Preferred Render Target Size", fMaxPreferredRenderTargetSize);
Brian Osman71a18892017-08-10 10:23:25 -0400217 writer->appendS32("Max Window Rectangles", fMaxWindowRectangles);
Chris Dalton1e6c5b82019-06-17 14:16:49 -0600218 writer->appendS32("Preferred Sample Count for Internal MSAA and Mixed Samples",
Chris Daltona1638a52019-06-24 11:54:24 -0600219 fInternalMultisampleCount);
bsalomondc47ff72015-05-26 12:16:59 -0700220
221 static const char* kBlendEquationSupportNames[] = {
222 "Basic",
223 "Advanced",
224 "Advanced Coherent",
225 };
226 GR_STATIC_ASSERT(0 == kBasic_BlendEquationSupport);
227 GR_STATIC_ASSERT(1 == kAdvanced_BlendEquationSupport);
228 GR_STATIC_ASSERT(2 == kAdvancedCoherent_BlendEquationSupport);
229 GR_STATIC_ASSERT(SK_ARRAY_COUNT(kBlendEquationSupportNames) == kLast_BlendEquationSupport + 1);
230
Brian Osman71a18892017-08-10 10:23:25 -0400231 writer->appendString("Blend Equation Support",
232 kBlendEquationSupportNames[fBlendEquationSupport]);
233 writer->appendString("Map Buffer Support", map_flags_to_string(fMapBufferFlags).c_str());
bsalomondc47ff72015-05-26 12:16:59 -0700234
Brian Osman71a18892017-08-10 10:23:25 -0400235 writer->beginArray("configs");
236
Greg Danieleadfac92019-08-02 09:03:53 -0400237 // TODO: Either move this logic into individual backends dump and do it based on format and
238 // colorType, or have a loop printing out the defaults for given GrColorTypes. Or both.
Brian Osman71a18892017-08-10 10:23:25 -0400239 for (size_t i = 1; i < kGrPixelConfigCnt; ++i) {
Brian Osman0f450ac2017-08-09 20:45:52 +0000240 GrPixelConfig config = static_cast<GrPixelConfig>(i);
Brian Osman80488222017-08-10 13:29:30 -0400241 writer->beginObject(nullptr, false);
Robert Phillipsbac46722019-08-01 15:09:17 -0400242 writer->appendString("name", GrPixelConfigToStr(config));
Greg Danieleadfac92019-08-02 09:03:53 -0400243 //writer->appendS32("max sample count", this->maxRenderTargetSampleCount(config));
Brian Osman71a18892017-08-10 10:23:25 -0400244 writer->appendBool("texturable", this->isConfigTexturable(config));
245 writer->endObject();
Brian Osman0f450ac2017-08-09 20:45:52 +0000246 }
Brian Osman175af0d2017-08-09 14:29:36 -0400247
Brian Osman71a18892017-08-10 10:23:25 -0400248 writer->endArray();
249
250 this->onDumpJSON(writer);
251
252 writer->appendName("shaderCaps");
253 this->shaderCaps()->dumpJSON(writer);
254
255 writer->endObject();
bsalomondc47ff72015-05-26 12:16:59 -0700256}
Kevin Lubickf4def342018-10-04 12:52:50 -0400257#else
258void GrCaps::dumpJSON(SkJSONWriter* writer) const { }
259#endif
Greg Danielf5d87582017-12-18 14:48:15 -0500260
Brian Salomonc67c31c2018-12-06 10:00:03 -0500261bool GrCaps::surfaceSupportsWritePixels(const GrSurface* surface) const {
262 return surface->readOnly() ? false : this->onSurfaceSupportsWritePixels(surface);
263}
264
265bool GrCaps::canCopySurface(const GrSurfaceProxy* dst, const GrSurfaceProxy* src,
266 const SkIRect& srcRect, const SkIPoint& dstPoint) const {
Greg Daniel2c3398d2019-06-19 11:58:01 -0400267 if (dst->readOnly()) {
268 return false;
269 }
270 // Currently we only ever do copies where the configs are the same. This check really should be
271 // checking if the backend formats, color types, and swizzle are compatible. Our copy always
272 // copies exact byte to byte from src to dst so when need to check the if we do this, the dst
273 // has the expected values stored in the right places taking the swizzle into account. For now
274 // we can be more restrictive and just make sure the configs are the same and if we generalize
275 // copies and swizzles more in the future this can be updated.
Brian Salomon947efe22019-07-16 15:36:11 -0400276 if (this->makeConfigSpecific(dst->config(), dst->backendFormat()) !=
277 this->makeConfigSpecific(src->config(), src->backendFormat())) {
Greg Daniel2c3398d2019-06-19 11:58:01 -0400278 return false;
279 }
280 return this->onCanCopySurface(dst, src, srcRect, dstPoint);
Brian Salomonc67c31c2018-12-06 10:00:03 -0500281}
282
Greg Daniel6fa62e22019-08-07 15:52:37 -0400283bool GrCaps::validateSurfaceParams(const SkISize& size, const GrBackendFormat& format,
284 GrPixelConfig config, GrRenderable renderable,
285 int renderTargetSampleCnt, GrMipMapped mipped) const {
286 if (!this->isConfigTexturable(config)) {
Brian Salomonbdecacf2018-02-02 20:32:49 -0500287 return false;
288 }
289
Brian Salomon57111332018-02-05 15:55:54 -0500290 if (GrMipMapped::kYes == mipped && !this->mipMapSupport()) {
291 return false;
Brian Salomonbdecacf2018-02-02 20:32:49 -0500292 }
293
Greg Daniel6fa62e22019-08-07 15:52:37 -0400294 if (size.width() < 1 || size.height() < 1) {
Brian Salomonbdecacf2018-02-02 20:32:49 -0500295 return false;
296 }
297
Brian Salomonf2c2ba92019-07-17 09:59:59 -0400298 if (renderable == GrRenderable::kYes) {
Greg Daniel6fa62e22019-08-07 15:52:37 -0400299 if (!this->isFormatRenderable(format, renderTargetSampleCnt)) {
Brian Salomonbdecacf2018-02-02 20:32:49 -0500300 return false;
301 }
302 int maxRTSize = this->maxRenderTargetSize();
Greg Daniel6fa62e22019-08-07 15:52:37 -0400303 if (size.width() > maxRTSize || size.height() > maxRTSize) {
Brian Salomonbdecacf2018-02-02 20:32:49 -0500304 return false;
305 }
306 } else {
307 // We currently do not support multisampled textures
Brian Salomon27b4d8d2019-07-22 14:23:45 -0400308 if (renderTargetSampleCnt != 1) {
Brian Salomonbdecacf2018-02-02 20:32:49 -0500309 return false;
310 }
311 int maxSize = this->maxTextureSize();
Greg Daniel6fa62e22019-08-07 15:52:37 -0400312 if (size.width() > maxSize || size.height() > maxSize) {
Brian Salomonbdecacf2018-02-02 20:32:49 -0500313 return false;
314 }
315 }
316
317 return true;
318}
Timothy Liang036fdfe2018-06-28 15:50:36 -0400319
Greg Danielc6dc5cf2019-07-17 16:02:00 -0400320GrCaps::SupportedRead GrCaps::supportedReadPixelsColorType(GrColorType srcColorType,
Greg Danielba88ab62019-07-26 09:14:01 -0400321 const GrBackendFormat& srcFormat,
Brian Salomonf30b1c12019-06-20 12:25:02 -0400322 GrColorType dstColorType) const {
Greg Danielba88ab62019-07-26 09:14:01 -0400323 SupportedRead read = this->onSupportedReadPixelsColorType(srcColorType, srcFormat,
324 dstColorType);
325
326 // There are known problems with 24 vs 32 bit BPP with this color type. Just fail for now if
327 // using a transfer buffer.
328 if (GrColorType::kRGB_888x == read.fColorType) {
329 read.fOffsetAlignmentForTransferBuffer = 0;
330 }
Brian Salomon8f8354a2019-07-31 20:12:02 -0400331 // It's very convenient to access 1 byte-per-channel 32 bit color types as uint32_t on the CPU.
Greg Danielba88ab62019-07-26 09:14:01 -0400332 // Make those aligned reads out of the buffer even if the underlying API doesn't require it.
333 auto componentFlags = GrColorTypeComponentFlags(read.fColorType);
334 if ((componentFlags == kRGBA_SkColorTypeComponentFlags ||
Brian Salomon8f8354a2019-07-31 20:12:02 -0400335 componentFlags == kRGB_SkColorTypeComponentFlags ||
336 componentFlags == kAlpha_SkColorTypeComponentFlag ||
337 componentFlags == kGray_SkColorTypeComponentFlag) &&
Greg Danielba88ab62019-07-26 09:14:01 -0400338 GrColorTypeBytesPerPixel(read.fColorType) == 4) {
339 switch (read.fOffsetAlignmentForTransferBuffer & 0b11) {
340 // offset alignment already a multiple of 4
341 case 0:
342 break;
343 // offset alignment is a multiple of 2 but not 4.
344 case 2:
345 read.fOffsetAlignmentForTransferBuffer *= 2;
346 // offset alignment is not a multiple of 2.
347 default:
348 read.fOffsetAlignmentForTransferBuffer *= 4;
349 }
350 }
351 return read;
Brian Salomonf30b1c12019-06-20 12:25:02 -0400352}
Robert Phillips0902c982019-07-16 07:47:56 -0400353
354#ifdef SK_DEBUG
355bool GrCaps::AreConfigsCompatible(GrPixelConfig genericConfig, GrPixelConfig specificConfig) {
356 bool compatible = false;
357
358 switch (genericConfig) {
359 case kAlpha_8_GrPixelConfig:
360 compatible = kAlpha_8_GrPixelConfig == specificConfig || // here bc of the mock context
361 kAlpha_8_as_Alpha_GrPixelConfig == specificConfig ||
362 kAlpha_8_as_Red_GrPixelConfig == specificConfig;
363 break;
364 case kGray_8_GrPixelConfig:
365 compatible = kGray_8_GrPixelConfig == specificConfig || // here bc of the mock context
366 kGray_8_as_Lum_GrPixelConfig == specificConfig ||
367 kGray_8_as_Red_GrPixelConfig == specificConfig;
368 break;
369 case kAlpha_half_GrPixelConfig:
370 compatible = kAlpha_half_GrPixelConfig == specificConfig || // bc of the mock context
Robert Phillipsebab03f2019-07-22 08:48:18 -0400371 kAlpha_half_as_Red_GrPixelConfig == specificConfig ||
372 kAlpha_half_as_Lum_GrPixelConfig == specificConfig;
Robert Phillips0902c982019-07-16 07:47:56 -0400373 break;
374 case kRGB_888_GrPixelConfig:
375 compatible = kRGB_888_GrPixelConfig == specificConfig ||
376 kRGB_888X_GrPixelConfig == specificConfig;
377 break;
378 case kRGBA_8888_GrPixelConfig:
379 compatible = kRGBA_8888_GrPixelConfig == specificConfig ||
380 kBGRA_8888_GrPixelConfig == specificConfig;
381 break;
382 default:
383 compatible = genericConfig == specificConfig;
384 break;
385 }
386
387 if (!compatible) {
388 SkDebugf("Configs are not compatible: %d %d\n", genericConfig, specificConfig);
389 }
390
391 return compatible;
392}
393#endif
Robert Phillips0a15cc62019-07-30 12:49:10 -0400394
395GrBackendFormat GrCaps::getDefaultBackendFormat(GrColorType grColorType,
396 GrRenderable renderable) const {
397 GrBackendFormat format = this->onGetDefaultBackendFormat(grColorType, renderable);
398 if (!this->isFormatTexturable(grColorType, format)) {
399 return {};
400 }
401
402 if (renderable == GrRenderable::kYes) {
Greg Daniel900583a2019-08-06 12:05:31 -0400403 if (!this->isFormatAsColorTypeRenderable(grColorType, format)) {
Robert Phillips0a15cc62019-07-30 12:49:10 -0400404 return {};
405 }
406 }
407
408 return format;
409}
Greg Danieleadfac92019-08-02 09:03:53 -0400410