@@ -425,7 +425,6 @@ GrGLGpu::~GrGLGpu() {
425425 fCopyProgramArrayBuffer .reset ();
426426 fMipmapProgramArrayBuffer .reset ();
427427
428- fHWProgram .reset ();
429428 if (fHWProgramID ) {
430429 // detach the current program so there is no confusion on OpenGL's part
431430 // that we want it to be deleted
@@ -501,7 +500,6 @@ void GrGLGpu::disconnect(DisconnectType type) {
501500 }
502501 }
503502
504- fHWProgram .reset ();
505503 fProgramCache .reset ();
506504
507505 fHWProgramID = 0 ;
@@ -662,7 +660,6 @@ void GrGLGpu::onResetContext(uint32_t resetBits) {
662660
663661 if (resetBits & kProgram_GrGLBackendState ) {
664662 fHWProgramID = 0 ;
665- fHWProgram .reset ();
666663 }
667664 ++fResetTimestampForTextureParameters ;
668665}
@@ -1765,6 +1762,7 @@ void GrGLGpu::flushScissorTest(GrScissorTest scissorTest) {
17651762
17661763void GrGLGpu::flushScissorRect (const SkIRect& scissor, int rtWidth, int rtHeight,
17671764 GrSurfaceOrigin rtOrigin) {
1765+ SkASSERT (TriState::kYes_TriState == fHWScissorSettings .fEnabled );
17681766 auto nativeScissor = GrNativeRect::MakeRelativeTo (rtOrigin, rtHeight, scissor);
17691767 if (fHWScissorSettings .fRect != nativeScissor) {
17701768 GL_CALL (Scissor (nativeScissor.fX , nativeScissor.fY , nativeScissor.fWidth ,
@@ -1813,26 +1811,27 @@ void GrGLGpu::disableWindowRectangles() {
18131811#endif
18141812}
18151813
1816- bool GrGLGpu::flushGLState (GrRenderTarget* renderTarget, const GrProgramInfo& programInfo) {
1814+ sk_sp<GrGLProgram> GrGLGpu::flushGLState (GrRenderTarget* renderTarget,
1815+ const GrProgramInfo& programInfo) {
18171816 this ->handleDirtyContext ();
18181817
1819- if (GrPrimitiveType::kPatches == programInfo.primitiveType ()) {
1820- this ->flushPatchVertexCount (programInfo.tessellationPatchVertexCount ());
1821- }
1822-
1823- sk_sp<GrGLProgram> program (fProgramCache ->findOrCreateProgram (renderTarget, programInfo));
1818+ sk_sp<GrGLProgram> program = fProgramCache ->findOrCreateProgram (renderTarget, programInfo);
18241819 if (!program) {
18251820 GrCapsDebugf (this ->caps (), " Failed to create program!\n " );
1826- return false ;
1821+ return nullptr ;
18271822 }
18281823
1829- this ->flushProgram (std::move (program));
1824+ this ->flushProgram (program->programID ());
1825+
1826+ if (GrPrimitiveType::kPatches == programInfo.primitiveType ()) {
1827+ this ->flushPatchVertexCount (programInfo.tessellationPatchVertexCount ());
1828+ }
18301829
18311830 // Swizzle the blend to match what the shader will output.
18321831 this ->flushBlendAndColorWrite (programInfo.pipeline ().getXferProcessor ().getBlendInfo (),
18331832 programInfo.pipeline ().outputSwizzle ());
18341833
1835- fHWProgram ->updateUniforms (renderTarget, programInfo);
1834+ program ->updateUniforms (renderTarget, programInfo);
18361835
18371836 GrGLRenderTarget* glRT = static_cast <GrGLRenderTarget*>(renderTarget);
18381837 GrStencilSettings stencil;
@@ -1854,85 +1853,18 @@ bool GrGLGpu::flushGLState(GrRenderTarget* renderTarget, const GrProgramInfo& pr
18541853 // to be msaa-resolved (which will modify bound FBO state).
18551854 this ->flushRenderTarget (glRT);
18561855
1857- return true ;
1858- }
1859-
1860- void GrGLGpu::flushProgram (sk_sp<GrGLProgram> program) {
1861- if (!program) {
1862- fHWProgram .reset ();
1863- fHWProgramID = 0 ;
1864- return ;
1865- }
1866- SkASSERT ((program == fHWProgram ) == (fHWProgramID == program->programID ()));
1867- if (program == fHWProgram ) {
1868- return ;
1869- }
1870- auto id = program->programID ();
1871- SkASSERT (id);
1872- GL_CALL (UseProgram (id));
1873- fHWProgram = std::move (program);
1874- fHWProgramID = id;
1856+ return program;
18751857}
18761858
18771859void GrGLGpu::flushProgram (GrGLuint id) {
18781860 SkASSERT (id);
18791861 if (fHWProgramID == id) {
1880- SkASSERT (!fHWProgram );
18811862 return ;
18821863 }
1883- fHWProgram .reset ();
18841864 GL_CALL (UseProgram (id));
18851865 fHWProgramID = id;
18861866}
18871867
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-
19361868GrGLenum GrGLGpu::bindBuffer (GrGpuBufferType type, const GrBuffer* buffer) {
19371869 this ->handleDirtyContext ();
19381870
@@ -2325,6 +2257,8 @@ void GrGLGpu::flushViewport(int width, int height) {
23252257}
23262258
23272259GrGLenum GrGLGpu::prepareToDraw (GrPrimitiveType primitiveType) {
2260+ fStats .incNumDraws ();
2261+
23282262 if (this ->glCaps ().requiresCullFaceEnableDisableWhenDrawingLinesAfterNonLines () &&
23292263 GrIsPrimTypeLines (primitiveType) && !GrIsPrimTypeLines (fLastPrimitiveType )) {
23302264 GL_CALL (Enable (GR_GL_CULL_FACE));
@@ -2352,72 +2286,40 @@ GrGLenum GrGLGpu::prepareToDraw(GrPrimitiveType primitiveType) {
23522286 SK_ABORT (" invalid GrPrimitiveType" );
23532287}
23542288
2355- void GrGLGpu::draw (GrPrimitiveType primitiveType, const GrBuffer* vertexBuffer, int vertexCount,
2356- int baseVertex) {
2289+ void GrGLGpu::drawArrays (GrPrimitiveType primitiveType, GrGLint baseVertex, GrGLsizei vertexCount) {
2290+ SkASSERT (! this -> glCaps (). drawArraysBaseVertexIsBroken () || 0 == baseVertex);
23572291 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 ();
2292+ GL_CALL (DrawArrays (glPrimType, baseVertex, vertexCount));
23662293}
23672294
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- }
2295+ void GrGLGpu::drawElements (GrPrimitiveType primitiveType, GrGLsizei indexCount, GrGLenum indexType,
2296+ const void * indices) {
2297+ GrGLenum glPrimType = this ->prepareToDraw (primitiveType);
2298+ GL_CALL (DrawElements (glPrimType, indexCount, indexType, indices));
23752299}
23762300
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) {
2301+ void GrGLGpu::drawRangeElements (GrPrimitiveType primitiveType, GrGLuint minIndexValue ,
2302+ GrGLuint maxIndexValue, GrGLsizei indexCount, GrGLenum indexType ,
2303+ const void * indices) {
2304+ SkASSERT ( this -> glCaps (). drawRangeElementsSupport ());
23812305 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 ();
2306+ GL_CALL (DrawRangeElements (glPrimType, minIndexValue, maxIndexValue, indexCount, indexType,
2307+ indices));
23912308}
23922309
2393- void GrGLGpu::drawInstanced (GrPrimitiveType primitiveType, const GrBuffer* instanceBuffer ,
2394- int instanceCount, int baseInstance, const GrBuffer* vertexBuffer,
2395- int vertexCount, int baseVertex) {
2310+ void GrGLGpu::drawArraysInstanced (GrPrimitiveType primitiveType, GrGLint baseVertex ,
2311+ GrGLsizei vertexCount, GrGLsizei instanceCount) {
2312+ SkASSERT (instanceCount <= this -> glCaps (). maxInstancesPerDrawWithoutCrashing (instanceCount));
23962313 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- }
2314+ GL_CALL (DrawArraysInstanced (glPrimType, baseVertex, vertexCount, instanceCount));
24052315}
24062316
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) {
2317+ void GrGLGpu::drawElementsInstanced (GrPrimitiveType primitiveType, GrGLsizei indexCount,
2318+ GrGLenum indexType, const void * indices ,
2319+ GrGLsizei instanceCount) {
2320+ SkASSERT (instanceCount <= this -> glCaps (). maxInstancesPerDrawWithoutCrashing (instanceCount));
24112321 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- }
2322+ GL_CALL (DrawElementsInstanced (glPrimType, indexCount, indexType, indices, instanceCount));
24212323}
24222324
24232325void GrGLGpu::onResolveRenderTarget (GrRenderTarget* target, const SkIRect& resolveRect,
@@ -3922,6 +3824,7 @@ void GrGLGpu::testingOnly_flushGpuAndSync() {
39223824
39233825GrGLAttribArrayState* GrGLGpu::HWVertexArrayState::bindInternalVertexArray (GrGLGpu* gpu,
39243826 const GrBuffer* ibuf) {
3827+ SkASSERT (!ibuf || ibuf->isCpuBuffer () || !static_cast <const GrGpuBuffer*>(ibuf)->isMapped ());
39253828 GrGLAttribArrayState* attribState;
39263829
39273830 if (gpu->glCaps ().isCoreProfile ()) {
0 commit comments