static const char* sample_offset_array_name(GrGLSLFPFragmentBuilder::Coordinates coords) { static const char* kArrayNames[] = { "deviceSpaceSampleOffsets", "windowSpaceSampleOffsets" }; return kArrayNames[coords]; GR_STATIC_ASSERT(0 == GrGLSLFPFragmentBuilder::kSkiaDevice_Coordinates); GR_STATIC_ASSERT(1 == GrGLSLFPFragmentBuilder::kGLSLWindow_Coordinates); GR_STATIC_ASSERT(SK_ARRAY_COUNT(kArrayNames) == GrGLSLFPFragmentBuilder::kLast_Coordinates + 1); }
static inline VkSamplerAddressMode tile_to_vk_sampler_address(SkShader::TileMode tm) { static const VkSamplerAddressMode gWrapModes[] = { VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE, VK_SAMPLER_ADDRESS_MODE_REPEAT, VK_SAMPLER_ADDRESS_MODE_MIRRORED_REPEAT }; GR_STATIC_ASSERT(SkShader::kTileModeCount == SK_ARRAY_COUNT(gWrapModes)); GR_STATIC_ASSERT(0 == SkShader::kClamp_TileMode); GR_STATIC_ASSERT(1 == SkShader::kRepeat_TileMode); GR_STATIC_ASSERT(2 == SkShader::kMirror_TileMode); return gWrapModes[tm]; }
GrPathRenderer* GrPathRendererChain::getPathRenderer(const GrDrawTarget* target, const GrPipelineBuilder* pipelineBuilder, const SkMatrix& viewMatrix, const SkPath& path, const GrStrokeInfo& stroke, DrawType drawType, StencilSupport* stencilSupport) { if (!fInit) { this->init(); } bool antiAlias = (kColorAntiAlias_DrawType == drawType || kStencilAndColorAntiAlias_DrawType == drawType); GR_STATIC_ASSERT(GrPathRenderer::kNoSupport_StencilSupport < GrPathRenderer::kStencilOnly_StencilSupport); GR_STATIC_ASSERT(GrPathRenderer::kStencilOnly_StencilSupport < GrPathRenderer::kNoRestriction_StencilSupport); GrPathRenderer::StencilSupport minStencilSupport; if (kStencilOnly_DrawType == drawType) { minStencilSupport = GrPathRenderer::kStencilOnly_StencilSupport; } else if (kStencilAndColor_DrawType == drawType || kStencilAndColorAntiAlias_DrawType == drawType) { minStencilSupport = GrPathRenderer::kNoRestriction_StencilSupport; } else { minStencilSupport = GrPathRenderer::kNoSupport_StencilSupport; } for (int i = 0; i < fChain.count(); ++i) { GrPathRenderer::CanDrawPathArgs args; args.fShaderCaps = target->caps()->shaderCaps(); args.fPipelineBuilder = pipelineBuilder; args.fViewMatrix = &viewMatrix; args.fPath = &path; args.fStroke = &stroke; args.fAntiAlias = antiAlias; if (fChain[i]->canDrawPath(args)) { if (GrPathRenderer::kNoSupport_StencilSupport != minStencilSupport) { GrPathRenderer::StencilSupport support = fChain[i]->getStencilSupport(path, stroke); if (support < minStencilSupport) { continue; } else if (stencilSupport) { *stencilSupport = support; } } return fChain[i]; } } return NULL; }
VkCullModeFlags draw_face_to_vk_cull_mode(GrPipelineBuilder::DrawFace drawFace) { // Assumes that we've set the front face to be ccw static const VkCullModeFlags gTable[] = { VK_CULL_MODE_NONE, // kBoth_DrawFace VK_CULL_MODE_BACK_BIT, // kCCW_DrawFace, cull back face VK_CULL_MODE_FRONT_BIT, // kCW_DrawFace, cull front face }; GR_STATIC_ASSERT(0 == GrPipelineBuilder::kBoth_DrawFace); GR_STATIC_ASSERT(1 == GrPipelineBuilder::kCCW_DrawFace); GR_STATIC_ASSERT(2 == GrPipelineBuilder::kCW_DrawFace); SkASSERT((unsigned)drawFace <= 2); return gTable[drawFace]; }
// If the path is small enough to be keyed from its data this returns key length, otherwise -1. static int path_key_from_data_size(const SkPath& path) { const int verbCnt = path.countVerbs(); if (verbCnt > GrShape::kMaxKeyFromDataVerbCnt) { return -1; } const int pointCnt = path.countPoints(); const int conicWeightCnt = SkPathPriv::ConicWeightCnt(path); GR_STATIC_ASSERT(sizeof(SkPoint) == 2 * sizeof(uint32_t)); GR_STATIC_ASSERT(sizeof(SkScalar) == sizeof(uint32_t)); // 2 is for the verb cnt and a fill type. Each verb is a byte but we'll pad the verb data out to // a uint32_t length. return 2 + (SkAlign4(verbCnt) >> 2) + 2 * pointCnt + conicWeightCnt; }
static VkBlendOp blend_equation_to_vk_blend_op(GrBlendEquation equation) { static const VkBlendOp gTable[] = { VK_BLEND_OP_ADD, // kAdd_GrBlendEquation VK_BLEND_OP_SUBTRACT, // kSubtract_GrBlendEquation VK_BLEND_OP_REVERSE_SUBTRACT, // kReverseSubtract_GrBlendEquation }; GR_STATIC_ASSERT(SK_ARRAY_COUNT(gTable) == kFirstAdvancedGrBlendEquation); GR_STATIC_ASSERT(0 == kAdd_GrBlendEquation); GR_STATIC_ASSERT(1 == kSubtract_GrBlendEquation); GR_STATIC_ASSERT(2 == kReverseSubtract_GrBlendEquation); SkASSERT((unsigned)equation < kGrBlendCoeffCnt); return gTable[equation]; }
void GrGLCaps::print() const { INHERITED::print(); GrPrintf("--- GL-Specific ---\n"); for (int i = 0; i < fStencilFormats.count(); ++i) { GrPrintf("Stencil Format %d, stencil bits: %02d, total bits: %02d\n", i, fStencilFormats[i].fStencilBits, fStencilFormats[i].fTotalBits); } GR_STATIC_ASSERT(0 == kNone_MSFBOType); GR_STATIC_ASSERT(1 == kDesktopARB_MSFBOType); GR_STATIC_ASSERT(2 == kDesktopEXT_MSFBOType); GR_STATIC_ASSERT(3 == kAppleES_MSFBOType); GR_STATIC_ASSERT(4 == kImaginationES_MSFBOType); static const char* gMSFBOExtStr[] = { "None", "ARB", "EXT", "Apple", "IMG", }; GrPrintf("MSAA Type: %s\n", gMSFBOExtStr[fMSFBOType]); GrPrintf("Max FS Uniform Vectors: %d\n", fMaxFragmentUniformVectors); GrPrintf("Max Vertex Attributes: %d\n", fMaxVertexAttributes); GrPrintf("Support RGBA8 Render Buffer: %s\n", (fRGBA8RenderbufferSupport ? "YES": "NO")); GrPrintf("BGRA support: %s\n", (fBGRAFormatSupport ? "YES": "NO")); GrPrintf("BGRA is an internal format: %s\n", (fBGRAIsInternalFormat ? "YES": "NO")); GrPrintf("Support texture swizzle: %s\n", (fTextureSwizzleSupport ? "YES": "NO")); GrPrintf("Unpack Row length support: %s\n", (fUnpackRowLengthSupport ? "YES": "NO")); GrPrintf("Unpack Flip Y support: %s\n", (fUnpackFlipYSupport ? "YES": "NO")); GrPrintf("Pack Row length support: %s\n", (fPackRowLengthSupport ? "YES": "NO")); GrPrintf("Pack Flip Y support: %s\n", (fPackFlipYSupport ? "YES": "NO")); GrPrintf("Texture Usage support: %s\n", (fTextureUsageSupport ? "YES": "NO")); GrPrintf("Texture Storage support: %s\n", (fTexStorageSupport ? "YES": "NO")); GrPrintf("GL_R support: %s\n", (fTextureRedSupport ? "YES": "NO")); GrPrintf("GL_ARB_imaging support: %s\n", (fImagingSupport ? "YES": "NO")); GrPrintf("Two Format Limit: %s\n", (fTwoFormatLimit ? "YES": "NO")); GrPrintf("Fragment coord conventions support: %s\n", (fFragCoordsConventionSupport ? "YES": "NO")); GrPrintf("Vertex array object support: %s\n", (fVertexArrayObjectSupport ? "YES": "NO")); GrPrintf("Use non-VBO for dynamic data: %s\n", (fUseNonVBOVertexAndIndexDynamicData ? "YES" : "NO")); GrPrintf("Core Profile: %s\n", (fIsCoreProfile ? "YES" : "NO")); GrPrintf("Discard FrameBuffer support: %s\n", (fDiscardFBSupport ? "YES" : "NO")); }
static uint32_t setup_quad_index_buffer(const GrGLInterface* gl) { static const int kMaxQuads = 1;//1 << 12; // max possible: (1 << 14) - 1; GR_STATIC_ASSERT(4 * kMaxQuads <= 65535); static const uint16_t kPattern[] = { 0, 1, 2, 0, 2, 3 }; static const int kPatternSize = 6; static const int kVertCount = 4; static const int kIndicesCount = kPatternSize * kMaxQuads; int size = kPatternSize * kMaxQuads * sizeof(uint16_t); uint16_t* data = SkNEW_ARRAY(uint16_t, kMaxQuads * kPatternSize); for (int i = 0; i < kMaxQuads; ++i) { int baseIdx = i * kPatternSize; uint16_t baseVert = (uint16_t)(i * kVertCount); for (int j = 0; j < kPatternSize; ++j) { data[baseIdx+j] = baseVert + kPattern[j]; } } GrGLuint quadIBO; GR_GL_CALL(gl, GenBuffers(1, &quadIBO)); GR_GL_CALL(gl, BindBuffer(GR_GL_ELEMENT_ARRAY_BUFFER, quadIBO)); GR_GL_CALL(gl, BufferData(GR_GL_ELEMENT_ARRAY_BUFFER, size, data, GR_GL_STATIC_DRAW)); SkDELETE_ARRAY(data); return kIndicesCount; }
static GrVkGpu::Heap buffer_type_to_heap(GrVkBuffer::Type type) { const GrVkGpu::Heap kBufferToHeap[] { GrVkGpu::kVertexBuffer_Heap, GrVkGpu::kIndexBuffer_Heap, GrVkGpu::kUniformBuffer_Heap, GrVkGpu::kCopyReadBuffer_Heap, GrVkGpu::kCopyWriteBuffer_Heap, }; GR_STATIC_ASSERT(0 == GrVkBuffer::kVertex_Type); GR_STATIC_ASSERT(1 == GrVkBuffer::kIndex_Type); GR_STATIC_ASSERT(2 == GrVkBuffer::kUniform_Type); GR_STATIC_ASSERT(3 == GrVkBuffer::kCopyRead_Type); GR_STATIC_ASSERT(4 == GrVkBuffer::kCopyWrite_Type); return kBufferToHeap[type]; }
uint32_t get_blend_info_key(const GrPipeline& pipeline) { GrXferProcessor::BlendInfo blendInfo; pipeline.getXferProcessor().getBlendInfo(&blendInfo); static const uint32_t kBlendWriteShift = 1; static const uint32_t kBlendCoeffShift = 5; GR_STATIC_ASSERT(kLast_GrBlendCoeff < (1 << kBlendCoeffShift)); GR_STATIC_ASSERT(kFirstAdvancedGrBlendEquation - 1 < 4); uint32_t key = blendInfo.fWriteColor; key |= (blendInfo.fSrcBlend << kBlendWriteShift); key |= (blendInfo.fDstBlend << (kBlendWriteShift + kBlendCoeffShift)); key |= (blendInfo.fEquation << (kBlendWriteShift + 2 * kBlendCoeffShift)); return key; }
void GrGLConvexPolyEffect::GenKey(const GrProcessor& processor, const GrGLSLCaps&, GrProcessorKeyBuilder* b) { const GrConvexPolyEffect& cpe = processor.cast<GrConvexPolyEffect>(); GR_STATIC_ASSERT(kGrProcessorEdgeTypeCnt <= 8); uint32_t key = (cpe.getEdgeCount() << 3) | cpe.getEdgeType(); b->add32(key); }
bool blend_coeff_refs_constant(GrBlendCoeff coeff) { static const bool gCoeffReferencesBlendConst[] = { false, false, false, false, false, false, false, false, false, false, true, true, true, true, // extended blend coeffs false, false, false, false, }; return gCoeffReferencesBlendConst[coeff]; GR_STATIC_ASSERT(kGrBlendCoeffCnt == SK_ARRAY_COUNT(gCoeffReferencesBlendConst)); // Individual enum asserts already made in blend_coeff_to_vk_blend }
const GrIndexBuffer* GrResourceProvider::createQuadIndexBuffer() { static const int kMaxQuads = 1 << 12; // max possible: (1 << 14) - 1; GR_STATIC_ASSERT(4 * kMaxQuads <= 65535); static const uint16_t kPattern[] = { 0, 1, 2, 0, 2, 3 }; return this->createInstancedIndexBuffer(kPattern, 6, kMaxQuads, 4, fQuadIndexBufferKey); }
GrResourceKey GrTexture::ComputeScratchKey(const GrTextureDesc& desc) { GrCacheID::Key idKey; // Instead of a client-provided key of the texture contents we create a key from the // descriptor. GR_STATIC_ASSERT(sizeof(idKey) >= 16); GrAssert(desc.fHeight < (1 << 16)); GrAssert(desc.fWidth < (1 << 16)); idKey.fData32[0] = (desc.fWidth) | (desc.fHeight << 16); idKey.fData32[1] = desc.fConfig | desc.fSampleCnt << 16; idKey.fData32[2] = desc.fFlags; idKey.fData32[3] = resolve_origin(desc); // Only needs 2 bits actually static const int kPadSize = sizeof(idKey) - 16; GR_STATIC_ASSERT(kPadSize >= 0); memset(idKey.fData8 + 16, 0, kPadSize); GrCacheID cacheID(GrResourceKey::ScratchDomain(), idKey); return GrResourceKey(cacheID, texture_resource_type(), 0); }
void GrLayerCache::initAtlas() { SkASSERT(NULL == fAtlas.get()); GR_STATIC_ASSERT(kNumPlotsX*kNumPlotsX == GrPictureInfo::kNumPlots); SkISize textureSize = SkISize::Make(kAtlasTextureWidth, kAtlasTextureHeight); fAtlas.reset(SkNEW_ARGS(GrAtlas, (fContext->getGpu(), kSkia8888_GrPixelConfig, kRenderTarget_GrSurfaceFlag, textureSize, kNumPlotsX, kNumPlotsY, false))); }
GrPathRenderer* GrPathRendererChain::getPathRenderer(const GrDrawTarget* target, const GrPipelineBuilder* pipelineBuilder, const SkMatrix& viewMatrix, const SkPath& path, const SkStrokeRec& stroke, DrawType drawType, StencilSupport* stencilSupport) { if (!fInit) { this->init(); } bool antiAlias = (kColorAntiAlias_DrawType == drawType || kStencilAndColorAntiAlias_DrawType == drawType); GR_STATIC_ASSERT(GrPathRenderer::kNoSupport_StencilSupport < GrPathRenderer::kStencilOnly_StencilSupport); GR_STATIC_ASSERT(GrPathRenderer::kStencilOnly_StencilSupport < GrPathRenderer::kNoRestriction_StencilSupport); GrPathRenderer::StencilSupport minStencilSupport; if (kStencilOnly_DrawType == drawType) { minStencilSupport = GrPathRenderer::kStencilOnly_StencilSupport; } else if (kStencilAndColor_DrawType == drawType || kStencilAndColorAntiAlias_DrawType == drawType) { minStencilSupport = GrPathRenderer::kNoRestriction_StencilSupport; } else { minStencilSupport = GrPathRenderer::kNoSupport_StencilSupport; } for (int i = 0; i < fChain.count(); ++i) { if (fChain[i]->canDrawPath(target, pipelineBuilder, viewMatrix, path, stroke, antiAlias)) { if (GrPathRenderer::kNoSupport_StencilSupport != minStencilSupport) { GrPathRenderer::StencilSupport support = fChain[i]->getStencilSupport(target, pipelineBuilder, path, stroke); if (support < minStencilSupport) { continue; } else if (stencilSupport) { *stencilSupport = support; } } return fChain[i]; } } return NULL; }
SkString GrDrawTargetCaps::dump() const { SkString r; static const char* gNY[] = {"NO", "YES"}; r.appendf("8 Bit Palette Support : %s\n", gNY[f8BitPaletteSupport]); r.appendf("MIP Map Support : %s\n", gNY[fMipMapSupport]); r.appendf("NPOT Texture Tile Support : %s\n", gNY[fNPOTTextureTileSupport]); r.appendf("Two Sided Stencil Support : %s\n", gNY[fTwoSidedStencilSupport]); r.appendf("Stencil Wrap Ops Support : %s\n", gNY[fStencilWrapOpsSupport]); r.appendf("HW AA Lines Support : %s\n", gNY[fHWAALineSupport]); r.appendf("Shader Derivative Support : %s\n", gNY[fShaderDerivativeSupport]); r.appendf("Geometry Shader Support : %s\n", gNY[fGeometryShaderSupport]); r.appendf("Dual Source Blending Support : %s\n", gNY[fDualSourceBlendingSupport]); r.appendf("Buffer Lock Support : %s\n", gNY[fBufferLockSupport]); r.appendf("Path Rendering Support : %s\n", gNY[fPathRenderingSupport]); r.appendf("Dst Read In Shader Support : %s\n", gNY[fDstReadInShaderSupport]); r.appendf("Discard Render Target Support: %s\n", gNY[fDiscardRenderTargetSupport]); r.appendf("Reuse Scratch Textures : %s\n", gNY[fReuseScratchTextures]); r.appendf("Gpu Tracing Support : %s\n", gNY[fGpuTracingSupport]); r.appendf("Max Texture Size : %d\n", fMaxTextureSize); r.appendf("Max Render Target Size : %d\n", fMaxRenderTargetSize); r.appendf("Max Sample Count : %d\n", fMaxSampleCount); static const char* kConfigNames[] = { "Unknown", // kUnknown_GrPixelConfig "Alpha8", // kAlpha_8_GrPixelConfig, "Index8", // kIndex_8_GrPixelConfig, "RGB565", // kRGB_565_GrPixelConfig, "RGBA444", // kRGBA_4444_GrPixelConfig, "RGBA8888", // kRGBA_8888_GrPixelConfig, "BGRA8888", // kBGRA_8888_GrPixelConfig, }; GR_STATIC_ASSERT(0 == kUnknown_GrPixelConfig); GR_STATIC_ASSERT(1 == kAlpha_8_GrPixelConfig); GR_STATIC_ASSERT(2 == kIndex_8_GrPixelConfig); GR_STATIC_ASSERT(3 == kRGB_565_GrPixelConfig); GR_STATIC_ASSERT(4 == kRGBA_4444_GrPixelConfig); GR_STATIC_ASSERT(5 == kRGBA_8888_GrPixelConfig); GR_STATIC_ASSERT(6 == kBGRA_8888_GrPixelConfig); GR_STATIC_ASSERT(SK_ARRAY_COUNT(kConfigNames) == kGrPixelConfigCnt); SkASSERT(!fConfigRenderSupport[kUnknown_GrPixelConfig][0]); SkASSERT(!fConfigRenderSupport[kUnknown_GrPixelConfig][1]); for (size_t i = 0; i < SK_ARRAY_COUNT(kConfigNames); ++i) { if (i != kUnknown_GrPixelConfig) { r.appendf("%s is renderable: %s, with MSAA: %s\n", kConfigNames[i], gNY[fConfigRenderSupport[i][0]], gNY[fConfigRenderSupport[i][1]]); } } return r; }
void GrGLSLShaderBuilder::compileAndAppendLayoutQualifiers() { static const char* interfaceQualifierNames[] = { "out" }; for (int interface = 0; interface <= kLastInterfaceQualifier; ++interface) { const SkTArray<SkString>& params = fLayoutParams[interface]; if (params.empty()) { continue; } this->layoutQualifiers().appendf("layout(%s", params[0].c_str()); for (int i = 1; i < params.count(); ++i) { this->layoutQualifiers().appendf(", %s", params[i].c_str()); } this->layoutQualifiers().appendf(") %s;\n", interfaceQualifierNames[interface]); } GR_STATIC_ASSERT(0 == GrGLSLShaderBuilder::kOut_InterfaceQualifier); GR_STATIC_ASSERT(SK_ARRAY_COUNT(interfaceQualifierNames) == kLastInterfaceQualifier + 1); }
GrPathRenderer* GrPathRendererChain::getPathRenderer( const GrPathRenderer::CanDrawPathArgs& args, DrawType drawType, GrPathRenderer::StencilSupport* stencilSupport) { GR_STATIC_ASSERT(GrPathRenderer::kNoSupport_StencilSupport < GrPathRenderer::kStencilOnly_StencilSupport); GR_STATIC_ASSERT(GrPathRenderer::kStencilOnly_StencilSupport < GrPathRenderer::kNoRestriction_StencilSupport); GrPathRenderer::StencilSupport minStencilSupport; if (kStencilOnly_DrawType == drawType) { minStencilSupport = GrPathRenderer::kStencilOnly_StencilSupport; } else if (kStencilAndColor_DrawType == drawType || kStencilAndColorAntiAlias_DrawType == drawType) { minStencilSupport = GrPathRenderer::kNoRestriction_StencilSupport; } else { minStencilSupport = GrPathRenderer::kNoSupport_StencilSupport; } if (minStencilSupport != GrPathRenderer::kNoSupport_StencilSupport) { // We don't support (and shouldn't need) stenciling of non-fill paths. if (!args.fStyle->isSimpleFill()) { return nullptr; } } for (int i = 0; i < fChain.count(); ++i) { if (fChain[i]->canDrawPath(args)) { if (GrPathRenderer::kNoSupport_StencilSupport != minStencilSupport) { GrPathRenderer::StencilSupport support = fChain[i]->getStencilSupport(*args.fPath); if (support < minStencilSupport) { continue; } else if (stencilSupport) { *stencilSupport = support; } } return fChain[i]; } } return nullptr; }
SkMesaGLContext::SkMesaGLContext() : fContext(static_cast<Context>(NULL)) , fImage(NULL) { GR_STATIC_ASSERT(sizeof(Context) == sizeof(OSMesaContext)); /* Create an RGBA-mode context */ #if OSMESA_MAJOR_VERSION * 100 + OSMESA_MINOR_VERSION >= 305 /* specify Z, stencil, accum sizes */ fContext = (Context)OSMesaCreateContextExt(OSMESA_BGRA, 0, 0, 0, NULL); #else fContext = (Context)OSMesaCreateContext(OSMESA_BGRA, NULL); #endif if (!fContext) { SkDebugf("OSMesaCreateContext failed!\n"); this->destroyGLContext(); return; } // Allocate the image buffer fImage = (GrGLubyte *) sk_malloc_throw(gBOGUS_SIZE * gBOGUS_SIZE * 4 * sizeof(GrGLubyte)); if (!fImage) { SkDebugf("Alloc image buffer failed!\n"); this->destroyGLContext(); return; } // Bind the buffer to the context and make it current if (!OSMesaMakeCurrent((OSMesaContext)fContext, fImage, GR_GL_UNSIGNED_BYTE, gBOGUS_SIZE, gBOGUS_SIZE)) { SkDebugf("OSMesaMakeCurrent failed!\n"); this->destroyGLContext(); return; } SkAutoTUnref<const GrGLInterface> gl(GrGLCreateMesaInterface()); if (NULL == gl.get()) { SkDebugf("Could not create GL interface!\n"); this->destroyGLContext(); return; } if (!gl->validate()) { SkDebugf("Could not validate GL interface!\n"); this->destroyGLContext(); return; } this->init(gl.detach()); }
static void GenKey(const GrXferProcessor& p, const GrGLSLCaps& caps, GrProcessorKeyBuilder* b) { const CustomXP& xp = p.cast<CustomXP>(); uint32_t key = 0; if (xp.hasHWBlendEquation()) { SkASSERT(caps.advBlendEqInteraction() > 0); // 0 will mean !xp.hasHWBlendEquation(). key |= caps.advBlendEqInteraction(); GR_STATIC_ASSERT(GrGLSLCaps::kLast_AdvBlendEqInteraction < 4); } if (!xp.hasHWBlendEquation() || caps.mustEnableSpecificAdvBlendEqs()) { key |= xp.mode() << 3; } b->add32(key); }
int GrDrawTarget::VertexTexCoordsForStage(int stage, GrVertexLayout vertexLayout) { GrAssert(stage < kNumStages); GrAssert(check_layout(vertexLayout)); int bit = vertexLayout & stage_tex_coord_mask(stage); if (bit) { // figure out which set of texture coordates is used // bits are ordered T0S0, T0S1, T0S2, ..., T1S0, T1S1, ... // and start at bit 0. GR_STATIC_ASSERT(sizeof(GrVertexLayout) <= sizeof(uint32_t)); return (32 - Gr_clz(bit) - 1) / kNumStages; } return -1; }
int GrDrawTarget::VertexTexCoordsForStage(int stageIdx, GrVertexLayout vertexLayout) { GrAssert(stageIdx < GrDrawState::kNumStages); GrAssert(check_layout(vertexLayout)); int bit = vertexLayout & gStageTexCoordMasks[stageIdx]; if (bit) { // figure out which set of texture coordates is used // bits are ordered T0S0, T0S1, T0S2, ..., T1S0, T1S1, ... // and start at bit 0. GR_STATIC_ASSERT(sizeof(GrVertexLayout) <= sizeof(uint32_t)); return (32 - SkCLZ(bit) - 1) / GrDrawState::kNumStages; } return -1; }
SkString GrGLSLCaps::dump() const { SkString r = INHERITED::dump(); static const char* kAdvBlendEqInteractionStr[] = { "Not Supported", "Automatic", "General Enable", "Specific Enables", }; GR_STATIC_ASSERT(0 == kNotSupported_AdvBlendEqInteraction); GR_STATIC_ASSERT(1 == kAutomatic_AdvBlendEqInteraction); GR_STATIC_ASSERT(2 == kGeneralEnable_AdvBlendEqInteraction); GR_STATIC_ASSERT(3 == kSpecificEnables_AdvBlendEqInteraction); GR_STATIC_ASSERT(SK_ARRAY_COUNT(kAdvBlendEqInteractionStr) == kLast_AdvBlendEqInteraction + 1); r.appendf("--- GLSL-Specific ---\n"); r.appendf("FB Fetch Support: %s\n", (fFBFetchSupport ? "YES" : "NO")); r.appendf("Drops tile on zero divide: %s\n", (fDropsTileOnZeroDivide ? "YES" : "NO")); r.appendf("Advanced blend equation interaction: %s\n", kAdvBlendEqInteractionStr[fAdvBlendEqInteraction]); return r; }
int GrShape::unstyledKeySize() const { if (fInheritedKey.count()) { return fInheritedKey.count(); } switch (fType) { case Type::kEmpty: return 1; case Type::kInvertedEmpty: return 1; case Type::kRRect: SkASSERT(!fInheritedKey.count()); GR_STATIC_ASSERT(0 == SkRRect::kSizeInMemory % sizeof(uint32_t)); // + 1 for the direction, start index, and inverseness. return SkRRect::kSizeInMemory / sizeof(uint32_t) + 1; case Type::kArc: SkASSERT(!fInheritedKey.count()); GR_STATIC_ASSERT(0 == sizeof(fArcData) % sizeof(uint32_t)); return sizeof(fArcData) / sizeof(uint32_t); case Type::kLine: GR_STATIC_ASSERT(2 * sizeof(uint32_t) == sizeof(SkPoint)); // 4 for the end points and 1 for the inverseness return 5; case Type::kPath: { if (0 == fPathData.fGenID) { return -1; } int dataKeySize = path_key_from_data_size(fPathData.fPath); if (dataKeySize >= 0) { return dataKeySize; } // The key is the path ID and fill type. return 2; } } SK_ABORT("Should never get here."); return 0; }
void GrGLCaps::print() const { for (int i = 0; i < fStencilFormats.count(); ++i) { GrPrintf("Stencil Format %d, stencil bits: %02d, total bits: %02d\n", i, fStencilFormats[i].fStencilBits, fStencilFormats[i].fTotalBits); } GR_STATIC_ASSERT(0 == kNone_MSFBOType); GR_STATIC_ASSERT(1 == kDesktopARB_MSFBOType); GR_STATIC_ASSERT(2 == kDesktopEXT_MSFBOType); GR_STATIC_ASSERT(3 == kAppleES_MSFBOType); static const char* gMSFBOExtStr[] = { "None", "ARB", "EXT", "Apple", }; GrPrintf("MSAA Type: %s\n", gMSFBOExtStr[fMSFBOType]); GrPrintf("Max FS Uniform Vectors: %d\n", fMaxFragmentUniformVectors); GrPrintf("Support RGBA8 Render Buffer: %s\n", (fRGBA8RenderbufferSupport ? "YES": "NO")); GrPrintf("BGRA is an internal format: %s\n", (fBGRAIsInternalFormat ? "YES": "NO")); GrPrintf("Support texture swizzle: %s\n", (fTextureSwizzleSupport ? "YES": "NO")); GrPrintf("Unpack Row length support: %s\n", (fUnpackRowLengthSupport ? "YES": "NO")); GrPrintf("Unpack Flip Y support: %s\n", (fUnpackFlipYSupport ? "YES": "NO")); GrPrintf("Pack Row length support: %s\n", (fPackRowLengthSupport ? "YES": "NO")); GrPrintf("Pack Flip Y support: %s\n", (fPackFlipYSupport ? "YES": "NO")); GrPrintf("Two Format Limit: %s\n", (fTwoFormatLimit ? "YES": "NO")); GrPrintf("Fragment coord conventions support: %s\n", (fFragCoordsConventionSupport ? "YES": "NO")); }
const GrIndexBuffer* getIndexBuffer(GrResourceProvider* resourceProvider) { GR_DEFINE_STATIC_UNIQUE_KEY(gAAFillRectIndexBufferKey); static const uint16_t gFillAARectIdx[] = { 0, 1, 5, 5, 4, 0, 1, 2, 6, 6, 5, 1, 2, 3, 7, 7, 6, 2, 3, 0, 4, 4, 7, 3, 4, 5, 6, 6, 7, 4, }; GR_STATIC_ASSERT(SK_ARRAY_COUNT(gFillAARectIdx) == kIndicesPerAAFillRect); return resourceProvider->refOrCreateInstancedIndexBuffer(gFillAARectIdx, kIndicesPerAAFillRect, kNumAAFillRectsInIndexBuffer, kVertsPerAAFillRect, gAAFillRectIndexBufferKey); }
static uint16_t sampler_key(GrSLType samplerType, GrPixelConfig config, GrShaderFlags visibility, const GrGLSLCaps& caps) { enum { kFirstSamplerType = kSampler2D_GrSLType, kLastSamplerType = kSamplerBuffer_GrSLType, kSamplerTypeKeyBits = 4 }; GR_STATIC_ASSERT(kLastSamplerType - kFirstSamplerType < (1 << kSamplerTypeKeyBits)); SkASSERT((int)samplerType >= kFirstSamplerType && (int)samplerType <= kLastSamplerType); int samplerTypeKey = samplerType - kFirstSamplerType; return SkToU16(caps.configTextureSwizzle(config).asKey() | (samplerTypeKey << 8) | (caps.samplerPrecision(config, visibility) << (8 + kSamplerTypeKeyBits))); }
VkStencilOp stencil_op_to_vk_stencil_op(GrStencilOp op) { static const VkStencilOp gTable[] = { VK_STENCIL_OP_KEEP, // kKeep_StencilOp VK_STENCIL_OP_REPLACE, // kReplace_StencilOp VK_STENCIL_OP_INCREMENT_AND_WRAP, // kIncWrap_StencilOp VK_STENCIL_OP_INCREMENT_AND_CLAMP, // kIncClamp_StencilOp VK_STENCIL_OP_DECREMENT_AND_WRAP, // kDecWrap_StencilOp VK_STENCIL_OP_DECREMENT_AND_CLAMP, // kDecClamp_StencilOp VK_STENCIL_OP_ZERO, // kZero_StencilOp VK_STENCIL_OP_INVERT, // kInvert_StencilOp }; GR_STATIC_ASSERT(SK_ARRAY_COUNT(gTable) == kStencilOpCount); GR_STATIC_ASSERT(0 == kKeep_StencilOp); GR_STATIC_ASSERT(1 == kReplace_StencilOp); GR_STATIC_ASSERT(2 == kIncWrap_StencilOp); GR_STATIC_ASSERT(3 == kIncClamp_StencilOp); GR_STATIC_ASSERT(4 == kDecWrap_StencilOp); GR_STATIC_ASSERT(5 == kDecClamp_StencilOp); GR_STATIC_ASSERT(6 == kZero_StencilOp); GR_STATIC_ASSERT(7 == kInvert_StencilOp); SkASSERT((unsigned)op < kStencilOpCount); return gTable[op]; }
VkStencilOp stencil_op_to_vk_stencil_op(GrStencilOp op) { static const VkStencilOp gTable[] = { VK_STENCIL_OP_KEEP, // kKeep VK_STENCIL_OP_ZERO, // kZero VK_STENCIL_OP_REPLACE, // kReplace VK_STENCIL_OP_INVERT, // kInvert VK_STENCIL_OP_INCREMENT_AND_WRAP, // kIncWrap VK_STENCIL_OP_DECREMENT_AND_WRAP, // kDecWrap VK_STENCIL_OP_INCREMENT_AND_CLAMP, // kIncClamp VK_STENCIL_OP_DECREMENT_AND_CLAMP, // kDecClamp }; GR_STATIC_ASSERT(SK_ARRAY_COUNT(gTable) == kGrStencilOpCount); GR_STATIC_ASSERT(0 == (int)GrStencilOp::kKeep); GR_STATIC_ASSERT(1 == (int)GrStencilOp::kZero); GR_STATIC_ASSERT(2 == (int)GrStencilOp::kReplace); GR_STATIC_ASSERT(3 == (int)GrStencilOp::kInvert); GR_STATIC_ASSERT(4 == (int)GrStencilOp::kIncWrap); GR_STATIC_ASSERT(5 == (int)GrStencilOp::kDecWrap); GR_STATIC_ASSERT(6 == (int)GrStencilOp::kIncClamp); GR_STATIC_ASSERT(7 == (int)GrStencilOp::kDecClamp); SkASSERT(op < (GrStencilOp)kGrStencilOpCount); return gTable[(int)op]; }