Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
GrGLCaps.h
Go to the documentation of this file.
1/*
2 * Copyright 2012 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
8
9#ifndef GrGLCaps_DEFINED
10#define GrGLCaps_DEFINED
11
19#include "src/gpu/Swizzle.h"
23
24#include <cstdint>
25#include <memory>
26#include <vector>
27
28class GrGLContextInfo;
29class GrProgramInfo;
30class GrRenderTarget;
32class GrSurface;
33class GrSurfaceProxy;
34class SkJSONWriter;
36struct GrContextOptions;
37struct GrGLInterface;
38struct GrShaderCaps;
39struct SkIRect;
40struct SkRect;
41
43
44/**
45 * Stores some capabilities of a GL context. Most are determined by the GL
46 * version and the extensions string. It also tracks formats that have passed
47 * the FBO completeness test.
48 */
49class GrGLCaps : public GrCaps {
50public:
51 /**
52 * The type of MSAA for FBOs supported. Different extensions have different
53 * semantics of how / when a resolve is performed.
54 */
55 enum MSFBOType {
56 /**
57 * no support for MSAA FBOs
58 */
60 /**
61 * OpenGL 3.0+, OpenGL ES 3.0+, GL_ARB_framebuffer_object,
62 * GL_CHROMIUM_framebuffer_multisample, GL_ANGLE_framebuffer_multisample,
63 * or GL_EXT_framebuffer_multisample
64 */
66 /**
67 * GL_APPLE_framebuffer_multisample ES extension
68 */
70 /**
71 * GL_IMG_multisampled_render_to_texture. This variation does not have MSAA renderbuffers.
72 * Instead the texture is multisampled when bound to the FBO and then resolved automatically
73 * when read. It also defines an alternate value for GL_MAX_SAMPLES (which we call
74 * GR_GL_MAX_SAMPLES_IMG).
75 */
77 /**
78 * GL_EXT_multisampled_render_to_texture. Same as the IMG one above but uses the standard
79 * GL_MAX_SAMPLES value.
80 */
82 };
83
93
96 kDiscard_InvalidateFBType, //<! glDiscardFramebuffer()
97 kInvalidate_InvalidateFBType, //<! glInvalidateFramebuffer()
98 };
99
101 kNone,
102 kNullData, // Call glBufferData with a null data pointer.
103 kInvalidate // glInvalidateBufferData
104 };
105
108 kMapBuffer_MapBufferType, // glMapBuffer()
109 kMapBufferRange_MapBufferType, // glMapBufferRange()
110 kChromium_MapBufferType, // GL_CHROMIUM_map_sub
111 };
112
114 kNone,
115 kNV_PBO, // NV_pixel_buffer_object
116 kARB_PBO, // ARB_pixel_buffer_object
117 kChromium, // CHROMIUM_pixel_transfer_buffer_object
118 };
119
120 enum class FenceType {
121 kNone,
124 };
125
126 enum class MultiDrawType {
127 kNone,
128 kMultiDrawIndirect, // ARB_multi_draw_indirect, EXT_multi_draw_indirect, or GL 4.3 core.
129 kANGLEOrWebGL // ANGLE_base_vertex_base_instance or
130 // WEBGL_draw_instanced_base_vertex_base_instance
131 };
132
138
139 /**
140 * Initializes the GrGLCaps to the set of features supported in the current
141 * OpenGL context accessible via ctxInfo.
142 */
143 GrGLCaps(const GrContextOptions& contextOptions, const GrGLContextInfo& ctxInfo,
144 const GrGLInterface* glInterface);
145
146 bool isFormatSRGB(const GrBackendFormat&) const override;
147
148 bool isFormatTexturable(const GrBackendFormat&, GrTextureType) const override;
149 bool isFormatTexturable(GrGLFormat) const;
150
152 int sampleCount = 1) const override;
153 bool isFormatRenderable(const GrBackendFormat& format, int sampleCount) const override;
154 bool isFormatRenderable(GrGLFormat format, int sampleCount) const {
155 return sampleCount <= this->maxRenderTargetSampleCount(format);
156 }
157
158 int getRenderTargetSampleCount(int requestedCount,
159 const GrBackendFormat& format) const override {
160 return this->getRenderTargetSampleCount(requestedCount,
162 }
163 int getRenderTargetSampleCount(int requestedCount, GrGLFormat) const;
164
169
170 float maxTextureMaxAnisotropy() const { return fMaxTextureMaxAnisotropy; }
171
172 bool isFormatCopyable(const GrBackendFormat&) const override;
173
175
177 int idx = static_cast<int>(colorType);
178 return fColorTypeToFormatTable[idx];
179 }
180
181 /**
182 * Gets the internal format to use with glTexImage...() and glTexStorage...(). May be sized or
183 * base depending upon the GL. Not applicable to compressed textures.
184 */
186 return this->getFormatInfo(format).fInternalFormatForTexImageOrStorage;
187 }
188
189 /**
190 * Gets the external format and type to pass to glTexImage2D with nullptr to create an
191 * uninitialized texture. See getTexImageOrStorageInternalFormat() for the internal format.
192 */
193 void getTexImageExternalFormatAndType(GrGLFormat surfaceFormat, GrGLenum* externalFormat,
194 GrGLenum* externalType) const;
195
196 /**
197 * Given a src data color type and a color type interpretation for a texture of a given format
198 * this provides the external GL format and type to use with glTexSubImage2d. The color types
199 * should originate from supportedWritePixelsColorType().
200 */
201 void getTexSubImageExternalFormatAndType(GrGLFormat surfaceFormat, GrColorType surfaceColorType,
202 GrColorType memoryColorType, GrGLenum* externalFormat,
203 GrGLenum* externalType) const;
204
205 /**
206 * Gets the external format, type, and bytes per pixel to use when uploading solid color data
207 * via glTexSubImage...() to clear the texture at creation.
208 */
210 GrGLenum* externalFormat,
211 GrGLenum* externalType,
212 GrColorType* colorType) const;
213
214 void getReadPixelsFormat(GrGLFormat surfaceFormat, GrColorType surfaceColorType,
215 GrColorType memoryColorType, GrGLenum* externalFormat,
216 GrGLenum* externalType) const;
217
218 /**
219 * Gets an array of legal stencil formats. These formats are not guaranteed
220 * to be supported by the driver but are legal GLenum names given the GL
221 * version and extensions supported.
222 */
224 return fStencilFormats;
225 }
226
228
229 /**
230 * Would it be useful to check GL_IMPLEMENTATION_READ_FORMAT and _TYPE for this format to
231 * detect more efficient glReadPixels arguments?
232 */
234
235 /**
236 * Let caps know the result of GL_IMPLEMENTATION_READ_FORMAT and _TYPE query for a format
237 * to update supported glReadPixels arguments.
238 */
240 GrGLenum readFormat,
241 GrGLenum readType) const;
242
243 /**
244 * Gets the internal format to use with glRenderbufferStorageMultisample...(). May be sized or
245 * base depending upon the GL. Not applicable to compressed textures.
246 */
248 return this->getFormatInfo(format).fInternalFormatForRenderbuffer;
249 }
250
251 /**
252 * Gets the default external type to use with glTex[Sub]Image... when the data pointer is null.
253 */
255 return this->getFormatInfo(format).fDefaultExternalType;
256 }
257
258 /**
259 * Has a stencil format index been found for the format (or we've found that no format works).
260 */
262 return this->getFormatInfo(format).fStencilFormatIndex != FormatInfo::kUnknown_StencilIndex;
263 }
264
265 /**
266 * Gets the stencil format index for the format. This assumes
267 * hasStencilFormatBeenDeterminedForFormat has already been checked. Returns a value < 0 if
268 * no stencil format is supported with the format. Otherwise, returned index refers to the array
269 * returned by stencilFormats().
270 */
273 return this->getFormatInfo(format).fStencilFormatIndex;
274 }
275
276 /**
277 * If index is >= 0 this records an index into stencilFormats() as the best stencil format for
278 * the format. If < 0 it records that the format has no supported stencil format index.
279 */
281
282 /**
283 * Reports the type of MSAA FBO support.
284 */
285 MSFBOType msFBOType() const { return fMSFBOType; }
286
287 /**
288 * Does the preferred MSAA FBO extension have MSAA renderbuffers?
289 */
291 return kNone_MSFBOType != fMSFBOType &&
292 kES_IMG_MsToTexture_MSFBOType != fMSFBOType &&
293 kES_EXT_MsToTexture_MSFBOType != fMSFBOType;
294 }
295
296 /**
297 * Is it unsupported to only resolve a sub-rectangle of a framebuffer?
298 */
300 SkASSERT(fMSFBOType != kNone_MSFBOType);
301 return fMSFBOType == kES_Apple_MSFBOType ||
302 (fBlitFramebufferFlags & kResolveMustBeFull_BlitFrambufferFlag);
303 }
304
305 /**
306 * Can we resolve a single-sample framebuffer into an MSAA framebuffer?
307 */
309 SkASSERT(fMSFBOType != kNone_MSFBOType);
310 return fMSFBOType != kES_Apple_MSFBOType &&
311 !(fBlitFramebufferFlags & GrGLCaps::kNoMSAADst_BlitFramebufferFlag);
312 }
313
314 /**
315 * Is the MSAA FBO extension one where the texture is multisampled when bound to an FBO and
316 * then implicitly resolved when read.
317 */
319 return kES_IMG_MsToTexture_MSFBOType == fMSFBOType ||
320 kES_EXT_MsToTexture_MSFBOType == fMSFBOType;
321 }
322
323 InvalidateFBType invalidateFBType() const { return fInvalidateFBType; }
324
325 /// What type of buffer mapping is supported?
326 MapBufferType mapBufferType() const { return fMapBufferType; }
327
328 /// What type of transfer buffer is supported?
329 TransferBufferType transferBufferType() const { return fTransferBufferType; }
330
331 /** Supports using GrGLsync. */
332 bool fenceSyncSupport() const { return fFenceSyncSupport; }
333
334 /// How is GrGLsync implemented?
335 FenceType fenceType() const { return fFenceType; }
336
337 /// How are multi draws implemented (if at all)?
338 MultiDrawType multiDrawType() const { return fMultiDrawType; }
339
340 /// How is restricting sampled miplevels in onRegenerateMipmapLevels implemented?
341 RegenerateMipmapType regenerateMipmapType() const { return fRegenerateMipmapType; }
342
343 /// The maximum number of fragment uniform vectors (GLES has min. 16).
344 int maxFragmentUniformVectors() const { return fMaxFragmentUniformVectors; }
345
346 /// Is there support for GL_PACK_REVERSE_ROW_ORDER
347 bool packFlipYSupport() const { return fPackFlipYSupport; }
348
349 /// Is there support for texture parameter GL_TEXTURE_USAGE
350 bool textureUsageSupport() const { return fTextureUsageSupport; }
351
352 /// Is GL_ARB_IMAGING supported
353 bool imagingSupport() const { return fImagingSupport; }
354
355 /// Is there support for Vertex Array Objects?
356 bool vertexArrayObjectSupport() const { return fVertexArrayObjectSupport; }
357
358 /// Is there support for GL_KHR_debug?
359 bool debugSupport() const { return fDebugSupport; }
360
361 /// Is there support for ES2 compatability?
362 bool ES2CompatibilitySupport() const { return fES2CompatibilitySupport; }
363
364 /// Is there support for glDrawRangeElements?
365 bool drawRangeElementsSupport() const { return fDrawRangeElementsSupport; }
366
367 /// Are the glDraw*Base(VertexBase)Instance methods, and baseInstance fields in indirect draw
368 //commands supported?
369 bool baseVertexBaseInstanceSupport() const { return fBaseVertexBaseInstanceSupport; }
370
372
373 SupportedWrite supportedWritePixelsColorType(GrColorType surfaceColorType,
374 const GrBackendFormat& surfaceFormat,
375 GrColorType srcColorType) const override;
376
377 bool isCoreProfile() const { return fIsCoreProfile; }
378
379 bool bindFragDataLocationSupport() const { return fBindFragDataLocationSupport; }
380
381 bool bindUniformLocationSupport() const { return fBindUniformLocationSupport; }
382
383 /// Are textures with GL_TEXTURE_RECTANGLE type supported.
384 bool rectangleTextureSupport() const { return fRectangleTextureSupport; }
385
386 /// Can set the BASE and MAX mip map level.
387 bool mipmapLevelControlSupport() const { return fMipmapLevelControlSupport; }
388
389 /// Can set the MIN/MAX LOD value.
390 bool mipmapLodControlSupport() const { return fMipmapLodControlSupport; }
391
392 bool doManualMipmapping() const { return fDoManualMipmapping; }
393
394 void onDumpJSON(SkJSONWriter*) const override;
395
396 InvalidateBufferType invalidateBufferType() const { return fInvalidateBufferType; }
397
398 // Certain Intel GPUs on Mac fail to clear if the glClearColor is made up of only 1s and 0s.
399 bool clearToBoundaryValuesIsBroken() const { return fClearToBoundaryValuesIsBroken; }
400
401 /// glClearTex(Sub)Image support
402 bool clearTextureSupport() const { return fClearTextureSupport; }
403
404 // Adreno/MSAA drops a draw on the imagefiltersbase GM if the base vertex param to
405 // glDrawArrays is nonzero.
406 // https://bugs.chromium.org/p/skia/issues/detail?id=6650
407 bool drawArraysBaseVertexIsBroken() const { return fDrawArraysBaseVertexIsBroken; }
408
409 // If true then we must use an intermediate surface to perform partial updates to unorm textures
410 // that have ever been bound to a FBO.
412 return fDisallowTexSubImageForUnormConfigTexturesEverBoundToFBO;
413 }
414
415 // Use an intermediate surface to write pixels (full or partial overwrite) to into a texture
416 // that is bound to an FBO.
418 return fUseDrawInsteadOfAllRenderTargetWrites;
419 }
420
421 // At least some Adreno 3xx drivers draw lines incorrectly after drawing non-lines. Toggling
422 // face culling on and off seems to resolve this.
424 return fRequiresCullFaceEnableDisableWhenDrawingLinesAfterNonLines;
425 }
426
427 // Older Android versions seem to have an issue with setting GL_TEXTURE_BASE_LEVEL or
428 // GL_TEXTURE_MAX_LEVEL for GL_TEXTURE_EXTERNAL_OES textures.
430 return fDontSetBaseOrMaxLevelForExternalTextures;
431 }
432
433 // PowerVRGX6250 drops every pixel if we modify the sample mask while color writes are disabled.
434 bool neverDisableColorWrites() const { return fNeverDisableColorWrites; }
435
436 // Texture parameters must be used to enable MIP mapping even when a sampler object is used.
438 return fMustSetAnyTexParameterToEnableMipmapping;
439 }
440
441 // Whether we must reset the blend function to not reference src2 when disabling blending after
442 // previously referencing src2.
444 return fMustResetBlendFuncBetweenDualSourceAndDisable;
445 }
446
447 // Before changing the sample count of a texture bound to an FBO with
448 // glFramebufferTexture2DMultisample() temporarily bind texture 0 to avoid corruption int the
449 // texture contents.
451 return fBindTexture0WhenChangingTextureFBOMultisampleCount;
452 }
453
454 // After using glCheckFramebufferStatus() bind 0 to the color attachment and then rebind the
455 // original color attachment.
457 return fRebindColorAttachmentAfterCheckFramebufferStatus;
458 }
459
460 // During writePixels, call glFlush() before issuing glTexSubImage2D().
462 return fFlushBeforeWritePixels;
463 }
464
465 // Returns the observed maximum number of instances the driver can handle in a single draw call
466 // without crashing, or 'pendingInstanceCount' if this workaround is not necessary.
467 // NOTE: the return value may be larger than pendingInstanceCount.
468 int maxInstancesPerDrawWithoutCrashing(int pendingInstanceCount) const {
469 return (fMaxInstancesPerDrawWithoutCrashing)
470 ? fMaxInstancesPerDrawWithoutCrashing : pendingInstanceCount;
471 }
472
473 bool canCopyTexSubImage(GrGLFormat dstFormat, bool dstHasMSAARenderBuffer,
474 const GrTextureType* dstTypeIfTexture,
475 GrGLFormat srcFormat, bool srcHasMSAARenderBuffer,
476 const GrTextureType* srcTypeIfTexture) const;
477 bool canCopyAsBlit(GrGLFormat dstFormat, int dstSampleCnt,
478 const GrTextureType* dstTypeIfTexture,
479 GrGLFormat srcFormat, int srcSampleCnt,
480 const GrTextureType* srcTypeIfTexture,
481 const SkRect& srcBounds, bool srcBoundsExact,
482 const SkIRect& srcRect, const SkIRect& dstRect) const;
483 bool canCopyAsDraw(GrGLFormat dstFormat, bool srcIsTexturable, bool scalingCopy) const;
484
485 DstCopyRestrictions getDstCopyRestrictions(const GrRenderTargetProxy* src,
486 GrColorType) const override;
487
488 bool programBinarySupport() const { return fProgramBinarySupport; }
489 bool programParameterSupport() const { return fProgramParameterSupport; }
490 bool programBinaryFormatIsValid(GrGLenum binaryFormat) const;
491
492 /** Are sampler objects available in this GL? */
493 bool samplerObjectSupport() const { return fSamplerObjectSupport; }
494
495 /**
496 * Are we using sampler objects in favor of texture parameters? (This will only be true if
497 * samplerObjectSupport()).
498 */
499 bool useSamplerObjects() const { return fUseSamplerObjects; }
500
501 bool textureSwizzleSupport() const { return fTextureSwizzleSupport; }
502
503 bool tiledRenderingSupport() const { return fTiledRenderingSupport; }
504
505 bool fbFetchRequiresEnablePerSample() const { return fFBFetchRequiresEnablePerSample; }
506
507 /* Is there support for enabling/disabling sRGB writes for sRGB-capable color buffers? */
508 bool srgbWriteControl() const { return fSRGBWriteControl; }
509
510 /**
511 * Skip checks for GL errors and framebuffer completeness. Note that this does not skip
512 * checking shader compilation and program linking status.
513 */
514 bool skipErrorChecks() const { return fSkipErrorChecks; }
515
516 bool clientCanDisableMultisample() const { return fClientCanDisableMultisample; }
517
519
521
522 uint64_t computeFormatKey(const GrBackendFormat&) const override;
523
525 const GrProgramInfo&,
526 ProgramDescOverrideFlags) const override;
527
528#if defined(GR_TEST_UTILS)
529 GrGLStandard standard() const { return fStandard; }
530
531 std::vector<GrTest::TestFormatColorTypeCombination> getTestingCombinations() const override;
532#endif
533
534private:
535 enum ExternalFormatUsage {
536 kTexImage_ExternalFormatUsage,
537 kReadPixels_ExternalFormatUsage,
538 };
539 void getExternalFormat(GrGLFormat surfaceFormat, GrColorType surfaceColorType,
540 GrColorType memoryColorType, ExternalFormatUsage usage,
541 GrGLenum* externalFormat, GrGLenum* externalType) const;
542
543 void init(const GrContextOptions&, const GrGLContextInfo&, const GrGLInterface*);
544 void initGLSL(const GrGLContextInfo&, const GrGLInterface*);
545
546 struct FormatWorkarounds {
547 bool fDisableSRGBRenderWithMSAAForMacAMD = false;
548 bool fDisableRGBA16FTexStorageForCrBug1008003 = false;
549 bool fDisableBGRATextureStorageForIntelWindowsES = false;
550 bool fDisableLuminance16F = false;
551 bool fDisableTexStorage = false;
552 bool fDisallowDirectRG8ReadPixels = false;
553 bool fDisallowBGRA8ReadPixels = false;
554 bool fDisallowR8ForPowerVRSGX54x = false;
555 bool fDisallowUnorm16Transfers = false;
556 bool fDisallowTextureUnorm16 = false;
557 bool fDisallowETC2Compression = false;
558 };
559
560 void applyDriverCorrectnessWorkarounds(const GrGLContextInfo&, const GrContextOptions&,
561 const GrGLInterface*,
562 GrShaderCaps*, FormatWorkarounds*);
563
565
567
568 void initFSAASupport(const GrContextOptions& contextOptions, const GrGLContextInfo&,
569 const GrGLInterface*);
570 void initBlendEqationSupport(const GrGLContextInfo&);
571 void initStencilSupport(const GrGLContextInfo&);
572 // This must be called after initFSAASupport().
573 void initFormatTable(const GrGLContextInfo&, const GrGLInterface*, const FormatWorkarounds&);
574 void setupSampleCounts(const GrGLContextInfo&, const GrGLInterface*);
575 bool onSurfaceSupportsWritePixels(const GrSurface*) const override;
576 bool onCanCopySurface(const GrSurfaceProxy* dst, const SkIRect& dstRect,
577 const GrSurfaceProxy* src, const SkIRect& srcRect) const override;
580
582 GrColorType) const override;
583
585
587
588 bool onSupportsDynamicMSAA(const GrRenderTargetProxy*) const override;
589
591
593 skia_private::TArray<GrGLenum, true> fProgramBinaryFormats;
594
595 int fMaxFragmentUniformVectors = 0;
596 float fMaxTextureMaxAnisotropy = 1.f;
597
598 MSFBOType fMSFBOType = kNone_MSFBOType;
599 InvalidateFBType fInvalidateFBType = kNone_InvalidateFBType;
601 MapBufferType fMapBufferType = kNone_MapBufferType;
602 TransferBufferType fTransferBufferType = TransferBufferType::kNone;
603 FenceType fFenceType = FenceType::kNone;
604 MultiDrawType fMultiDrawType = MultiDrawType::kNone;
606
607 bool fPackFlipYSupport : 1;
608 bool fTextureUsageSupport : 1;
609 bool fImagingSupport : 1;
610 bool fVertexArrayObjectSupport : 1;
611 bool fDebugSupport : 1;
612 bool fES2CompatibilitySupport : 1;
613 bool fDrawRangeElementsSupport : 1;
614 bool fBaseVertexBaseInstanceSupport : 1;
615 bool fIsCoreProfile : 1;
616 bool fBindFragDataLocationSupport : 1;
617 bool fBindUniformLocationSupport : 1;
618 bool fRectangleTextureSupport : 1;
619 bool fMipmapLevelControlSupport : 1;
620 bool fMipmapLodControlSupport : 1;
621 bool fClearTextureSupport : 1;
622 bool fProgramBinarySupport : 1;
623 bool fProgramParameterSupport : 1;
624 bool fSamplerObjectSupport : 1;
625 bool fUseSamplerObjects : 1;
626 bool fTextureSwizzleSupport : 1;
627 bool fTiledRenderingSupport : 1;
628 bool fFenceSyncSupport : 1;
629 bool fFBFetchRequiresEnablePerSample : 1;
630 bool fSRGBWriteControl : 1;
631 bool fSkipErrorChecks : 1;
632 bool fClientCanDisableMultisample : 1;
633
634 // Driver workarounds
635 bool fDoManualMipmapping : 1;
636 bool fClearToBoundaryValuesIsBroken : 1;
637 bool fDrawArraysBaseVertexIsBroken : 1;
638 bool fDisallowTexSubImageForUnormConfigTexturesEverBoundToFBO : 1;
639 bool fUseDrawInsteadOfAllRenderTargetWrites : 1;
640 bool fRequiresCullFaceEnableDisableWhenDrawingLinesAfterNonLines : 1;
641 bool fDontSetBaseOrMaxLevelForExternalTextures : 1;
642 bool fNeverDisableColorWrites : 1;
643 bool fMustSetAnyTexParameterToEnableMipmapping : 1;
644 bool fAllowBGRA8CopyTexSubImage : 1;
645 bool fAllowSRGBCopyTexSubImage : 1;
646 bool fDisallowDynamicMSAA : 1;
647 bool fMustResetBlendFuncBetweenDualSourceAndDisable : 1;
648 bool fBindTexture0WhenChangingTextureFBOMultisampleCount : 1;
649 bool fRebindColorAttachmentAfterCheckFramebufferStatus : 1;
650 bool fFlushBeforeWritePixels : 1;
651 bool fDisableScalingCopyAsDraws : 1;
652 bool fPadRG88TransferAlignment : 1;
653 int fMaxInstancesPerDrawWithoutCrashing = 0;
654
655 uint32_t fBlitFramebufferFlags = kNoSupport_BlitFramebufferFlag;
656
657 struct ReadPixelsFormat {
658 ReadPixelsFormat() : fFormat(0), fType(0) {}
659 GrGLenum fFormat;
660 GrGLenum fType;
661 };
662
663 /** Number type of the components (with out considering number of bits.) */
664 enum class FormatType {
665 kUnknown,
666 kNormalizedFixedPoint,
667 kFloat,
668 };
669
670 // ColorTypeInfo for a specific format
671 struct ColorTypeInfo {
673 enum {
674 kUploadData_Flag = 0x1,
675 // Does Ganesh itself support rendering to this colorType & format pair. Renderability
676 // still additionally depends on if the format can be an FBO color attachment.
677 kRenderable_Flag = 0x2,
678 };
679 uint32_t fFlags = 0;
680
681 skgpu::Swizzle fReadSwizzle;
682 skgpu::Swizzle fWriteSwizzle;
683
686
687 /** The external format and type are to be used when uploading/downloading data using
688 data of fColorType and uploading to a texture of a given GrGLFormat and its
689 intended GrColorType. The fExternalTexImageFormat is the format to use for TexImage
690 calls. The fExternalReadFormat is used when calling ReadPixels. If either is zero
691 that signals that either TexImage or ReadPixels is not supported for the combination
692 of format and color types. */
696 /**
697 * Must check whether GL_IMPLEMENTATION_COLOR_READ_FORMAT and _TYPE match
698 * fExternalReadFormat and fExternalType before using with glReadPixels.
699 */
701 };
702
703 GrGLenum externalFormat(GrColorType externalColorType, ExternalFormatUsage usage,
704 bool haveQueriedImplementationReadFormat) const {
705 for (int i = 0; i < fExternalIOFormatCount; ++i) {
706 if (fExternalIOFormats[i].fColorType == externalColorType) {
707 if (usage == kTexImage_ExternalFormatUsage) {
708 return fExternalIOFormats[i].fExternalTexImageFormat;
709 } else {
710 SkASSERT(usage == kReadPixels_ExternalFormatUsage);
711 if (!haveQueriedImplementationReadFormat &&
712 fExternalIOFormats[i].fRequiresImplementationReadQuery) {
713 return 0;
714 }
715 return fExternalIOFormats[i].fExternalReadFormat;
716 }
717 }
718 }
719 return 0;
720 }
721
722 GrGLenum externalType(GrColorType externalColorType) const {
723 for (int i = 0; i < fExternalIOFormatCount; ++i) {
724 if (fExternalIOFormats[i].fColorType == externalColorType) {
725 return fExternalIOFormats[i].fExternalType;
726 }
727 }
728 return 0;
729 }
730
731 std::unique_ptr<ExternalIOFormats[]> fExternalIOFormats;
732 int fExternalIOFormatCount = 0;
733 };
734
735 struct FormatInfo {
736 uint32_t colorTypeFlags(GrColorType colorType) const {
737 for (int i = 0; i < fColorTypeInfoCount; ++i) {
738 if (fColorTypeInfos[i].fColorType == colorType) {
739 return fColorTypeInfos[i].fFlags;
740 }
741 }
742 return 0;
743 }
744
745 GrGLenum externalFormat(GrColorType surfaceColorType, GrColorType externalColorType,
746 ExternalFormatUsage usage) const {
747 for (int i = 0; i < fColorTypeInfoCount; ++i) {
748 if (fColorTypeInfos[i].fColorType == surfaceColorType) {
749 return fColorTypeInfos[i].externalFormat(externalColorType, usage,
750 fHaveQueriedImplementationReadSupport);
751 }
752 }
753 return 0;
754 }
755
756 GrGLenum externalType(GrColorType surfaceColorType, GrColorType externalColorType) const {
757 for (int i = 0; i < fColorTypeInfoCount; ++i) {
758 if (fColorTypeInfos[i].fColorType == surfaceColorType) {
759 return fColorTypeInfos[i].externalType(externalColorType);
760 }
761 }
762 return 0;
763 }
764
765 enum {
766 kTexturable_Flag = 0x01,
767 /** kFBOColorAttachment means that even if the format cannot be a GrRenderTarget, we can
768 still attach it to a FBO for blitting or reading pixels. */
769 kFBOColorAttachment_Flag = 0x02,
770 kFBOColorAttachmentWithMSAA_Flag = 0x04,
771 kUseTexStorage_Flag = 0x08,
772 /**
773 * Are pixel buffer objects supported in/out of this format? Ignored if PBOs are not
774 * supported at all.
775 */
776 kTransfers_Flag = 0x10,
777 };
778 uint32_t fFlags = 0;
779
780 FormatType fFormatType = FormatType::kUnknown;
781
782 // Not defined for uncompressed formats. Passed to glCompressedTexImage...
783 GrGLenum fCompressedInternalFormat = 0;
784
785 // Value to uses as the "internalformat" argument to glTexImage or glTexStorage. It is
786 // initialized in coordination with the presence/absence of the kUseTexStorage flag. In
787 // other words, it is only guaranteed to be compatible with glTexImage if the flag is not
788 // set and or with glTexStorage if the flag is set.
789 GrGLenum fInternalFormatForTexImageOrStorage = 0;
790
791 // Value to uses as the "internalformat" argument to glRenderbufferStorageMultisample...
792 GrGLenum fInternalFormatForRenderbuffer = 0;
793
794 // Default values to use along with fInternalFormatForTexImageOrStorage for function
795 // glTexImage2D when not input providing data (passing nullptr) or when clearing it by
796 // uploading a block of solid color data. Not defined for compressed formats.
797 GrGLenum fDefaultExternalFormat = 0;
798 GrGLenum fDefaultExternalType = 0;
799 // When the above two values are used to initialize a texture by uploading cleared data to
800 // it the data should be of this color type.
801 GrColorType fDefaultColorType = GrColorType::kUnknown;
802
803 bool fHaveQueriedImplementationReadSupport = false;
804
805 enum {
806 // This indicates that a stencil format has not yet been determined for the config.
807 kUnknown_StencilIndex = -1,
808 // This indicates that there is no supported stencil format for the config.
809 kUnsupported_StencilFormatIndex = -2
810 };
811
812 // Index fStencilFormats.
813 int fStencilFormatIndex = kUnknown_StencilIndex;
814
815 SkTDArray<int> fColorSampleCounts;
816
817 std::unique_ptr<ColorTypeInfo[]> fColorTypeInfos;
818 int fColorTypeInfoCount = 0;
819 };
820
821 FormatInfo fFormatTable[kGrGLColorFormatCount];
822
823 FormatInfo& getFormatInfo(GrGLFormat format) { return fFormatTable[static_cast<int>(format)]; }
824 const FormatInfo& getFormatInfo(GrGLFormat format) const {
825 return fFormatTable[static_cast<int>(format)];
826 }
827
828 GrGLFormat fColorTypeToFormatTable[kGrColorTypeCnt];
829 void setColorTypeFormat(GrColorType, GrGLFormat);
830
831 using INHERITED = GrCaps;
832};
833
834#endif
const char * options
static constexpr int kGrGLColorFormatCount
GrGLFormat
Definition GrGLTypes.h:59
GrGLStandard
Definition GrGLTypes.h:19
@ kNone_GrGLStandard
Definition GrGLTypes.h:20
unsigned int GrGLenum
Definition GrGLTypes.h:102
GrDstSampleFlags
static const int kGrColorTypeCnt
GrTextureType
GrColorType
SkColorType fColorType
uint16_t fFlags
#define SkASSERT(cond)
Definition SkAssert.h:116
static SkColorType colorType(AImageDecoder *decoder, const AImageDecoderHeaderInfo *headerInfo)
SurfaceReadPixelsSupport
Definition GrCaps.h:296
ProgramDescOverrideFlags
Definition GrCaps.h:511
bool flushBeforeWritePixels() const
Definition GrGLCaps.h:461
bool skipErrorChecks() const
Definition GrGLCaps.h:514
bool bindUniformLocationSupport() const
Definition GrGLCaps.h:381
uint64_t computeFormatKey(const GrBackendFormat &) const override
DstCopyRestrictions getDstCopyRestrictions(const GrRenderTargetProxy *src, GrColorType) const override
bool isFormatAsColorTypeRenderable(GrColorType ct, const GrBackendFormat &format, int sampleCount=1) const override
skgpu::Swizzle onGetReadSwizzle(const GrBackendFormat &, GrColorType) const override
void getReadPixelsFormat(GrGLFormat surfaceFormat, GrColorType surfaceColorType, GrColorType memoryColorType, GrGLenum *externalFormat, GrGLenum *externalType) const
bool onAreColorTypeAndFormatCompatible(GrColorType, const GrBackendFormat &) const override
BlitFramebufferFlags
Definition GrGLCaps.h:84
@ kNoScalingOrMirroring_BlitFramebufferFlag
Definition GrGLCaps.h:86
@ kResolveMustBeFull_BlitFrambufferFlag
Definition GrGLCaps.h:87
@ kNoSupport_BlitFramebufferFlag
Definition GrGLCaps.h:85
@ kRectsMustMatchForMSAASrc_BlitFramebufferFlag
Definition GrGLCaps.h:91
@ kNoFormatConversion_BlitFramebufferFlag
Definition GrGLCaps.h:89
@ kNoFormatConversionForMSAASrc_BlitFramebufferFlag
Definition GrGLCaps.h:90
@ kNoMSAADst_BlitFramebufferFlag
Definition GrGLCaps.h:88
bool drawRangeElementsSupport() const
Is there support for glDrawRangeElements?
Definition GrGLCaps.h:365
GrGLenum getRenderbufferInternalFormat(GrGLFormat format) const
Definition GrGLCaps.h:247
bool onSurfaceSupportsWritePixels(const GrSurface *) const override
GrBackendFormat getBackendFormatFromCompressionType(SkTextureCompressionType) const override
bool vertexArrayObjectSupport() const
Is there support for Vertex Array Objects?
Definition GrGLCaps.h:356
bool baseVertexBaseInstanceSupport() const
Are the glDraw*Base(VertexBase)Instance methods, and baseInstance fields in indirect draw.
Definition GrGLCaps.h:369
bool canCopyAsDraw(GrGLFormat dstFormat, bool srcIsTexturable, bool scalingCopy) const
bool samplerObjectSupport() const
Definition GrGLCaps.h:493
@ kES_Apple_MSFBOType
Definition GrGLCaps.h:69
@ kES_EXT_MsToTexture_MSFBOType
Definition GrGLCaps.h:81
@ kNone_MSFBOType
Definition GrGLCaps.h:59
@ kES_IMG_MsToTexture_MSFBOType
Definition GrGLCaps.h:76
@ kStandard_MSFBOType
Definition GrGLCaps.h:65
bool onCanCopySurface(const GrSurfaceProxy *dst, const SkIRect &dstRect, const GrSurfaceProxy *src, const SkIRect &srcRect) const override
bool dontSetBaseOrMaxLevelForExternalTextures() const
Definition GrGLCaps.h:429
bool ES2CompatibilitySupport() const
Is there support for ES2 compatability?
Definition GrGLCaps.h:362
int maxRenderTargetSampleCount(const GrBackendFormat &format) const override
Definition GrGLCaps.h:165
bool useSamplerObjects() const
Definition GrGLCaps.h:499
bool textureUsageSupport() const
Is there support for texture parameter GL_TEXTURE_USAGE.
Definition GrGLCaps.h:350
bool mustResetBlendFuncBetweenDualSourceAndDisable() const
Definition GrGLCaps.h:443
bool imagingSupport() const
Is GL_ARB_IMAGING supported.
Definition GrGLCaps.h:353
bool isCoreProfile() const
Definition GrGLCaps.h:377
void didQueryImplementationReadSupport(GrGLFormat format, GrGLenum readFormat, GrGLenum readType) const
float maxTextureMaxAnisotropy() const
Definition GrGLCaps.h:170
int maxInstancesPerDrawWithoutCrashing(int pendingInstanceCount) const
Definition GrGLCaps.h:468
bool mipmapLodControlSupport() const
Can set the MIN/MAX LOD value.
Definition GrGLCaps.h:390
MSFBOType msFBOType() const
Definition GrGLCaps.h:285
TransferBufferType
Definition GrGLCaps.h:113
void getTexSubImageExternalFormatAndType(GrGLFormat surfaceFormat, GrColorType surfaceColorType, GrColorType memoryColorType, GrGLenum *externalFormat, GrGLenum *externalType) const
@ kMapBufferRange_MapBufferType
Definition GrGLCaps.h:109
@ kMapBuffer_MapBufferType
Definition GrGLCaps.h:108
@ kNone_MapBufferType
Definition GrGLCaps.h:107
@ kChromium_MapBufferType
Definition GrGLCaps.h:110
void onApplyOptionsOverrides(const GrContextOptions &options) override
bool usesMSAARenderBuffers() const
Definition GrGLCaps.h:290
bool drawArraysBaseVertexIsBroken() const
Definition GrGLCaps.h:407
bool requiresCullFaceEnableDisableWhenDrawingLinesAfterNonLines() const
Definition GrGLCaps.h:423
bool usesImplicitMSAAResolve() const
Definition GrGLCaps.h:318
InvalidateFBType invalidateFBType() const
Definition GrGLCaps.h:323
bool rectangleTextureSupport() const
Are textures with GL_TEXTURE_RECTANGLE type supported.
Definition GrGLCaps.h:384
bool hasStencilFormatBeenDeterminedForFormat(GrGLFormat format) const
Definition GrGLCaps.h:261
bool debugSupport() const
Is there support for GL_KHR_debug?
Definition GrGLCaps.h:359
bool bindTexture0WhenChangingTextureFBOMultisampleCount() const
Definition GrGLCaps.h:450
bool clearToBoundaryValuesIsBroken() const
Definition GrGLCaps.h:399
bool doManualMipmapping() const
Definition GrGLCaps.h:392
bool programBinarySupport() const
Definition GrGLCaps.h:488
bool formatSupportsTexStorage(GrGLFormat) const
RegenerateMipmapType regenerateMipmapType() const
How is restricting sampled miplevels in onRegenerateMipmapLevels implemented?
Definition GrGLCaps.h:341
GrGLenum getFormatDefaultExternalType(GrGLFormat format) const
Definition GrGLCaps.h:254
GrProgramDesc makeDesc(GrRenderTarget *, const GrProgramInfo &, ProgramDescOverrideFlags) const override
bool useDrawInsteadOfAllRenderTargetWrites() const
Definition GrGLCaps.h:417
GrBackendFormat onGetDefaultBackendFormat(GrColorType) const override
SupportedRead onSupportedReadPixelsColorType(GrColorType, const GrBackendFormat &, GrColorType) const override
GrDstSampleFlags onGetDstSampleFlagsForProxy(const GrRenderTargetProxy *) const override
bool fenceSyncSupport() const
Definition GrGLCaps.h:332
bool isFormatSRGB(const GrBackendFormat &) const override
bool neverDisableColorWrites() const
Definition GrGLCaps.h:434
MultiDrawType multiDrawType() const
How are multi draws implemented (if at all)?
Definition GrGLCaps.h:338
bool isFormatCopyable(const GrBackendFormat &) const override
bool rebindColorAttachmentAfterCheckFramebufferStatus() const
Definition GrGLCaps.h:456
bool programBinaryFormatIsValid(GrGLenum binaryFormat) const
SupportedWrite supportedWritePixelsColorType(GrColorType surfaceColorType, const GrBackendFormat &surfaceFormat, GrColorType srcColorType) const override
bool framebufferResolvesMustBeFullSize() const
Definition GrGLCaps.h:299
bool canResolveSingleToMSAA() const
Definition GrGLCaps.h:308
bool disallowTexSubImageForUnormConfigTexturesEverBoundToFBO() const
Definition GrGLCaps.h:411
bool programParameterSupport() const
Definition GrGLCaps.h:489
FenceType fenceType() const
How is GrGLsync implemented?
Definition GrGLCaps.h:335
void getTexSubImageDefaultFormatTypeAndColorType(GrGLFormat format, GrGLenum *externalFormat, GrGLenum *externalType, GrColorType *colorType) const
bool isFormatRenderable(GrGLFormat format, int sampleCount) const
Definition GrGLCaps.h:154
bool textureSwizzleSupport() const
Definition GrGLCaps.h:501
GrGLFormat getFormatFromColorType(GrColorType colorType) const
Definition GrGLCaps.h:176
int getStencilFormatIndexForFormat(GrGLFormat format) const
Definition GrGLCaps.h:271
SurfaceReadPixelsSupport surfaceSupportsReadPixels(const GrSurface *) const override
bool packFlipYSupport() const
Is there support for GL_PACK_REVERSE_ROW_ORDER.
Definition GrGLCaps.h:347
bool isFormatRenderable(const GrBackendFormat &format, int sampleCount) const override
bool canFormatBeFBOColorAttachment(GrGLFormat) const
bool canCopyTexSubImage(GrGLFormat dstFormat, bool dstHasMSAARenderBuffer, const GrTextureType *dstTypeIfTexture, GrGLFormat srcFormat, bool srcHasMSAARenderBuffer, const GrTextureType *srcTypeIfTexture) const
bool fbFetchRequiresEnablePerSample() const
Definition GrGLCaps.h:505
void setStencilFormatIndexForFormat(GrGLFormat, int index)
MapBufferType mapBufferType() const
What type of buffer mapping is supported?
Definition GrGLCaps.h:326
bool clearTextureSupport() const
glClearTex(Sub)Image support
Definition GrGLCaps.h:402
bool mipmapLevelControlSupport() const
Can set the BASE and MAX mip map level.
Definition GrGLCaps.h:387
skgpu::Swizzle getWriteSwizzle(const GrBackendFormat &, GrColorType) const override
RegenerateMipmapType
Definition GrGLCaps.h:133
bool mustSetAnyTexParameterToEnableMipmapping() const
Definition GrGLCaps.h:437
int getRenderTargetSampleCount(int requestedCount, const GrBackendFormat &format) const override
Definition GrGLCaps.h:158
bool canCopyAsBlit(GrGLFormat dstFormat, int dstSampleCnt, const GrTextureType *dstTypeIfTexture, GrGLFormat srcFormat, int srcSampleCnt, const GrTextureType *srcTypeIfTexture, const SkRect &srcBounds, bool srcBoundsExact, const SkIRect &srcRect, const SkIRect &dstRect) const
bool tiledRenderingSupport() const
Definition GrGLCaps.h:503
void getTexImageExternalFormatAndType(GrGLFormat surfaceFormat, GrGLenum *externalFormat, GrGLenum *externalType) const
InvalidateFBType
Definition GrGLCaps.h:94
@ kNone_InvalidateFBType
Definition GrGLCaps.h:95
@ kDiscard_InvalidateFBType
Definition GrGLCaps.h:96
@ kInvalidate_InvalidateFBType
Definition GrGLCaps.h:97
bool onIsWindowRectanglesSupportedForRT(const GrBackendRenderTarget &) const override
int maxFragmentUniformVectors() const
The maximum number of fragment uniform vectors (GLES has min. 16).
Definition GrGLCaps.h:344
bool clientCanDisableMultisample() const
Definition GrGLCaps.h:516
bool shouldQueryImplementationReadSupport(GrGLFormat format) const
bool onSupportsDynamicMSAA(const GrRenderTargetProxy *) const override
bool isFormatTexturable(const GrBackendFormat &, GrTextureType) const override
bool srgbWriteControl() const
Definition GrGLCaps.h:508
InvalidateBufferType invalidateBufferType() const
Definition GrGLCaps.h:396
void onDumpJSON(SkJSONWriter *) const override
TransferBufferType transferBufferType() const
What type of transfer buffer is supported?
Definition GrGLCaps.h:329
bool bindFragDataLocationSupport() const
Definition GrGLCaps.h:379
const skia_private::TArray< GrGLFormat, true > & stencilFormats() const
Definition GrGLCaps.h:223
InvalidateBufferType
Definition GrGLCaps.h:100
GrGLenum getTexImageOrStorageInternalFormat(GrGLFormat format) const
Definition GrGLCaps.h:185
uint32_t uint32_t * format
SK_API GrGLFormat AsGLFormat(const GrBackendFormat &)
static void usage(char *argv0)