blob: daffcefb207862c2561cbbd327d287f36848e7d3 [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;
bsalomondc47ff72015-05-26 12:16:59 -070050
bsalomondc47ff72015-05-26 12:16:59 -070051 fBlendEquationSupport = kBasic_BlendEquationSupport;
cdalton1dd05422015-06-12 09:01:18 -070052 fAdvBlendEqBlacklist = 0;
53
bsalomondc47ff72015-05-26 12:16:59 -070054 fMapBufferFlags = kNone_MapFlags;
55
bsalomon7dbd45d2016-03-23 10:40:53 -070056 fMaxVertexAttributes = 0;
egdanielff1d5472015-09-10 08:37:20 -070057 fMaxRenderTargetSize = 1;
Chris Dalton2612bae2018-02-22 13:41:37 -070058 fMaxPreferredRenderTargetSize = 1;
egdanielff1d5472015-09-10 08:37:20 -070059 fMaxTextureSize = 1;
csmartdalton9bc11872016-08-09 12:42:47 -070060 fMaxWindowRectangles = 0;
Chris Daltona1638a52019-06-24 11:54:24 -060061 fInternalMultisampleCount = 0;
bsalomondc47ff72015-05-26 12:16:59 -070062
robertphillipscaef3452015-11-11 13:18:11 -080063 fSuppressPrints = options.fSuppressPrints;
Brian Osman195c05b2017-08-30 15:14:04 -040064#if GR_TEST_UTILS
Jim Van Verthfbdc0802017-05-02 16:15:53 -040065 fWireframeMode = options.fWireframeMode;
Brian Osman195c05b2017-08-30 15:14:04 -040066#else
67 fWireframeMode = false;
68#endif
cdalton397536c2016-03-25 12:15:03 -070069 fBufferMapThreshold = options.fBufferMapThreshold;
Eric Karl5c779752017-05-08 12:02:07 -070070 fAvoidStencilBuffers = false;
Greg Daniel4374e962018-09-28 15:09:47 -040071 fAvoidWritePixelsFastPath = false;
robertphillips63926682015-08-20 09:39:02 -070072
73 fPreferVRAMUseOverFlushes = true;
Adrienne Walkerab7181d2018-05-14 14:02:03 -070074
Chris Dalton0dffbab2019-03-27 13:08:50 -060075 fPreferTrianglesOverSampleMask = false;
76
Michael Ludwigf23a1522018-12-10 11:36:13 -050077 // Default to true, allow older versions of OpenGL to disable explicitly
78 fClampToBorderSupport = true;
79
Adrienne Walkerab7181d2018-05-14 14:02:03 -070080 fDriverBugWorkarounds = options.fDriverBugWorkarounds;
bsalomondc47ff72015-05-26 12:16:59 -070081}
82
bsalomon4ee6bd82015-05-27 13:23:23 -070083void GrCaps::applyOptionsOverrides(const GrContextOptions& options) {
csmartdalton28341fa2016-08-17 10:00:21 -070084 this->onApplyOptionsOverrides(options);
Brian Salomon01b476a2018-01-23 11:06:41 -050085 if (options.fDisableDriverCorrectnessWorkarounds) {
Chris Daltona8fbeba2019-03-30 00:31:23 -060086 SkASSERT(!fDriverBlacklistCCPR);
Brian Salomon01b476a2018-01-23 11:06:41 -050087 SkASSERT(!fAvoidStencilBuffers);
88 SkASSERT(!fAdvBlendEqBlacklist);
Michael Ludwiga21d1962019-01-11 15:26:22 -050089 SkASSERT(!fPerformColorClearsAsDraws);
90 SkASSERT(!fPerformStencilClearsAsDraws);
91 // Don't check the partial-clear workaround, since that is a backend limitation, not a
92 // driver workaround (it just so happens the fallbacks are the same).
93 }
94 if (GrContextOptions::Enable::kNo == options.fUseDrawInsteadOfClear) {
95 fPerformColorClearsAsDraws = false;
96 fPerformStencilClearsAsDraws = false;
97 } else if (GrContextOptions::Enable::kYes == options.fUseDrawInsteadOfClear) {
98 fPerformColorClearsAsDraws = true;
99 fPerformStencilClearsAsDraws = true;
Brian Salomon01b476a2018-01-23 11:06:41 -0500100 }
101
Chris Daltona8fbeba2019-03-30 00:31:23 -0600102 fAllowCoverageCounting = !options.fDisableCoverageCountingPaths;
103
bsalomon4ee6bd82015-05-27 13:23:23 -0700104 fMaxTextureSize = SkTMin(fMaxTextureSize, options.fMaxTextureSizeOverride);
Brian Osman195c05b2017-08-30 15:14:04 -0400105 fMaxTileSize = fMaxTextureSize;
106#if GR_TEST_UTILS
bsalomon8c07b7a2015-11-02 11:36:52 -0800107 // If the max tile override is zero, it means we should use the max texture size.
Brian Osman195c05b2017-08-30 15:14:04 -0400108 if (options.fMaxTileSizeOverride && options.fMaxTileSizeOverride < fMaxTextureSize) {
bsalomon8c07b7a2015-11-02 11:36:52 -0800109 fMaxTileSize = options.fMaxTileSizeOverride;
110 }
Chris Dalton040238b2017-12-18 14:22:34 -0700111 if (options.fSuppressGeometryShaders) {
112 fShaderCaps->fGeometryShaderSupport = false;
113 }
Brian Osman195c05b2017-08-30 15:14:04 -0400114#endif
Chris Dalton1e6c5b82019-06-17 14:16:49 -0600115
csmartdalton28341fa2016-08-17 10:00:21 -0700116 if (fMaxWindowRectangles > GrWindowRectangles::kMaxWindows) {
csmartdalton7535f412016-08-23 06:51:00 -0700117 SkDebugf("WARNING: capping window rectangles at %i. HW advertises support for %i.\n",
118 GrWindowRectangles::kMaxWindows, fMaxWindowRectangles);
csmartdalton28341fa2016-08-17 10:00:21 -0700119 fMaxWindowRectangles = GrWindowRectangles::kMaxWindows;
120 }
Chris Dalton1e6c5b82019-06-17 14:16:49 -0600121
Chris Daltona1638a52019-06-24 11:54:24 -0600122 fInternalMultisampleCount = options.fInternalMultisampleCount;
Chris Dalton1e6c5b82019-06-17 14:16:49 -0600123
Eric Karl5c779752017-05-08 12:02:07 -0700124 fAvoidStencilBuffers = options.fAvoidStencilBuffers;
Adrienne Walkerab7181d2018-05-14 14:02:03 -0700125
126 fDriverBugWorkarounds.applyOverrides(options.fDriverBugWorkarounds);
bsalomon4ee6bd82015-05-27 13:23:23 -0700127}
128
Kevin Lubickf4def342018-10-04 12:52:50 -0400129
130#ifdef SK_ENABLE_DUMP_GPU
131static const char* pixel_config_name(GrPixelConfig config) {
132 switch (config) {
133 case kUnknown_GrPixelConfig: return "Unknown";
134 case kAlpha_8_GrPixelConfig: return "Alpha8";
135 case kAlpha_8_as_Alpha_GrPixelConfig: return "Alpha8_asAlpha";
136 case kAlpha_8_as_Red_GrPixelConfig: return "Alpha8_asRed";
137 case kGray_8_GrPixelConfig: return "Gray8";
138 case kGray_8_as_Lum_GrPixelConfig: return "Gray8_asLum";
139 case kGray_8_as_Red_GrPixelConfig: return "Gray8_asRed";
140 case kRGB_565_GrPixelConfig: return "RGB565";
141 case kRGBA_4444_GrPixelConfig: return "RGBA444";
142 case kRGBA_8888_GrPixelConfig: return "RGBA8888";
143 case kRGB_888_GrPixelConfig: return "RGB888";
Greg Danielf259b8b2019-02-14 09:03:43 -0500144 case kRGB_888X_GrPixelConfig: return "RGB888X";
Jim Van Verth69e57852018-12-05 13:38:59 -0500145 case kRG_88_GrPixelConfig: return "RG88";
Kevin Lubickf4def342018-10-04 12:52:50 -0400146 case kBGRA_8888_GrPixelConfig: return "BGRA8888";
147 case kSRGBA_8888_GrPixelConfig: return "SRGBA8888";
Kevin Lubickf4def342018-10-04 12:52:50 -0400148 case kRGBA_1010102_GrPixelConfig: return "RGBA1010102";
149 case kRGBA_float_GrPixelConfig: return "RGBAFloat";
150 case kRG_float_GrPixelConfig: return "RGFloat";
151 case kAlpha_half_GrPixelConfig: return "AlphaHalf";
152 case kAlpha_half_as_Red_GrPixelConfig: return "AlphaHalf_asRed";
153 case kRGBA_half_GrPixelConfig: return "RGBAHalf";
Brian Osmand0626aa2019-03-11 15:28:06 -0400154 case kRGBA_half_Clamped_GrPixelConfig: return "RGBAHalfClamped";
Jim Van Verth1676cb92019-01-15 13:24:45 -0500155 case kRGB_ETC1_GrPixelConfig: return "RGBETC1";
Robert Phillipsfe18de52019-06-06 17:21:50 -0400156 case kR_16_GrPixelConfig: return "R16";
157 case kRG_1616_GrPixelConfig: return "RG1616";
Robert Phillips66a46032019-06-18 08:00:42 -0400158 // Experimental (for Y416 and mutant P016/P010)
159 case kRGBA_16161616_GrPixelConfig: return "RGBA16161616";
160 case kRG_half_GrPixelConfig: return "RGHalf";
Kevin Lubickf4def342018-10-04 12:52:50 -0400161 }
162 SK_ABORT("Invalid pixel config");
163 return "<invalid>";
164}
165
bsalomondc47ff72015-05-26 12:16:59 -0700166static SkString map_flags_to_string(uint32_t flags) {
167 SkString str;
168 if (GrCaps::kNone_MapFlags == flags) {
169 str = "none";
170 } else {
171 SkASSERT(GrCaps::kCanMap_MapFlag & flags);
172 SkDEBUGCODE(flags &= ~GrCaps::kCanMap_MapFlag);
173 str = "can_map";
174
175 if (GrCaps::kSubset_MapFlag & flags) {
176 str.append(" partial");
177 } else {
178 str.append(" full");
179 }
180 SkDEBUGCODE(flags &= ~GrCaps::kSubset_MapFlag);
Brian Salomon105d7c22019-04-16 13:46:14 -0400181 if (GrCaps::kAsyncRead_MapFlag & flags) {
182 str.append(" async_read");
183 } else {
184 str.append(" sync_read");
185 }
186 SkDEBUGCODE(flags &= ~GrCaps::kAsyncRead_MapFlag);
bsalomondc47ff72015-05-26 12:16:59 -0700187 }
188 SkASSERT(0 == flags); // Make sure we handled all the flags.
189 return str;
190}
191
Brian Osman71a18892017-08-10 10:23:25 -0400192void GrCaps::dumpJSON(SkJSONWriter* writer) const {
193 writer->beginObject();
jvanverth84741b32016-09-30 08:39:02 -0700194
Brian Osman71a18892017-08-10 10:23:25 -0400195 writer->appendBool("MIP Map Support", fMipMapSupport);
196 writer->appendBool("NPOT Texture Tile Support", fNPOTTextureTileSupport);
197 writer->appendBool("sRGB Support", fSRGBSupport);
198 writer->appendBool("sRGB Write Control", fSRGBWriteControl);
Brian Osman71a18892017-08-10 10:23:25 -0400199 writer->appendBool("Reuse Scratch Textures", fReuseScratchTextures);
200 writer->appendBool("Reuse Scratch Buffers", fReuseScratchBuffers);
201 writer->appendBool("Gpu Tracing Support", fGpuTracingSupport);
202 writer->appendBool("Oversized Stencil Support", fOversizedStencilSupport);
203 writer->appendBool("Texture Barrier Support", fTextureBarrierSupport);
Robert Phillips7f861922018-01-30 13:13:42 +0000204 writer->appendBool("Sample Locations Support", fSampleLocationsSupport);
Brian Osman71a18892017-08-10 10:23:25 -0400205 writer->appendBool("Multisample disable support", fMultisampleDisableSupport);
206 writer->appendBool("Instance Attrib Support", fInstanceAttribSupport);
Chris Dalton6ce447a2019-06-23 18:07:38 -0600207 writer->appendBool("Mixed Samples Support", fMixedSamplesSupport);
Chris Dalton27059d32018-01-23 14:06:50 -0700208 writer->appendBool("Use primitive restart", fUsePrimitiveRestart);
Brian Osman71a18892017-08-10 10:23:25 -0400209 writer->appendBool("Prefer client-side dynamic buffers", fPreferClientSideDynamicBuffers);
Chris Dalton344e9032017-12-11 15:42:09 -0700210 writer->appendBool("Prefer fullscreen clears", fPreferFullscreenClears);
Brian Osman71a18892017-08-10 10:23:25 -0400211 writer->appendBool("Must clear buffer memory", fMustClearUploadedBufferData);
Kevin Lubick61a5f0a2019-03-28 09:47:15 -0400212 writer->appendBool("Should initialize textures", fShouldInitializeTextures);
Greg Danielb2acf0a2018-09-12 09:17:11 -0400213 writer->appendBool("Supports importing AHardwareBuffers", fSupportsAHardwareBufferImages);
Brian Osman71a18892017-08-10 10:23:25 -0400214 writer->appendBool("Fence sync support", fFenceSyncSupport);
Brian Salomon9ff5acb2019-05-08 09:04:47 -0400215 writer->appendBool("Semaphore support", fSemaphoreSupport);
Brian Osman71a18892017-08-10 10:23:25 -0400216 writer->appendBool("Cross context texture support", fCrossContextTextureSupport);
Brian Osman499bf1a2018-09-17 11:32:42 -0400217 writer->appendBool("Half float vertex attribute support", fHalfFloatVertexAttributeSupport);
Brian Salomonf7232642018-09-19 08:58:08 -0400218 writer->appendBool("Specify GeometryProcessor textures as a dynamic state array",
219 fDynamicStateArrayGeometryProcessorTextureSupport);
Michael Ludwiga21d1962019-01-11 15:26:22 -0500220 writer->appendBool("Use draws for partial clears", fPerformPartialClearsAsDraws);
221 writer->appendBool("Use draws for color clears", fPerformColorClearsAsDraws);
222 writer->appendBool("Use draws for stencil clip clears", fPerformStencilClearsAsDraws);
Chris Daltona8fbeba2019-03-30 00:31:23 -0600223 writer->appendBool("Allow coverage counting shortcuts", fAllowCoverageCounting);
Brian Salomone05ba5a2019-04-08 11:59:07 -0400224 writer->appendBool("Supports transfer buffers", fTransferBufferSupport);
Brian Salomon1047a492019-07-02 12:25:21 -0400225 writer->appendBool("Write pixels row bytes support", fWritePixelsRowBytesSupport);
226 writer->appendBool("Read pixels row bytes support", fReadPixelsRowBytesSupport);
Chris Daltona8fbeba2019-03-30 00:31:23 -0600227 writer->appendBool("Blacklist CCPR on current driver [workaround]", fDriverBlacklistCCPR);
Michael Ludwiga21d1962019-01-11 15:26:22 -0500228 writer->appendBool("Clamp-to-border", fClampToBorderSupport);
Brian Osman71a18892017-08-10 10:23:25 -0400229
Brian Osman71a18892017-08-10 10:23:25 -0400230 writer->appendBool("Prefer VRAM Use over flushes [workaround]", fPreferVRAMUseOverFlushes);
Chris Dalton0dffbab2019-03-27 13:08:50 -0600231 writer->appendBool("Prefer more triangles over sample mask [MSAA only]",
232 fPreferTrianglesOverSampleMask);
Robert Phillipsf2ec0242018-03-01 16:51:25 -0500233 writer->appendBool("Avoid stencil buffers [workaround]", fAvoidStencilBuffers);
robertphillips63926682015-08-20 09:39:02 -0700234
cdalton1dd05422015-06-12 09:01:18 -0700235 if (this->advancedBlendEquationSupport()) {
Brian Osman71a18892017-08-10 10:23:25 -0400236 writer->appendHexU32("Advanced Blend Equation Blacklist", fAdvBlendEqBlacklist);
cdalton1dd05422015-06-12 09:01:18 -0700237 }
bsalomondc47ff72015-05-26 12:16:59 -0700238
Brian Osman71a18892017-08-10 10:23:25 -0400239 writer->appendS32("Max Vertex Attributes", fMaxVertexAttributes);
240 writer->appendS32("Max Texture Size", fMaxTextureSize);
241 writer->appendS32("Max Render Target Size", fMaxRenderTargetSize);
Chris Dalton2612bae2018-02-22 13:41:37 -0700242 writer->appendS32("Max Preferred Render Target Size", fMaxPreferredRenderTargetSize);
Brian Osman71a18892017-08-10 10:23:25 -0400243 writer->appendS32("Max Window Rectangles", fMaxWindowRectangles);
Chris Dalton1e6c5b82019-06-17 14:16:49 -0600244 writer->appendS32("Preferred Sample Count for Internal MSAA and Mixed Samples",
Chris Daltona1638a52019-06-24 11:54:24 -0600245 fInternalMultisampleCount);
bsalomondc47ff72015-05-26 12:16:59 -0700246
247 static const char* kBlendEquationSupportNames[] = {
248 "Basic",
249 "Advanced",
250 "Advanced Coherent",
251 };
252 GR_STATIC_ASSERT(0 == kBasic_BlendEquationSupport);
253 GR_STATIC_ASSERT(1 == kAdvanced_BlendEquationSupport);
254 GR_STATIC_ASSERT(2 == kAdvancedCoherent_BlendEquationSupport);
255 GR_STATIC_ASSERT(SK_ARRAY_COUNT(kBlendEquationSupportNames) == kLast_BlendEquationSupport + 1);
256
Brian Osman71a18892017-08-10 10:23:25 -0400257 writer->appendString("Blend Equation Support",
258 kBlendEquationSupportNames[fBlendEquationSupport]);
259 writer->appendString("Map Buffer Support", map_flags_to_string(fMapBufferFlags).c_str());
bsalomondc47ff72015-05-26 12:16:59 -0700260
Brian Salomonbdecacf2018-02-02 20:32:49 -0500261 SkASSERT(!this->isConfigRenderable(kUnknown_GrPixelConfig));
Brian Osman0f450ac2017-08-09 20:45:52 +0000262 SkASSERT(!this->isConfigTexturable(kUnknown_GrPixelConfig));
Brian Osman175af0d2017-08-09 14:29:36 -0400263
Brian Osman71a18892017-08-10 10:23:25 -0400264 writer->beginArray("configs");
265
266 for (size_t i = 1; i < kGrPixelConfigCnt; ++i) {
Brian Osman0f450ac2017-08-09 20:45:52 +0000267 GrPixelConfig config = static_cast<GrPixelConfig>(i);
Brian Osman80488222017-08-10 13:29:30 -0400268 writer->beginObject(nullptr, false);
Brian Osman71a18892017-08-10 10:23:25 -0400269 writer->appendString("name", pixel_config_name(config));
Brian Salomonbdecacf2018-02-02 20:32:49 -0500270 writer->appendS32("max sample count", this->maxRenderTargetSampleCount(config));
Brian Osman71a18892017-08-10 10:23:25 -0400271 writer->appendBool("texturable", this->isConfigTexturable(config));
272 writer->endObject();
Brian Osman0f450ac2017-08-09 20:45:52 +0000273 }
Brian Osman175af0d2017-08-09 14:29:36 -0400274
Brian Osman71a18892017-08-10 10:23:25 -0400275 writer->endArray();
276
277 this->onDumpJSON(writer);
278
279 writer->appendName("shaderCaps");
280 this->shaderCaps()->dumpJSON(writer);
281
282 writer->endObject();
bsalomondc47ff72015-05-26 12:16:59 -0700283}
Kevin Lubickf4def342018-10-04 12:52:50 -0400284#else
285void GrCaps::dumpJSON(SkJSONWriter* writer) const { }
286#endif
Greg Danielf5d87582017-12-18 14:48:15 -0500287
Brian Salomonc67c31c2018-12-06 10:00:03 -0500288bool GrCaps::surfaceSupportsWritePixels(const GrSurface* surface) const {
289 return surface->readOnly() ? false : this->onSurfaceSupportsWritePixels(surface);
290}
291
Brian Salomon26de56e2019-04-10 12:14:26 -0400292size_t GrCaps::transferFromOffsetAlignment(GrColorType bufferColorType) const {
Brian Salomone05ba5a2019-04-08 11:59:07 -0400293 if (!this->transferBufferSupport()) {
Brian Salomon26de56e2019-04-10 12:14:26 -0400294 return 0;
Brian Salomone05ba5a2019-04-08 11:59:07 -0400295 }
Brian Salomon26de56e2019-04-10 12:14:26 -0400296 size_t result = this->onTransferFromOffsetAlignment(bufferColorType);
297 if (!result) {
298 return 0;
299 }
300 // It's very convenient to access 1 byte-per-channel 32 bitvRGB/RGBA color types as uint32_t.
301 // Make those aligned reads out of the buffer even if the underlying API doesn't require it.
302 auto componentFlags = GrColorTypeComponentFlags(bufferColorType);
303 if ((componentFlags == kRGBA_SkColorTypeComponentFlags ||
304 componentFlags == kRGB_SkColorTypeComponentFlags) &&
305 GrColorTypeBytesPerPixel(bufferColorType) == 4) {
306 switch (result & 0b11) {
307 // offset alignment already a multiple of 4
308 case 0: return result;
309 // offset alignment is a multiple of 2 but not 4.
310 case 2: return 2 * result;
311 // offset alignment is not a multiple of 2.
312 default: return 4 * result;
313 }
314 }
315 return result;
Brian Salomone05ba5a2019-04-08 11:59:07 -0400316}
317
Brian Salomonc67c31c2018-12-06 10:00:03 -0500318bool GrCaps::canCopySurface(const GrSurfaceProxy* dst, const GrSurfaceProxy* src,
319 const SkIRect& srcRect, const SkIPoint& dstPoint) const {
Greg Daniel2c3398d2019-06-19 11:58:01 -0400320 if (dst->readOnly()) {
321 return false;
322 }
323 // Currently we only ever do copies where the configs are the same. This check really should be
324 // checking if the backend formats, color types, and swizzle are compatible. Our copy always
325 // copies exact byte to byte from src to dst so when need to check the if we do this, the dst
326 // has the expected values stored in the right places taking the swizzle into account. For now
327 // we can be more restrictive and just make sure the configs are the same and if we generalize
328 // copies and swizzles more in the future this can be updated.
329 if (dst->config() != src->config()) {
330 return false;
331 }
332 return this->onCanCopySurface(dst, src, srcRect, dstPoint);
Brian Salomonc67c31c2018-12-06 10:00:03 -0500333}
334
Brian Salomonbdecacf2018-02-02 20:32:49 -0500335bool GrCaps::validateSurfaceDesc(const GrSurfaceDesc& desc, GrMipMapped mipped) const {
336 if (!this->isConfigTexturable(desc.fConfig)) {
337 return false;
338 }
339
Brian Salomon57111332018-02-05 15:55:54 -0500340 if (GrMipMapped::kYes == mipped && !this->mipMapSupport()) {
341 return false;
Brian Salomonbdecacf2018-02-02 20:32:49 -0500342 }
343
344 if (desc.fWidth < 1 || desc.fHeight < 1) {
345 return false;
346 }
347
348 if (SkToBool(desc.fFlags & kRenderTarget_GrSurfaceFlag)) {
349 if (0 == this->getRenderTargetSampleCount(desc.fSampleCnt, desc.fConfig)) {
350 return false;
351 }
352 int maxRTSize = this->maxRenderTargetSize();
353 if (desc.fWidth > maxRTSize || desc.fHeight > maxRTSize) {
354 return false;
355 }
356 } else {
357 // We currently do not support multisampled textures
358 if (desc.fSampleCnt > 1) {
359 return false;
360 }
361 int maxSize = this->maxTextureSize();
362 if (desc.fWidth > maxSize || desc.fHeight > maxSize) {
363 return false;
364 }
365 }
366
367 return true;
368}
Timothy Liang036fdfe2018-06-28 15:50:36 -0400369
Brian Salomonf30b1c12019-06-20 12:25:02 -0400370GrCaps::SupportedRead GrCaps::supportedReadPixelsColorType(GrPixelConfig config,
371 const GrBackendFormat&,
372 GrColorType dstColorType) const {
373 return SupportedRead{GrSwizzle::RGBA(), GrPixelConfigToColorType(config)};
374}
Robert Phillips0902c982019-07-16 07:47:56 -0400375
376#ifdef SK_DEBUG
377bool GrCaps::AreConfigsCompatible(GrPixelConfig genericConfig, GrPixelConfig specificConfig) {
378 bool compatible = false;
379
380 switch (genericConfig) {
381 case kAlpha_8_GrPixelConfig:
382 compatible = kAlpha_8_GrPixelConfig == specificConfig || // here bc of the mock context
383 kAlpha_8_as_Alpha_GrPixelConfig == specificConfig ||
384 kAlpha_8_as_Red_GrPixelConfig == specificConfig;
385 break;
386 case kGray_8_GrPixelConfig:
387 compatible = kGray_8_GrPixelConfig == specificConfig || // here bc of the mock context
388 kGray_8_as_Lum_GrPixelConfig == specificConfig ||
389 kGray_8_as_Red_GrPixelConfig == specificConfig;
390 break;
391 case kAlpha_half_GrPixelConfig:
392 compatible = kAlpha_half_GrPixelConfig == specificConfig || // bc of the mock context
393 kAlpha_half_as_Red_GrPixelConfig == specificConfig;
394 break;
395 case kRGB_888_GrPixelConfig:
396 compatible = kRGB_888_GrPixelConfig == specificConfig ||
397 kRGB_888X_GrPixelConfig == specificConfig;
398 break;
399 case kRGBA_8888_GrPixelConfig:
400 compatible = kRGBA_8888_GrPixelConfig == specificConfig ||
401 kBGRA_8888_GrPixelConfig == specificConfig;
402 break;
403 default:
404 compatible = genericConfig == specificConfig;
405 break;
406 }
407
408 if (!compatible) {
409 SkDebugf("Configs are not compatible: %d %d\n", genericConfig, specificConfig);
410 }
411
412 return compatible;
413}
414#endif