@@ -1765,6 +1765,7 @@ void GrGLGpu::flushScissorTest(GrScissorTest scissorTest) {
17651765
17661766void GrGLGpu::flushScissorRect (const SkIRect& scissor, int rtWidth, int rtHeight,
17671767 GrSurfaceOrigin rtOrigin) {
1768+ SkASSERT (fHWScissorSettings .fEnabled == TriState::kYes_TriState );
17681769 auto nativeScissor = GrNativeRect::MakeRelativeTo (rtOrigin, rtHeight, scissor);
17691770 if (fHWScissorSettings .fRect != nativeScissor) {
17701771 GL_CALL (Scissor (nativeScissor.fX , nativeScissor.fY , nativeScissor.fWidth ,
@@ -1813,21 +1814,22 @@ void GrGLGpu::disableWindowRectangles() {
18131814#endif
18141815}
18151816
1816- bool GrGLGpu::flushGLState (GrRenderTarget* renderTarget, const GrProgramInfo& programInfo) {
1817+ bool GrGLGpu::flushGLState (GrRenderTarget* renderTarget,
1818+ const GrProgramInfo& programInfo) {
18171819 this ->handleDirtyContext ();
18181820
1819- if (GrPrimitiveType::kPatches == programInfo.primitiveType ()) {
1820- this ->flushPatchVertexCount (programInfo.tessellationPatchVertexCount ());
1821- }
1822-
1823- sk_sp<GrGLProgram> program (fProgramCache ->findOrCreateProgram (renderTarget, programInfo));
1821+ sk_sp<GrGLProgram> program = fProgramCache ->findOrCreateProgram (renderTarget, programInfo);
18241822 if (!program) {
18251823 GrCapsDebugf (this ->caps (), " Failed to create program!\n " );
18261824 return false ;
18271825 }
18281826
18291827 this ->flushProgram (std::move (program));
18301828
1829+ if (GrPrimitiveType::kPatches == programInfo.primitiveType ()) {
1830+ this ->flushPatchVertexCount (programInfo.tessellationPatchVertexCount ());
1831+ }
1832+
18311833 // Swizzle the blend to match what the shader will output.
18321834 this ->flushBlendAndColorWrite (programInfo.pipeline ().getXferProcessor ().getBlendInfo (),
18331835 programInfo.pipeline ().outputSwizzle ());
@@ -1885,54 +1887,6 @@ void GrGLGpu::flushProgram(GrGLuint id) {
18851887 fHWProgramID = id;
18861888}
18871889
1888- void GrGLGpu::setupGeometry (const GrBuffer* indexBuffer,
1889- const GrBuffer* vertexBuffer,
1890- int baseVertex,
1891- const GrBuffer* instanceBuffer,
1892- int baseInstance,
1893- GrPrimitiveRestart enablePrimitiveRestart) {
1894- SkASSERT ((enablePrimitiveRestart == GrPrimitiveRestart::kNo ) || indexBuffer);
1895-
1896- GrGLAttribArrayState* attribState;
1897- if (indexBuffer) {
1898- SkASSERT (indexBuffer->isCpuBuffer () ||
1899- !static_cast <const GrGpuBuffer*>(indexBuffer)->isMapped ());
1900- attribState = fHWVertexArrayState .bindInternalVertexArray (this , indexBuffer);
1901- } else {
1902- attribState = fHWVertexArrayState .bindInternalVertexArray (this );
1903- }
1904-
1905- int numAttribs = fHWProgram ->numVertexAttributes () + fHWProgram ->numInstanceAttributes ();
1906- attribState->enableVertexArrays (this , numAttribs, enablePrimitiveRestart);
1907-
1908- if (int vertexStride = fHWProgram ->vertexStride ()) {
1909- SkASSERT (vertexBuffer);
1910- SkASSERT (vertexBuffer->isCpuBuffer () ||
1911- !static_cast <const GrGpuBuffer*>(vertexBuffer)->isMapped ());
1912- size_t bufferOffset = baseVertex * static_cast <size_t >(vertexStride);
1913- for (int i = 0 ; i < fHWProgram ->numVertexAttributes (); ++i) {
1914- const auto & attrib = fHWProgram ->vertexAttribute (i);
1915- static constexpr int kDivisor = 0 ;
1916- attribState->set (this , attrib.fLocation , vertexBuffer, attrib.fCPUType , attrib.fGPUType ,
1917- vertexStride, bufferOffset + attrib.fOffset , kDivisor );
1918- }
1919- }
1920- if (int instanceStride = fHWProgram ->instanceStride ()) {
1921- SkASSERT (instanceBuffer);
1922- SkASSERT (instanceBuffer->isCpuBuffer () ||
1923- !static_cast <const GrGpuBuffer*>(instanceBuffer)->isMapped ());
1924- size_t bufferOffset = baseInstance * static_cast <size_t >(instanceStride);
1925- int attribIdx = fHWProgram ->numVertexAttributes ();
1926- for (int i = 0 ; i < fHWProgram ->numInstanceAttributes (); ++i, ++attribIdx) {
1927- const auto & attrib = fHWProgram ->instanceAttribute (i);
1928- static constexpr int kDivisor = 1 ;
1929- attribState->set (this , attrib.fLocation , instanceBuffer, attrib.fCPUType ,
1930- attrib.fGPUType , instanceStride, bufferOffset + attrib.fOffset ,
1931- kDivisor );
1932- }
1933- }
1934- }
1935-
19361890GrGLenum GrGLGpu::bindBuffer (GrGpuBufferType type, const GrBuffer* buffer) {
19371891 this ->handleDirtyContext ();
19381892
@@ -2325,6 +2279,8 @@ void GrGLGpu::flushViewport(int width, int height) {
23252279}
23262280
23272281GrGLenum GrGLGpu::prepareToDraw (GrPrimitiveType primitiveType) {
2282+ fStats .incNumDraws ();
2283+
23282284 if (this ->glCaps ().requiresCullFaceEnableDisableWhenDrawingLinesAfterNonLines () &&
23292285 GrIsPrimTypeLines (primitiveType) && !GrIsPrimTypeLines (fLastPrimitiveType )) {
23302286 GL_CALL (Enable (GR_GL_CULL_FACE));
@@ -2352,72 +2308,40 @@ GrGLenum GrGLGpu::prepareToDraw(GrPrimitiveType primitiveType) {
23522308 SK_ABORT (" invalid GrPrimitiveType" );
23532309}
23542310
2355- void GrGLGpu::draw (GrPrimitiveType primitiveType, const GrBuffer* vertexBuffer, int vertexCount,
2356- int baseVertex) {
2311+ void GrGLGpu::drawArrays (GrPrimitiveType primitiveType, GrGLint baseVertex, GrGLsizei vertexCount) {
2312+ SkASSERT (! this -> glCaps (). drawArraysBaseVertexIsBroken () || 0 == baseVertex);
23572313 GrGLenum glPrimType = this ->prepareToDraw (primitiveType);
2358- if (this ->glCaps ().drawArraysBaseVertexIsBroken ()) {
2359- this ->setupGeometry (nullptr , vertexBuffer, baseVertex, nullptr , 0 , GrPrimitiveRestart::kNo );
2360- GL_CALL (DrawArrays (glPrimType, 0 , vertexCount));
2361- } else {
2362- this ->setupGeometry (nullptr , vertexBuffer, 0 , nullptr , 0 , GrPrimitiveRestart::kNo );
2363- GL_CALL (DrawArrays (glPrimType, baseVertex, vertexCount));
2364- }
2365- fStats .incNumDraws ();
2314+ GL_CALL (DrawArrays (glPrimType, baseVertex, vertexCount));
23662315}
23672316
2368- static const GrGLvoid* element_ptr (const GrBuffer* indexBuffer, int baseIndex) {
2369- size_t baseOffset = baseIndex * sizeof (uint16_t );
2370- if (indexBuffer->isCpuBuffer ()) {
2371- return static_cast <const GrCpuBuffer*>(indexBuffer)->data () + baseOffset;
2372- } else {
2373- return reinterpret_cast <const GrGLvoid*>(baseOffset);
2374- }
2317+ void GrGLGpu::drawElements (GrPrimitiveType primitiveType, GrGLsizei indexCount, GrGLenum indexType,
2318+ const void * indices) {
2319+ GrGLenum glPrimType = this ->prepareToDraw (primitiveType);
2320+ GL_CALL (DrawElements (glPrimType, indexCount, indexType, indices));
23752321}
23762322
2377- void GrGLGpu::drawIndexed (GrPrimitiveType primitiveType, const GrBuffer* indexBuffer ,
2378- int indexCount, int baseIndex, GrPrimitiveRestart primitiveRestart ,
2379- uint16_t minIndexValue, uint16_t maxIndexValue,
2380- const GrBuffer* vertexBuffer, int baseVertex) {
2323+ void GrGLGpu::drawRangeElements (GrPrimitiveType primitiveType, GrGLuint minIndexValue ,
2324+ GrGLuint maxIndexValue, GrGLsizei indexCount, GrGLenum indexType ,
2325+ const void * indices) {
2326+ SkASSERT ( this -> glCaps (). drawRangeElementsSupport ());
23812327 GrGLenum glPrimType = this ->prepareToDraw (primitiveType);
2382- const GrGLvoid* elementPtr = element_ptr (indexBuffer, baseIndex);
2383- this ->setupGeometry (indexBuffer, vertexBuffer, baseVertex, nullptr , 0 , primitiveRestart);
2384- if (this ->glCaps ().drawRangeElementsSupport ()) {
2385- GL_CALL (DrawRangeElements (glPrimType, minIndexValue, maxIndexValue, indexCount,
2386- GR_GL_UNSIGNED_SHORT, elementPtr));
2387- } else {
2388- GL_CALL (DrawElements (glPrimType, indexCount, GR_GL_UNSIGNED_SHORT, elementPtr));
2389- }
2390- fStats .incNumDraws ();
2328+ GL_CALL (DrawRangeElements (glPrimType, minIndexValue, maxIndexValue, indexCount, indexType,
2329+ indices));
23912330}
23922331
2393- void GrGLGpu::drawInstanced (GrPrimitiveType primitiveType, const GrBuffer* instanceBuffer ,
2394- int instanceCount, int baseInstance, const GrBuffer* vertexBuffer,
2395- int vertexCount, int baseVertex) {
2332+ void GrGLGpu::drawArraysInstanced (GrPrimitiveType primitiveType, GrGLint baseVertex ,
2333+ GrGLsizei vertexCount, GrGLsizei instanceCount) {
2334+ SkASSERT (instanceCount <= this -> glCaps (). maxInstancesPerDrawWithoutCrashing (instanceCount));
23962335 GrGLenum glPrimType = this ->prepareToDraw (primitiveType);
2397- int maxInstances = this ->glCaps ().maxInstancesPerDrawWithoutCrashing (instanceCount);
2398- for (int i = 0 ; i < instanceCount; i += maxInstances) {
2399- this ->setupGeometry (nullptr , vertexBuffer, 0 , instanceBuffer, baseInstance + i,
2400- GrPrimitiveRestart::kNo );
2401- GL_CALL (DrawArraysInstanced (glPrimType, baseVertex, vertexCount,
2402- std::min (instanceCount - i, maxInstances)));
2403- fStats .incNumDraws ();
2404- }
2336+ GL_CALL (DrawArraysInstanced (glPrimType, baseVertex, vertexCount, instanceCount));
24052337}
24062338
2407- void GrGLGpu::drawIndexedInstanced (
2408- GrPrimitiveType primitiveType, const GrBuffer* indexBuffer, int indexCount, int baseIndex ,
2409- GrPrimitiveRestart primitiveRestart, const GrBuffer* instanceBuffer, int instanceCount,
2410- int baseInstance, const GrBuffer* vertexBuffer, int baseVertex) {
2339+ void GrGLGpu::drawElementsInstanced (GrPrimitiveType primitiveType, GrGLsizei indexCount,
2340+ GrGLenum indexType, const void * indices ,
2341+ GrGLsizei instanceCount) {
2342+ SkASSERT (instanceCount <= this -> glCaps (). maxInstancesPerDrawWithoutCrashing (instanceCount));
24112343 GrGLenum glPrimType = this ->prepareToDraw (primitiveType);
2412- const GrGLvoid* elementPtr = element_ptr (indexBuffer, baseIndex);
2413- int maxInstances = this ->glCaps ().maxInstancesPerDrawWithoutCrashing (instanceCount);
2414- for (int i = 0 ; i < instanceCount; i += maxInstances) {
2415- this ->setupGeometry (indexBuffer, vertexBuffer, baseVertex,
2416- instanceBuffer, baseInstance + i, primitiveRestart);
2417- GL_CALL (DrawElementsInstanced (glPrimType, indexCount, GR_GL_UNSIGNED_SHORT, elementPtr,
2418- std::min (instanceCount - i, maxInstances)));
2419- fStats .incNumDraws ();
2420- }
2344+ GL_CALL (DrawElementsInstanced (glPrimType, indexCount, indexType, indices, instanceCount));
24212345}
24222346
24232347void GrGLGpu::onResolveRenderTarget (GrRenderTarget* target, const SkIRect& resolveRect,
@@ -3922,6 +3846,7 @@ void GrGLGpu::testingOnly_flushGpuAndSync() {
39223846
39233847GrGLAttribArrayState* GrGLGpu::HWVertexArrayState::bindInternalVertexArray (GrGLGpu* gpu,
39243848 const GrBuffer* ibuf) {
3849+ SkASSERT (!ibuf || ibuf->isCpuBuffer () || !static_cast <const GrGpuBuffer*>(ibuf)->isMapped ());
39253850 GrGLAttribArrayState* attribState;
39263851
39273852 if (gpu->glCaps ().isCoreProfile ()) {
0 commit comments