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 sk_sp<const GrBuffer> get_index_buffer(GrResourceProvider* resourceProvider) { GR_DEFINE_STATIC_UNIQUE_KEY(gAAFillRectIndexBufferKey); // clang-format off 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, }; // clang-format on GR_STATIC_ASSERT(SK_ARRAY_COUNT(gFillAARectIdx) == kIndicesPerAAFillRect); return resourceProvider->findOrCreatePatternedIndexBuffer( gFillAARectIdx, kIndicesPerAAFillRect, kNumAAFillRectsInIndexBuffer, kVertsPerAAFillRect, gAAFillRectIndexBufferKey); }
GrResourceProvider::GrResourceProvider(GrGpu* gpu, GrResourceCache* cache, GrSingleOwner* owner, GrContextOptions::Enable explicitlyAllocateGPUResources) : fCache(cache) , fGpu(gpu) #ifdef SK_DEBUG , fSingleOwner(owner) #endif { if (GrContextOptions::Enable::kNo == explicitlyAllocateGPUResources) { fExplicitlyAllocateGPUResources = false; } else if (GrContextOptions::Enable::kYes == explicitlyAllocateGPUResources) { fExplicitlyAllocateGPUResources = true; } else { fExplicitlyAllocateGPUResources = kDefaultExplicitlyAllocateGPUResources; } fCaps = sk_ref_sp(fGpu->caps()); GR_DEFINE_STATIC_UNIQUE_KEY(gQuadIndexBufferKey); fQuadIndexBufferKey = gQuadIndexBufferKey; }
static const GrIndexBuffer* ref_quads_index_buffer(GrResourceProvider* resourceProvider) { GR_DEFINE_STATIC_UNIQUE_KEY(gQuadsIndexBufferKey); return resourceProvider->findOrCreateInstancedIndexBuffer( kQuadIdxBufPattern, kIdxsPerQuad, kQuadsNumInIdxBuffer, kQuadNumVertices, gQuadsIndexBufferKey); }
static const GrIndexBuffer* ref_lines_index_buffer(GrResourceProvider* resourceProvider) { GR_DEFINE_STATIC_UNIQUE_KEY(gLinesIndexBufferKey); return resourceProvider->findOrCreateInstancedIndexBuffer( kLineSegIdxBufPattern, kIdxsPerLineSeg, kLineSegsNumInIdxBuffer, kLineSegNumVertices, gLinesIndexBufferKey); }
static const GrUniqueKey& get_layer_atlas_key() { GR_DEFINE_STATIC_UNIQUE_KEY(gLayerAtlasKey); return gLayerAtlasKey; }
sk_sp<GrBuffer> GrCCPRPathProcessor::FindOrMakeVertexBuffer(GrOnFlushResourceProvider* onFlushRP) { GR_DEFINE_STATIC_UNIQUE_KEY(gVertexBufferKey); return onFlushRP->findOrMakeStaticBuffer(gVertexBufferKey, kVertex_GrBufferType, sizeof(kOctoEdgeNorms), kOctoEdgeNorms); }
GrResourceProvider::GrResourceProvider(GrGpu* gpu, GrResourceCache* cache) : INHERITED(gpu, cache) { GR_DEFINE_STATIC_UNIQUE_KEY(gQuadIndexBufferKey); fQuadIndexBufferKey = gQuadIndexBufferKey; }
static const GrIndexBuffer* GetIndexBuffer(GrResourceProvider* resourceProvider, bool miterStroke) { if (miterStroke) { static const uint16_t gMiterIndices[] = { 0 + 0, 1 + 0, 5 + 0, 5 + 0, 4 + 0, 0 + 0, 1 + 0, 2 + 0, 6 + 0, 6 + 0, 5 + 0, 1 + 0, 2 + 0, 3 + 0, 7 + 0, 7 + 0, 6 + 0, 2 + 0, 3 + 0, 0 + 0, 4 + 0, 4 + 0, 7 + 0, 3 + 0, 0 + 4, 1 + 4, 5 + 4, 5 + 4, 4 + 4, 0 + 4, 1 + 4, 2 + 4, 6 + 4, 6 + 4, 5 + 4, 1 + 4, 2 + 4, 3 + 4, 7 + 4, 7 + 4, 6 + 4, 2 + 4, 3 + 4, 0 + 4, 4 + 4, 4 + 4, 7 + 4, 3 + 4, 0 + 8, 1 + 8, 5 + 8, 5 + 8, 4 + 8, 0 + 8, 1 + 8, 2 + 8, 6 + 8, 6 + 8, 5 + 8, 1 + 8, 2 + 8, 3 + 8, 7 + 8, 7 + 8, 6 + 8, 2 + 8, 3 + 8, 0 + 8, 4 + 8, 4 + 8, 7 + 8, 3 + 8, }; GR_STATIC_ASSERT(SK_ARRAY_COUNT(gMiterIndices) == kMiterIndexCnt); GR_DEFINE_STATIC_UNIQUE_KEY(gMiterIndexBufferKey); return resourceProvider->refOrCreateInstancedIndexBuffer(gMiterIndices, kMiterIndexCnt, kNumMiterRectsInIndexBuffer, kMiterVertexCnt, gMiterIndexBufferKey); } else { /** * As in miter-stroke, index = a + b, and a is the current index, b is the shift * from the first index. The index layout: * outer AA line: 0~3, 4~7 * outer edge: 8~11, 12~15 * inner edge: 16~19 * inner AA line: 20~23 * Following comes a bevel-stroke rect and its indices: * * 4 7 * ********************************* * * ______________________________ * * * / 12 15 \ * * * / \ * * 0 * |8 16_____________________19 11 | * 3 * * | | | | * * * | | **************** | | * * * | | * 20 23 * | | * * * | | * * | | * * * | | * 21 22 * | | * * * | | **************** | | * * * | |____________________| | * * 1 * |9 17 18 10| * 2 * * \ / * * * \13 __________________________14/ * * * * * ********************************** * 5 6 */ static const uint16_t gBevelIndices[] = { // Draw outer AA, from outer AA line to outer edge, shift is 0. 0 + 0, 1 + 0, 9 + 0, 9 + 0, 8 + 0, 0 + 0, 1 + 0, 5 + 0, 13 + 0, 13 + 0, 9 + 0, 1 + 0, 5 + 0, 6 + 0, 14 + 0, 14 + 0, 13 + 0, 5 + 0, 6 + 0, 2 + 0, 10 + 0, 10 + 0, 14 + 0, 6 + 0, 2 + 0, 3 + 0, 11 + 0, 11 + 0, 10 + 0, 2 + 0, 3 + 0, 7 + 0, 15 + 0, 15 + 0, 11 + 0, 3 + 0, 7 + 0, 4 + 0, 12 + 0, 12 + 0, 15 + 0, 7 + 0, 4 + 0, 0 + 0, 8 + 0, 8 + 0, 12 + 0, 4 + 0, // Draw the stroke, from outer edge to inner edge, shift is 8. 0 + 8, 1 + 8, 9 + 8, 9 + 8, 8 + 8, 0 + 8, 1 + 8, 5 + 8, 9 + 8, 5 + 8, 6 + 8, 10 + 8, 10 + 8, 9 + 8, 5 + 8, 6 + 8, 2 + 8, 10 + 8, 2 + 8, 3 + 8, 11 + 8, 11 + 8, 10 + 8, 2 + 8, 3 + 8, 7 + 8, 11 + 8, 7 + 8, 4 + 8, 8 + 8, 8 + 8, 11 + 8, 7 + 8, 4 + 8, 0 + 8, 8 + 8, // Draw the inner AA, from inner edge to inner AA line, shift is 16. 0 + 16, 1 + 16, 5 + 16, 5 + 16, 4 + 16, 0 + 16, 1 + 16, 2 + 16, 6 + 16, 6 + 16, 5 + 16, 1 + 16, 2 + 16, 3 + 16, 7 + 16, 7 + 16, 6 + 16, 2 + 16, 3 + 16, 0 + 16, 4 + 16, 4 + 16, 7 + 16, 3 + 16, }; GR_STATIC_ASSERT(SK_ARRAY_COUNT(gBevelIndices) == kBevelIndexCnt); GR_DEFINE_STATIC_UNIQUE_KEY(gBevelIndexBufferKey); return resourceProvider->refOrCreateInstancedIndexBuffer(gBevelIndices, kBevelIndexCnt, kNumBevelRectsInIndexBuffer, kBevelVertexCnt, gBevelIndexBufferKey); } }
void GrFillRRectOp::onExecute(GrOpFlushState* flushState, const SkRect& chainBounds) { if (!fInstanceBuffer) { return; // Setup failed. } sk_sp<const GrBuffer> indexBuffer, vertexBuffer; int indexCount; if (GrAAType::kCoverage == fAAType) { GR_DEFINE_STATIC_UNIQUE_KEY(gCoverageIndexBufferKey); indexBuffer = flushState->resourceProvider()->findOrMakeStaticBuffer( GrGpuBufferType::kIndex, sizeof(kCoverageIndexData), kCoverageIndexData, gCoverageIndexBufferKey); GR_DEFINE_STATIC_UNIQUE_KEY(gCoverageVertexBufferKey); vertexBuffer = flushState->resourceProvider()->findOrMakeStaticBuffer( GrGpuBufferType::kVertex, sizeof(kCoverageVertexData), kCoverageVertexData, gCoverageVertexBufferKey); indexCount = SK_ARRAY_COUNT(kCoverageIndexData); } else { GR_DEFINE_STATIC_UNIQUE_KEY(gMSAAIndexBufferKey); indexBuffer = flushState->resourceProvider()->findOrMakeStaticBuffer( GrGpuBufferType::kIndex, sizeof(kMSAAIndexData), kMSAAIndexData, gMSAAIndexBufferKey); GR_DEFINE_STATIC_UNIQUE_KEY(gMSAAVertexBufferKey); vertexBuffer = flushState->resourceProvider()->findOrMakeStaticBuffer( GrGpuBufferType::kVertex, sizeof(kMSAAVertexData), kMSAAVertexData, gMSAAVertexBufferKey); indexCount = SK_ARRAY_COUNT(kMSAAIndexData); } if (!indexBuffer || !vertexBuffer) { return; } Processor proc(fAAType, fFlags); SkASSERT(proc.instanceStride() == (size_t)fInstanceStride); GrPipeline::InitArgs initArgs; if (GrAAType::kMSAA == fAAType) { initArgs.fInputFlags = GrPipeline::InputFlags::kHWAntialias; } initArgs.fCaps = &flushState->caps(); initArgs.fResourceProvider = flushState->resourceProvider(); initArgs.fDstProxy = flushState->drawOpArgs().fDstProxy; auto clip = flushState->detachAppliedClip(); GrPipeline::FixedDynamicState fixedDynamicState(clip.scissorState().rect()); GrPipeline pipeline(initArgs, std::move(fProcessors), std::move(clip)); GrMesh mesh(GrPrimitiveType::kTriangles); mesh.setIndexedInstanced( std::move(indexBuffer), indexCount, fInstanceBuffer, fInstanceCount, fBaseInstance, GrPrimitiveRestart::kNo); mesh.setVertexData(std::move(vertexBuffer)); flushState->rtCommandBuffer()->draw( proc, pipeline, &fixedDynamicState, nullptr, &mesh, 1, this->bounds()); }