| 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 #include "GrGLGpu.h" |     8 #include "GrGLGpu.h" | 
|     9 #include "GrGLBuffer.h" |     9 #include "GrGLBuffer.h" | 
|    10 #include "GrGLGLSL.h" |    10 #include "GrGLGLSL.h" | 
| (...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|   290 void GrGLGpu::createPLSSetupProgram() { |   290 void GrGLGpu::createPLSSetupProgram() { | 
|   291     const GrGLSLCaps* glslCaps = this->glCaps().glslCaps(); |   291     const GrGLSLCaps* glslCaps = this->glCaps().glslCaps(); | 
|   292     const char* version = glslCaps->versionDeclString(); |   292     const char* version = glslCaps->versionDeclString(); | 
|   293  |   293  | 
|   294     GrGLSLShaderVar aVertex("a_vertex", kVec2f_GrSLType, GrShaderVar::kAttribute
      _TypeModifier); |   294     GrGLSLShaderVar aVertex("a_vertex", kVec2f_GrSLType, GrShaderVar::kAttribute
      _TypeModifier); | 
|   295     GrGLSLShaderVar uTexCoordXform("u_texCoordXform", kVec4f_GrSLType, |   295     GrGLSLShaderVar uTexCoordXform("u_texCoordXform", kVec4f_GrSLType, | 
|   296                                    GrShaderVar::kUniform_TypeModifier); |   296                                    GrShaderVar::kUniform_TypeModifier); | 
|   297     GrGLSLShaderVar uPosXform("u_posXform", kVec4f_GrSLType, GrShaderVar::kUnifo
      rm_TypeModifier); |   297     GrGLSLShaderVar uPosXform("u_posXform", kVec4f_GrSLType, GrShaderVar::kUnifo
      rm_TypeModifier); | 
|   298     GrGLSLShaderVar uTexture("u_texture", kSampler2D_GrSLType, GrShaderVar::kUni
      form_TypeModifier); |   298     GrGLSLShaderVar uTexture("u_texture", kSampler2D_GrSLType, GrShaderVar::kUni
      form_TypeModifier); | 
|   299     GrGLSLShaderVar vTexCoord("v_texCoord", kVec2f_GrSLType, GrShaderVar::kVaryi
      ngOut_TypeModifier); |   299     GrGLSLShaderVar vTexCoord("v_texCoord", kVec2f_GrSLType, GrShaderVar::kVaryi
      ngOut_TypeModifier); | 
|   300      |   300  | 
|   301     SkString vshaderTxt(version); |   301     SkString vshaderTxt(version); | 
|   302     if (glslCaps->noperspectiveInterpolationSupport()) { |   302     if (glslCaps->noperspectiveInterpolationSupport()) { | 
|   303         if (const char* extension = glslCaps->noperspectiveInterpolationExtensio
      nString()) { |   303         if (const char* extension = glslCaps->noperspectiveInterpolationExtensio
      nString()) { | 
|   304             vshaderTxt.appendf("#extension %s : require\n", extension); |   304             vshaderTxt.appendf("#extension %s : require\n", extension); | 
|   305         } |   305         } | 
|   306         vTexCoord.addModifier("noperspective"); |   306         vTexCoord.addModifier("noperspective"); | 
|   307     } |   307     } | 
|   308     aVertex.appendDecl(glslCaps, &vshaderTxt); |   308     aVertex.appendDecl(glslCaps, &vshaderTxt); | 
|   309     vshaderTxt.append(";"); |   309     vshaderTxt.append(";"); | 
|   310     uTexCoordXform.appendDecl(glslCaps, &vshaderTxt); |   310     uTexCoordXform.appendDecl(glslCaps, &vshaderTxt); | 
|   311     vshaderTxt.append(";"); |   311     vshaderTxt.append(";"); | 
|   312     uPosXform.appendDecl(glslCaps, &vshaderTxt); |   312     uPosXform.appendDecl(glslCaps, &vshaderTxt); | 
|   313     vshaderTxt.append(";"); |   313     vshaderTxt.append(";"); | 
|   314     vTexCoord.appendDecl(glslCaps, &vshaderTxt); |   314     vTexCoord.appendDecl(glslCaps, &vshaderTxt); | 
|   315     vshaderTxt.append(";"); |   315     vshaderTxt.append(";"); | 
|   316      |   316  | 
|   317     vshaderTxt.append( |   317     vshaderTxt.append( | 
|   318         "// PLS Setup Program VS\n" |   318         "// PLS Setup Program VS\n" | 
|   319         "void main() {" |   319         "void main() {" | 
|   320         "  gl_Position.xy = a_vertex * u_posXform.xy + u_posXform.zw;" |   320         "  gl_Position.xy = a_vertex * u_posXform.xy + u_posXform.zw;" | 
|   321         "  gl_Position.zw = vec2(0, 1);" |   321         "  gl_Position.zw = vec2(0, 1);" | 
|   322         "}" |   322         "}" | 
|   323     ); |   323     ); | 
|   324  |   324  | 
|   325     SkString fshaderTxt(version); |   325     SkString fshaderTxt(version); | 
|   326     if (glslCaps->noperspectiveInterpolationSupport()) { |   326     if (glslCaps->noperspectiveInterpolationSupport()) { | 
| (...skipping 2287 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  2614             } else { |  2614             } else { | 
|  2615                 dst -= rowBytes; |  2615                 dst -= rowBytes; | 
|  2616             } |  2616             } | 
|  2617         } |  2617         } | 
|  2618     } |  2618     } | 
|  2619     return true; |  2619     return true; | 
|  2620 } |  2620 } | 
|  2621  |  2621  | 
|  2622 void GrGLGpu::finishDrawTarget() { |  2622 void GrGLGpu::finishDrawTarget() { | 
|  2623     if (fPLSHasBeenUsed) { |  2623     if (fPLSHasBeenUsed) { | 
|  2624         /* There is an ARM driver bug where if we use PLS, and then draw a frame
       which does not  |  2624         /* There is an ARM driver bug where if we use PLS, and then draw a frame
       which does not | 
|  2625          * use PLS, it leaves garbage all over the place. As a workaround, we us
      e PLS in a  |  2625          * use PLS, it leaves garbage all over the place. As a workaround, we us
      e PLS in a | 
|  2626          * trivial way every frame. And since we use it every frame, there's nev
      er a point at which |  2626          * trivial way every frame. And since we use it every frame, there's nev
      er a point at which | 
|  2627          * it becomes safe to stop using this workaround once we start. |  2627          * it becomes safe to stop using this workaround once we start. | 
|  2628          */ |  2628          */ | 
|  2629         this->disableScissor(); |  2629         this->disableScissor(); | 
|  2630         // using PLS in the presence of MSAA results in GL_INVALID_OPERATION |  2630         // using PLS in the presence of MSAA results in GL_INVALID_OPERATION | 
|  2631         this->flushHWAAState(nullptr, false, false); |  2631         this->flushHWAAState(nullptr, false, false); | 
|  2632         SkASSERT(!fHWPLSEnabled); |  2632         SkASSERT(!fHWPLSEnabled); | 
|  2633         SkASSERT(fMSAAEnabled != kYes_TriState); |  2633         SkASSERT(fMSAAEnabled != kYes_TriState); | 
|  2634         GL_CALL(Enable(GR_GL_SHADER_PIXEL_LOCAL_STORAGE)); |  2634         GL_CALL(Enable(GR_GL_SHADER_PIXEL_LOCAL_STORAGE)); | 
|  2635         this->stampRectUsingProgram(fPLSSetupProgram.fProgram,  |  2635         this->stampRectUsingProgram(fPLSSetupProgram.fProgram, | 
|  2636                                     SkRect::MakeXYWH(-100.0f, -100.0f, 0.01f, 0.
      01f),  |  2636                                     SkRect::MakeXYWH(-100.0f, -100.0f, 0.01f, 0.
      01f), | 
|  2637                                     fPLSSetupProgram.fPosXformUniform,  |  2637                                     fPLSSetupProgram.fPosXformUniform, | 
|  2638                                     fPLSSetupProgram.fArrayBuffer); |  2638                                     fPLSSetupProgram.fArrayBuffer); | 
|  2639         GL_CALL(Disable(GR_GL_SHADER_PIXEL_LOCAL_STORAGE)); |  2639         GL_CALL(Disable(GR_GL_SHADER_PIXEL_LOCAL_STORAGE)); | 
|  2640     } |  2640     } | 
|  2641 } |  2641 } | 
|  2642  |  2642  | 
|  2643 void GrGLGpu::flushRenderTarget(GrGLRenderTarget* target, const SkIRect* bounds,
       bool disableSRGB) { |  2643 void GrGLGpu::flushRenderTarget(GrGLRenderTarget* target, const SkIRect* bounds,
       bool disableSRGB) { | 
|  2644     SkASSERT(target); |  2644     SkASSERT(target); | 
|  2645  |  2645  | 
|  2646     uint32_t rtID = target->getUniqueID(); |  2646     uint32_t rtID = target->getUniqueID(); | 
|  2647     if (fHWBoundRenderTargetUniqueID != rtID) { |  2647     if (fHWBoundRenderTargetUniqueID != rtID) { | 
| (...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  2796         int set_a_break_pt_here = 9; |  2796         int set_a_break_pt_here = 9; | 
|  2797         aglSwapBuffers(aglGetCurrentContext()); |  2797         aglSwapBuffers(aglGetCurrentContext()); | 
|  2798     #elif defined(SK_BUILD_FOR_WIN32) |  2798     #elif defined(SK_BUILD_FOR_WIN32) | 
|  2799         SwapBuf(); |  2799         SwapBuf(); | 
|  2800         int set_a_break_pt_here = 9; |  2800         int set_a_break_pt_here = 9; | 
|  2801         SwapBuf(); |  2801         SwapBuf(); | 
|  2802     #endif |  2802     #endif | 
|  2803 #endif |  2803 #endif | 
|  2804 } |  2804 } | 
|  2805  |  2805  | 
|  2806 void GrGLGpu::stampRectUsingProgram(GrGLuint program, const SkRect& bounds, GrGL
      int posXformUniform,  |  2806 void GrGLGpu::stampRectUsingProgram(GrGLuint program, const SkRect& bounds, GrGL
      int posXformUniform, | 
|  2807                                     GrGLuint arrayBuffer) { |  2807                                     GrGLuint arrayBuffer) { | 
|  2808     GL_CALL(UseProgram(program)); |  2808     GL_CALL(UseProgram(program)); | 
|  2809     this->fHWGeometryState.setVertexArrayID(this, 0); |  2809     this->fHWGeometryState.setVertexArrayID(this, 0); | 
|  2810  |  2810  | 
|  2811     GrGLAttribArrayState* attribs = |  2811     GrGLAttribArrayState* attribs = | 
|  2812             this->fHWGeometryState.bindArrayAndBufferToDraw(this, arrayBuffer); |  2812             this->fHWGeometryState.bindArrayAndBufferToDraw(this, arrayBuffer); | 
|  2813     attribs->set(this, 0, arrayBuffer, kVec2f_GrVertexAttribType, 2 * sizeof(GrG
      Lfloat), 0); |  2813     attribs->set(this, 0, arrayBuffer, kVec2f_GrVertexAttribType, 2 * sizeof(GrG
      Lfloat), 0); | 
|  2814     attribs->disableUnusedArrays(this, 0x1); |  2814     attribs->disableUnusedArrays(this, 0x1); | 
|  2815  |  2815  | 
|  2816     GL_CALL(Uniform4f(posXformUniform, bounds.width(), bounds.height(), bounds.l
      eft(),  |  2816     GL_CALL(Uniform4f(posXformUniform, bounds.width(), bounds.height(), bounds.l
      eft(), | 
|  2817                       bounds.top())); |  2817                       bounds.top())); | 
|  2818  |  2818  | 
|  2819     GrXferProcessor::BlendInfo blendInfo; |  2819     GrXferProcessor::BlendInfo blendInfo; | 
|  2820     blendInfo.reset(); |  2820     blendInfo.reset(); | 
|  2821     this->flushBlend(blendInfo, GrSwizzle()); |  2821     this->flushBlend(blendInfo, GrSwizzle()); | 
|  2822     this->flushColorWrite(true); |  2822     this->flushColorWrite(true); | 
|  2823     this->flushDrawFace(GrPipelineBuilder::kBoth_DrawFace); |  2823     this->flushDrawFace(GrPipelineBuilder::kBoth_DrawFace); | 
|  2824     if (!fHWStencilSettings.isDisabled()) { |  2824     if (!fHWStencilSettings.isDisabled()) { | 
|  2825         GL_CALL(Disable(GR_GL_STENCIL_TEST)); |  2825         GL_CALL(Disable(GR_GL_STENCIL_TEST)); | 
|  2826     } |  2826     } | 
|  2827     GL_CALL(DrawArrays(GR_GL_TRIANGLE_STRIP, 0, 4)); |  2827     GL_CALL(DrawArrays(GR_GL_TRIANGLE_STRIP, 0, 4)); | 
|  2828     GL_CALL(UseProgram(fHWProgramID)); |  2828     GL_CALL(UseProgram(fHWProgramID)); | 
|  2829     if (!fHWStencilSettings.isDisabled()) { |  2829     if (!fHWStencilSettings.isDisabled()) { | 
|  2830         GL_CALL(Enable(GR_GL_STENCIL_TEST)); |  2830         GL_CALL(Enable(GR_GL_STENCIL_TEST)); | 
|  2831     } |  2831     } | 
|  2832 } |  2832 } | 
|  2833  |  2833  | 
|  2834 void GrGLGpu::setupPixelLocalStorage(const GrPipeline& pipeline, |  2834 void GrGLGpu::setupPixelLocalStorage(const GrPipeline& pipeline, | 
|  2835                                      const GrPrimitiveProcessor& primProc) { |  2835                                      const GrPrimitiveProcessor& primProc) { | 
|  2836     fPLSHasBeenUsed = true; |  2836     fPLSHasBeenUsed = true; | 
|  2837     const SkRect& bounds =  |  2837     const SkRect& bounds = | 
|  2838             static_cast<const GrPLSGeometryProcessor&>(primProc).getBounds(); |  2838             static_cast<const GrPLSGeometryProcessor&>(primProc).getBounds(); | 
|  2839     // setup pixel local storage -- this means capturing and storing the current
       framebuffer color |  2839     // setup pixel local storage -- this means capturing and storing the current
       framebuffer color | 
|  2840     // and initializing the winding counts to zero |  2840     // and initializing the winding counts to zero | 
|  2841     GrRenderTarget* rt = pipeline.getRenderTarget(); |  2841     GrRenderTarget* rt = pipeline.getRenderTarget(); | 
|  2842     SkScalar width = SkIntToScalar(rt->width()); |  2842     SkScalar width = SkIntToScalar(rt->width()); | 
|  2843     SkScalar height = SkIntToScalar(rt->height()); |  2843     SkScalar height = SkIntToScalar(rt->height()); | 
|  2844     // dst rect edges in NDC (-1 to 1) |  2844     // dst rect edges in NDC (-1 to 1) | 
|  2845     // having some issues with rounding, just expand the bounds by 1 and trust t
      he scissor to keep |  2845     // having some issues with rounding, just expand the bounds by 1 and trust t
      he scissor to keep | 
|  2846     // it contained properly |  2846     // it contained properly | 
|  2847     GrGLfloat dx0 = 2.0f * (bounds.left() - 1) / width - 1.0f; |  2847     GrGLfloat dx0 = 2.0f * (bounds.left() - 1) / width - 1.0f; | 
|  2848     GrGLfloat dx1 = 2.0f * (bounds.right() + 1) / width - 1.0f; |  2848     GrGLfloat dx1 = 2.0f * (bounds.right() + 1) / width - 1.0f; | 
|  2849     GrGLfloat dy0 = -2.0f * (bounds.top() - 1) / height + 1.0f; |  2849     GrGLfloat dy0 = -2.0f * (bounds.top() - 1) / height + 1.0f; | 
|  2850     GrGLfloat dy1 = -2.0f * (bounds.bottom() + 1) / height + 1.0f; |  2850     GrGLfloat dy1 = -2.0f * (bounds.bottom() + 1) / height + 1.0f; | 
|  2851     SkRect deviceBounds = SkRect::MakeXYWH(dx0, dy0, dx1 - dx0, dy1 - dy0); |  2851     SkRect deviceBounds = SkRect::MakeXYWH(dx0, dy0, dx1 - dx0, dy1 - dy0); | 
|  2852      |  2852  | 
|  2853     GL_CALL(Enable(GR_GL_FETCH_PER_SAMPLE_ARM)); |  2853     GL_CALL(Enable(GR_GL_FETCH_PER_SAMPLE_ARM)); | 
|  2854     this->stampRectUsingProgram(fPLSSetupProgram.fProgram, deviceBounds,  |  2854     this->stampRectUsingProgram(fPLSSetupProgram.fProgram, deviceBounds, | 
|  2855                                 fPLSSetupProgram.fPosXformUniform, fPLSSetupProg
      ram.fArrayBuffer); |  2855                                 fPLSSetupProgram.fPosXformUniform, fPLSSetupProg
      ram.fArrayBuffer); | 
|  2856 } |  2856 } | 
|  2857  |  2857  | 
|  2858 void GrGLGpu::onResolveRenderTarget(GrRenderTarget* target) { |  2858 void GrGLGpu::onResolveRenderTarget(GrRenderTarget* target) { | 
|  2859     GrGLRenderTarget* rt = static_cast<GrGLRenderTarget*>(target); |  2859     GrGLRenderTarget* rt = static_cast<GrGLRenderTarget*>(target); | 
|  2860     if (rt->needsResolve()) { |  2860     if (rt->needsResolve()) { | 
|  2861         // Some extensions automatically resolves the texture when it is read. |  2861         // Some extensions automatically resolves the texture when it is read. | 
|  2862         if (this->glCaps().usesMSAARenderBuffers()) { |  2862         if (this->glCaps().usesMSAARenderBuffers()) { | 
|  2863             SkASSERT(rt->textureFBOID() != rt->renderFBOID()); |  2863             SkASSERT(rt->textureFBOID() != rt->renderFBOID()); | 
|  2864             fStats.incRenderTargetBinds(); |  2864             fStats.incRenderTargetBinds(); | 
| (...skipping 1359 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  4224         if (GR_GL_TEXTURE_EXTERNAL == glTexture->target() || |  4224         if (GR_GL_TEXTURE_EXTERNAL == glTexture->target() || | 
|  4225             GR_GL_TEXTURE_RECTANGLE == glTexture->target()) { |  4225             GR_GL_TEXTURE_RECTANGLE == glTexture->target()) { | 
|  4226             copyParams->fFilter = GrTextureParams::kNone_FilterMode; |  4226             copyParams->fFilter = GrTextureParams::kNone_FilterMode; | 
|  4227             copyParams->fWidth = texture->width(); |  4227             copyParams->fWidth = texture->width(); | 
|  4228             copyParams->fHeight = texture->height(); |  4228             copyParams->fHeight = texture->height(); | 
|  4229             return true; |  4229             return true; | 
|  4230         } |  4230         } | 
|  4231     } |  4231     } | 
|  4232     return false; |  4232     return false; | 
|  4233 } |  4233 } | 
| OLD | NEW |