| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2011 Google Inc. | 2 * Copyright 2011 Google Inc. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 | 8 |
| 9 #include "GrGLGpu.h" | 9 #include "GrGLGpu.h" |
| 10 #include "GrGLGLSL.h" | 10 #include "GrGLGLSL.h" |
| (...skipping 425 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 436 } | 436 } |
| 437 fHWWriteToColor = kUnknown_TriState; | 437 fHWWriteToColor = kUnknown_TriState; |
| 438 // we only ever use lines in hairline mode | 438 // we only ever use lines in hairline mode |
| 439 GL_CALL(LineWidth(1)); | 439 GL_CALL(LineWidth(1)); |
| 440 GL_CALL(Disable(GR_GL_DITHER)); | 440 GL_CALL(Disable(GR_GL_DITHER)); |
| 441 } | 441 } |
| 442 | 442 |
| 443 if (resetBits & kMSAAEnable_GrGLBackendState) { | 443 if (resetBits & kMSAAEnable_GrGLBackendState) { |
| 444 fMSAAEnabled = kUnknown_TriState; | 444 fMSAAEnabled = kUnknown_TriState; |
| 445 | 445 |
| 446 // In mixed samples mode coverage modulation allows the coverage to be c
onverted to | |
| 447 // "opacity", which can then be blended into the color buffer to accompl
ish antialiasing. | |
| 448 // Enable coverage modulation suitable for premultiplied alpha colors. | |
| 449 // This state has no effect when not rendering to a mixed sampled target
. | |
| 450 if (this->caps()->usesMixedSamples()) { | 446 if (this->caps()->usesMixedSamples()) { |
| 447 if (0 != this->caps()->maxRasterSamples()) { |
| 448 fHWRasterMultisampleEnabled = kUnknown_TriState; |
| 449 fHWNumRasterSamples = 0; |
| 450 } |
| 451 |
| 452 // The skia blend modes all use premultiplied alpha and therefore ex
pect RGBA coverage |
| 453 // modulation. This state has no effect when not rendering to a mixe
d sampled target. |
| 451 GL_CALL(CoverageModulation(GR_GL_RGBA)); | 454 GL_CALL(CoverageModulation(GR_GL_RGBA)); |
| 452 } | 455 } |
| 453 } | 456 } |
| 454 | 457 |
| 455 fHWActiveTextureUnitIdx = -1; // invalid | 458 fHWActiveTextureUnitIdx = -1; // invalid |
| 456 | 459 |
| 457 if (resetBits & kTextureBinding_GrGLBackendState) { | 460 if (resetBits & kTextureBinding_GrGLBackendState) { |
| 458 for (int s = 0; s < fHWBoundTextureUniqueIDs.count(); ++s) { | 461 for (int s = 0; s < fHWBoundTextureUniqueIDs.count(); ++s) { |
| 459 fHWBoundTextureUniqueIDs[s] = SK_InvalidUniqueID; | 462 fHWBoundTextureUniqueIDs[s] = SK_InvalidUniqueID; |
| 460 } | 463 } |
| (...skipping 1243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1704 | 1707 |
| 1705 int numTextureAccesses = textureAccesses.count(); | 1708 int numTextureAccesses = textureAccesses.count(); |
| 1706 for (int i = 0; i < numTextureAccesses; i++) { | 1709 for (int i = 0; i < numTextureAccesses; i++) { |
| 1707 this->bindTexture(i, textureAccesses[i]->getParams(), | 1710 this->bindTexture(i, textureAccesses[i]->getParams(), |
| 1708 static_cast<GrGLTexture*>(textureAccesses[i]->getTextu
re())); | 1711 static_cast<GrGLTexture*>(textureAccesses[i]->getTextu
re())); |
| 1709 } | 1712 } |
| 1710 | 1713 |
| 1711 GrGLRenderTarget* glRT = static_cast<GrGLRenderTarget*>(pipeline.getRenderTa
rget()); | 1714 GrGLRenderTarget* glRT = static_cast<GrGLRenderTarget*>(pipeline.getRenderTa
rget()); |
| 1712 this->flushStencil(pipeline.getStencil()); | 1715 this->flushStencil(pipeline.getStencil()); |
| 1713 this->flushScissor(pipeline.getScissorState(), glRT->getViewport(), glRT->or
igin()); | 1716 this->flushScissor(pipeline.getScissorState(), glRT->getViewport(), glRT->or
igin()); |
| 1714 this->flushHWAAState(glRT, pipeline.isHWAntialiasState()); | 1717 this->flushHWAAState(glRT, pipeline.isHWAntialiasState(), !pipeline.getStenc
il().isDisabled()); |
| 1715 | 1718 |
| 1716 // This must come after textures are flushed because a texture may need | 1719 // This must come after textures are flushed because a texture may need |
| 1717 // to be msaa-resolved (which will modify bound FBO state). | 1720 // to be msaa-resolved (which will modify bound FBO state). |
| 1718 this->flushRenderTarget(glRT, nullptr); | 1721 this->flushRenderTarget(glRT, nullptr); |
| 1719 | 1722 |
| 1720 return true; | 1723 return true; |
| 1721 } | 1724 } |
| 1722 | 1725 |
| 1723 void GrGLGpu::setupGeometry(const GrPrimitiveProcessor& primProc, | 1726 void GrGLGpu::setupGeometry(const GrPrimitiveProcessor& primProc, |
| 1724 const GrNonInstancedVertices& vertices, | 1727 const GrNonInstancedVertices& vertices, |
| (...skipping 652 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2377 | 2380 |
| 2378 void GrGLGpu::performFlushWorkaround() { | 2381 void GrGLGpu::performFlushWorkaround() { |
| 2379 if (fPLSHasBeenUsed) { | 2382 if (fPLSHasBeenUsed) { |
| 2380 /* There is an ARM driver bug where if we use PLS, and then draw a frame
which does not | 2383 /* There is an ARM driver bug where if we use PLS, and then draw a frame
which does not |
| 2381 * use PLS, it leaves garbage all over the place. As a workaround, we us
e PLS in a | 2384 * use PLS, it leaves garbage all over the place. As a workaround, we us
e PLS in a |
| 2382 * trivial way every frame. And since we use it every frame, there's nev
er a point at which | 2385 * trivial way every frame. And since we use it every frame, there's nev
er a point at which |
| 2383 * it becomes safe to stop using this workaround once we start. | 2386 * it becomes safe to stop using this workaround once we start. |
| 2384 */ | 2387 */ |
| 2385 this->disableScissor(); | 2388 this->disableScissor(); |
| 2386 // using PLS in the presence of MSAA results in GL_INVALID_OPERATION | 2389 // using PLS in the presence of MSAA results in GL_INVALID_OPERATION |
| 2387 this->flushHWAAState(nullptr, false); | 2390 this->flushHWAAState(nullptr, false, false); |
| 2388 SkASSERT(!fHWPLSEnabled); | 2391 SkASSERT(!fHWPLSEnabled); |
| 2389 SkASSERT(fMSAAEnabled != kYes_TriState); | 2392 SkASSERT(fMSAAEnabled != kYes_TriState); |
| 2390 GL_CALL(Enable(GR_GL_SHADER_PIXEL_LOCAL_STORAGE)); | 2393 GL_CALL(Enable(GR_GL_SHADER_PIXEL_LOCAL_STORAGE)); |
| 2391 this->stampRectUsingProgram(fPLSSetupProgram.fProgram, | 2394 this->stampRectUsingProgram(fPLSSetupProgram.fProgram, |
| 2392 SkRect::MakeXYWH(-100.0f, -100.0f, 0.01f, 0.
01f), | 2395 SkRect::MakeXYWH(-100.0f, -100.0f, 0.01f, 0.
01f), |
| 2393 fPLSSetupProgram.fPosXformUniform, | 2396 fPLSSetupProgram.fPosXformUniform, |
| 2394 fPLSSetupProgram.fArrayBuffer); | 2397 fPLSSetupProgram.fArrayBuffer); |
| 2395 GL_CALL(Disable(GR_GL_SHADER_PIXEL_LOCAL_STORAGE)); | 2398 GL_CALL(Disable(GR_GL_SHADER_PIXEL_LOCAL_STORAGE)); |
| 2396 } | 2399 } |
| 2397 } | 2400 } |
| (...skipping 311 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2709 set_gl_stencil(this->glInterface(), | 2712 set_gl_stencil(this->glInterface(), |
| 2710 stencilSettings, | 2713 stencilSettings, |
| 2711 GR_GL_FRONT_AND_BACK, | 2714 GR_GL_FRONT_AND_BACK, |
| 2712 GrStencilSettings::kFront_Face); | 2715 GrStencilSettings::kFront_Face); |
| 2713 } | 2716 } |
| 2714 } | 2717 } |
| 2715 fHWStencilSettings = stencilSettings; | 2718 fHWStencilSettings = stencilSettings; |
| 2716 } | 2719 } |
| 2717 } | 2720 } |
| 2718 | 2721 |
| 2719 void GrGLGpu::flushHWAAState(GrRenderTarget* rt, bool useHWAA) { | 2722 void GrGLGpu::flushHWAAState(GrRenderTarget* rt, bool useHWAA, bool stencilEnabl
ed) { |
| 2720 SkASSERT(!useHWAA || rt->isStencilBufferMultisampled()); | 2723 SkASSERT(!useHWAA || rt->isStencilBufferMultisampled()); |
| 2721 | 2724 |
| 2722 if (this->glCaps().multisampleDisableSupport()) { | 2725 if (this->glCaps().multisampleDisableSupport()) { |
| 2723 if (useHWAA) { | 2726 if (useHWAA) { |
| 2724 if (kYes_TriState != fMSAAEnabled) { | 2727 if (kYes_TriState != fMSAAEnabled) { |
| 2725 GL_CALL(Enable(GR_GL_MULTISAMPLE)); | 2728 GL_CALL(Enable(GR_GL_MULTISAMPLE)); |
| 2726 fMSAAEnabled = kYes_TriState; | 2729 fMSAAEnabled = kYes_TriState; |
| 2727 } | 2730 } |
| 2728 } else { | 2731 } else { |
| 2729 if (kNo_TriState != fMSAAEnabled) { | 2732 if (kNo_TriState != fMSAAEnabled) { |
| 2730 GL_CALL(Disable(GR_GL_MULTISAMPLE)); | 2733 GL_CALL(Disable(GR_GL_MULTISAMPLE)); |
| 2731 fMSAAEnabled = kNo_TriState; | 2734 fMSAAEnabled = kNo_TriState; |
| 2732 } | 2735 } |
| 2733 } | 2736 } |
| 2734 } | 2737 } |
| 2738 |
| 2739 if (0 != this->caps()->maxRasterSamples()) { |
| 2740 if (useHWAA && rt->hasMixedSamples() && !stencilEnabled) { |
| 2741 // Since stencil is disabled and we want more samples than are in th
e color buffer, we |
| 2742 // need to tell the rasterizer explicitly how many to run. |
| 2743 if (kYes_TriState != fHWRasterMultisampleEnabled) { |
| 2744 GL_CALL(Enable(GR_GL_RASTER_MULTISAMPLE)); |
| 2745 fHWRasterMultisampleEnabled = kYes_TriState; |
| 2746 } |
| 2747 if (rt->numStencilSamples() != fHWNumRasterSamples) { |
| 2748 SkASSERT(rt->numStencilSamples() <= this->caps()->maxRasterSampl
es()); |
| 2749 GL_CALL(RasterSamples(rt->numStencilSamples(), GR_GL_TRUE)); |
| 2750 fHWNumRasterSamples = rt->numStencilSamples(); |
| 2751 } |
| 2752 } else { |
| 2753 if (kNo_TriState != fHWRasterMultisampleEnabled) { |
| 2754 GL_CALL(Disable(GR_GL_RASTER_MULTISAMPLE)); |
| 2755 fHWRasterMultisampleEnabled = kNo_TriState; |
| 2756 } |
| 2757 } |
| 2758 } else { |
| 2759 SkASSERT(!useHWAA || !rt->hasMixedSamples() || stencilEnabled); |
| 2760 } |
| 2735 } | 2761 } |
| 2736 | 2762 |
| 2737 void GrGLGpu::flushBlend(const GrXferProcessor::BlendInfo& blendInfo, const GrSw
izzle& swizzle) { | 2763 void GrGLGpu::flushBlend(const GrXferProcessor::BlendInfo& blendInfo, const GrSw
izzle& swizzle) { |
| 2738 // Any optimization to disable blending should have already been applied and | 2764 // Any optimization to disable blending should have already been applied and |
| 2739 // tweaked the equation to "add" or "subtract", and the coeffs to (1, 0). | 2765 // tweaked the equation to "add" or "subtract", and the coeffs to (1, 0). |
| 2740 | 2766 |
| 2741 GrBlendEquation equation = blendInfo.fEquation; | 2767 GrBlendEquation equation = blendInfo.fEquation; |
| 2742 GrBlendCoeff srcCoeff = blendInfo.fSrcBlend; | 2768 GrBlendCoeff srcCoeff = blendInfo.fSrcBlend; |
| 2743 GrBlendCoeff dstCoeff = blendInfo.fDstBlend; | 2769 GrBlendCoeff dstCoeff = blendInfo.fDstBlend; |
| 2744 bool blendOff = (kAdd_GrBlendEquation == equation || kSubtract_GrBlendEquati
on == equation) && | 2770 bool blendOff = (kAdd_GrBlendEquation == equation || kSubtract_GrBlendEquati
on == equation) && |
| (...skipping 722 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3467 attribs->disableUnusedArrays(this, 0x1); | 3493 attribs->disableUnusedArrays(this, 0x1); |
| 3468 | 3494 |
| 3469 GL_CALL(Uniform4fv(fWireRectProgram.fRectUniform, 1, edges)); | 3495 GL_CALL(Uniform4fv(fWireRectProgram.fRectUniform, 1, edges)); |
| 3470 GL_CALL(Uniform4fv(fWireRectProgram.fColorUniform, 1, channels)); | 3496 GL_CALL(Uniform4fv(fWireRectProgram.fColorUniform, 1, channels)); |
| 3471 | 3497 |
| 3472 GrXferProcessor::BlendInfo blendInfo; | 3498 GrXferProcessor::BlendInfo blendInfo; |
| 3473 blendInfo.reset(); | 3499 blendInfo.reset(); |
| 3474 this->flushBlend(blendInfo, GrSwizzle::RGBA()); | 3500 this->flushBlend(blendInfo, GrSwizzle::RGBA()); |
| 3475 this->flushColorWrite(true); | 3501 this->flushColorWrite(true); |
| 3476 this->flushDrawFace(GrPipelineBuilder::kBoth_DrawFace); | 3502 this->flushDrawFace(GrPipelineBuilder::kBoth_DrawFace); |
| 3477 this->flushHWAAState(glRT, false); | 3503 this->flushHWAAState(glRT, false, false); |
| 3478 this->disableScissor(); | 3504 this->disableScissor(); |
| 3479 GrStencilSettings stencil; | 3505 GrStencilSettings stencil; |
| 3480 stencil.setDisabled(); | 3506 stencil.setDisabled(); |
| 3481 this->flushStencil(stencil); | 3507 this->flushStencil(stencil); |
| 3482 | 3508 |
| 3483 GL_CALL(DrawArrays(GR_GL_LINE_LOOP, 0, 4)); | 3509 GL_CALL(DrawArrays(GR_GL_LINE_LOOP, 0, 4)); |
| 3484 } | 3510 } |
| 3485 | 3511 |
| 3486 | 3512 |
| 3487 void GrGLGpu::copySurfaceAsDraw(GrSurface* dst, | 3513 void GrGLGpu::copySurfaceAsDraw(GrSurface* dst, |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3545 GL_CALL(Uniform4f(fCopyPrograms[progIdx].fPosXformUniform, dx1 - dx0, dy1 -
dy0, dx0, dy0)); | 3571 GL_CALL(Uniform4f(fCopyPrograms[progIdx].fPosXformUniform, dx1 - dx0, dy1 -
dy0, dx0, dy0)); |
| 3546 GL_CALL(Uniform4f(fCopyPrograms[progIdx].fTexCoordXformUniform, | 3572 GL_CALL(Uniform4f(fCopyPrograms[progIdx].fTexCoordXformUniform, |
| 3547 sx1 - sx0, sy1 - sy0, sx0, sy0)); | 3573 sx1 - sx0, sy1 - sy0, sx0, sy0)); |
| 3548 GL_CALL(Uniform1i(fCopyPrograms[progIdx].fTextureUniform, 0)); | 3574 GL_CALL(Uniform1i(fCopyPrograms[progIdx].fTextureUniform, 0)); |
| 3549 | 3575 |
| 3550 GrXferProcessor::BlendInfo blendInfo; | 3576 GrXferProcessor::BlendInfo blendInfo; |
| 3551 blendInfo.reset(); | 3577 blendInfo.reset(); |
| 3552 this->flushBlend(blendInfo, GrSwizzle::RGBA()); | 3578 this->flushBlend(blendInfo, GrSwizzle::RGBA()); |
| 3553 this->flushColorWrite(true); | 3579 this->flushColorWrite(true); |
| 3554 this->flushDrawFace(GrPipelineBuilder::kBoth_DrawFace); | 3580 this->flushDrawFace(GrPipelineBuilder::kBoth_DrawFace); |
| 3555 this->flushHWAAState(dstRT, false); | 3581 this->flushHWAAState(dstRT, false, false); |
| 3556 this->disableScissor(); | 3582 this->disableScissor(); |
| 3557 GrStencilSettings stencil; | 3583 GrStencilSettings stencil; |
| 3558 stencil.setDisabled(); | 3584 stencil.setDisabled(); |
| 3559 this->flushStencil(stencil); | 3585 this->flushStencil(stencil); |
| 3560 | 3586 |
| 3561 GL_CALL(DrawArrays(GR_GL_TRIANGLE_STRIP, 0, 4)); | 3587 GL_CALL(DrawArrays(GR_GL_TRIANGLE_STRIP, 0, 4)); |
| 3562 } | 3588 } |
| 3563 | 3589 |
| 3564 void GrGLGpu::copySurfaceAsCopyTexSubImage(GrSurface* dst, | 3590 void GrGLGpu::copySurfaceAsCopyTexSubImage(GrSurface* dst, |
| 3565 GrSurface* src, | 3591 GrSurface* src, |
| (...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3824 if (GR_GL_TEXTURE_EXTERNAL == glTexture->target() || | 3850 if (GR_GL_TEXTURE_EXTERNAL == glTexture->target() || |
| 3825 GR_GL_TEXTURE_RECTANGLE == glTexture->target()) { | 3851 GR_GL_TEXTURE_RECTANGLE == glTexture->target()) { |
| 3826 copyParams->fFilter = GrTextureParams::kNone_FilterMode; | 3852 copyParams->fFilter = GrTextureParams::kNone_FilterMode; |
| 3827 copyParams->fWidth = texture->width(); | 3853 copyParams->fWidth = texture->width(); |
| 3828 copyParams->fHeight = texture->height(); | 3854 copyParams->fHeight = texture->height(); |
| 3829 return true; | 3855 return true; |
| 3830 } | 3856 } |
| 3831 } | 3857 } |
| 3832 return false; | 3858 return false; |
| 3833 } | 3859 } |
| OLD | NEW |