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 GrGLTexture::IDDesc idDesc; | 436 GrGLTexture::IDDesc idDesc; |
437 GrSurfaceDesc surfDesc; | 437 GrSurfaceDesc surfDesc; |
438 | 438 |
439 #ifdef SK_IGNORE_GL_TEXTURE_TARGET | 439 #ifdef SK_IGNORE_GL_TEXTURE_TARGET |
440 idDesc.fInfo.fID = static_cast<GrGLuint>(desc.fTextureHandle); | 440 idDesc.fInfo.fID = static_cast<GrGLuint>(desc.fTextureHandle); |
441 // We only support GL_TEXTURE_2D at the moment. | 441 // We only support GL_TEXTURE_2D at the moment. |
442 idDesc.fInfo.fTarget = GR_GL_TEXTURE_2D; | 442 idDesc.fInfo.fTarget = GR_GL_TEXTURE_2D; |
443 #else | 443 #else |
444 idDesc.fInfo = *info; | 444 idDesc.fInfo = *info; |
445 #endif | 445 #endif |
446 | |
446 if (GR_GL_TEXTURE_EXTERNAL == idDesc.fInfo.fTarget) { | 447 if (GR_GL_TEXTURE_EXTERNAL == idDesc.fInfo.fTarget) { |
447 if (renderTarget) { | 448 if (renderTarget) { |
448 // This combination is not supported. | 449 // This combination is not supported. |
449 return nullptr; | 450 return nullptr; |
450 } | 451 } |
451 if (!this->glCaps().externalTextureSupport()) { | 452 if (!this->glCaps().externalTextureSupport()) { |
452 return nullptr; | 453 return nullptr; |
453 } | 454 } |
455 } else if (GR_GL_TEXTURE_RECTANGLE == idDesc.fInfo.fTarget) { | |
456 if (!this->glCaps().rectangleTextureSupport()) { | |
457 return nullptr; | |
458 } | |
459 } else if (GR_GL_TEXTURE_2D != idDesc.fInfo.fTarget) { | |
460 return nullptr; | |
454 } | 461 } |
455 // Sample count is interpretted to mean the number of samples that Gr code s hould allocate | 462 |
463 // Sample count is interpreted to mean the number of samples that Gr code sh ould allocate | |
456 // for a render buffer that resolves to the texture. We don't support MSAA t extures. | 464 // for a render buffer that resolves to the texture. We don't support MSAA t extures. |
457 if (desc.fSampleCnt && !renderTarget) { | 465 if (desc.fSampleCnt && !renderTarget) { |
458 return nullptr; | 466 return nullptr; |
459 } | 467 } |
460 | 468 |
461 switch (ownership) { | 469 switch (ownership) { |
462 case kAdopt_GrWrapOwnership: | 470 case kAdopt_GrWrapOwnership: |
463 idDesc.fLifeCycle = GrGpuResource::kAdopted_LifeCycle; | 471 idDesc.fLifeCycle = GrGpuResource::kAdopted_LifeCycle; |
464 break; | 472 break; |
465 case kBorrow_GrWrapOwnership: | 473 case kBorrow_GrWrapOwnership: |
466 idDesc.fLifeCycle = GrGpuResource::kBorrowed_LifeCycle; | 474 idDesc.fLifeCycle = GrGpuResource::kBorrowed_LifeCycle; |
467 break; | 475 break; |
468 } | 476 } |
469 | 477 |
470 surfDesc.fFlags = (GrSurfaceFlags) desc.fFlags; | 478 surfDesc.fFlags = (GrSurfaceFlags) desc.fFlags; |
471 surfDesc.fWidth = desc.fWidth; | 479 surfDesc.fWidth = desc.fWidth; |
472 surfDesc.fHeight = desc.fHeight; | 480 surfDesc.fHeight = desc.fHeight; |
473 surfDesc.fConfig = desc.fConfig; | 481 surfDesc.fConfig = desc.fConfig; |
474 surfDesc.fSampleCnt = SkTMin(desc.fSampleCnt, this->caps()->maxSampleCount() ); | 482 surfDesc.fSampleCnt = SkTMin(desc.fSampleCnt, this->caps()->maxSampleCount() ); |
475 // FIXME: this should be calling resolve_origin(), but Chrome code is curre ntly | 483 // FIXME: this should be calling resolve_origin(), but Chrome code is curre ntly |
476 // assuming the old behaviour, which is that backend textures are always | 484 // assuming the old behaviour, which is that backend textures are always |
477 // BottomLeft, even for non-RT's. Once Chrome is fixed, change this to: | 485 // BottomLeft, even for non-RT's. Once Chrome is fixed, change this to: |
478 // glTexDesc.fOrigin = resolve_origin(desc.fOrigin, renderTarget); | 486 // glTexDesc.fOrigin = resolve_origin(desc.fOrigin, renderTarget); |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
535 if (kIndex_8_GrPixelConfig == srcConfig || GrPixelConfigIsCompressed(dstSurf ace->config())) { | 543 if (kIndex_8_GrPixelConfig == srcConfig || GrPixelConfigIsCompressed(dstSurf ace->config())) { |
536 return false; | 544 return false; |
537 } | 545 } |
538 | 546 |
539 // This subclass only allows writes to textures. If the dst is not a texture we have to draw | 547 // This subclass only allows writes to textures. If the dst is not a texture we have to draw |
540 // into it. We could use glDrawPixels on GLs that have it, but we don't toda y. | 548 // into it. We could use glDrawPixels on GLs that have it, but we don't toda y. |
541 if (!dstSurface->asTexture()) { | 549 if (!dstSurface->asTexture()) { |
542 ElevateDrawPreference(drawPreference, kRequireDraw_DrawPreference); | 550 ElevateDrawPreference(drawPreference, kRequireDraw_DrawPreference); |
543 } else { | 551 } else { |
544 GrGLTexture* texture = static_cast<GrGLTexture*>(dstSurface->asTexture() ); | 552 GrGLTexture* texture = static_cast<GrGLTexture*>(dstSurface->asTexture() ); |
545 if (GR_GL_TEXTURE_2D != texture->target()) { | 553 if (GR_GL_TEXTURE_EXTERNAL == texture->target()) { |
546 // We don't currently support writing pixels to non-TEXTURE_2D text ures. | 554 // We don't currently support writing pixels to EXTERNAL textures. |
547 return false; | 555 return false; |
548 } | 556 } |
549 } | 557 } |
550 | 558 |
551 if (GrPixelConfigIsSRGB(dstSurface->config()) != GrPixelConfigIsSRGB(srcConf ig)) { | 559 if (GrPixelConfigIsSRGB(dstSurface->config()) != GrPixelConfigIsSRGB(srcConf ig)) { |
552 ElevateDrawPreference(drawPreference, kRequireDraw_DrawPreference); | 560 ElevateDrawPreference(drawPreference, kRequireDraw_DrawPreference); |
553 } | 561 } |
554 | 562 |
555 tempDrawInfo->fSwapRAndB = false; | 563 tempDrawInfo->fSwapRAndB = false; |
556 | 564 |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
597 GrPixelConfig config) { | 605 GrPixelConfig config) { |
598 if (!glTex) { | 606 if (!glTex) { |
599 return false; | 607 return false; |
600 } | 608 } |
601 | 609 |
602 // OpenGL doesn't do sRGB <-> linear conversions when reading and writing pi xels. | 610 // OpenGL doesn't do sRGB <-> linear conversions when reading and writing pi xels. |
603 if (GrPixelConfigIsSRGB(surface->config()) != GrPixelConfigIsSRGB(config)) { | 611 if (GrPixelConfigIsSRGB(surface->config()) != GrPixelConfigIsSRGB(config)) { |
604 return false; | 612 return false; |
605 } | 613 } |
606 | 614 |
607 // Write or transfer of pixels is only implemented for TEXTURE_2D textures | 615 // Write or transfer of pixels is no implemented for TEXTURE_EXTERNAL textur es |
jvanverth1
2016/01/14 16:47:21
not implemented
bsalomon
2016/01/14 17:11:50
Done.
| |
608 if (GR_GL_TEXTURE_2D != glTex->target()) { | 616 if (GR_GL_TEXTURE_EXTERNAL == glTex->target()) { |
609 return false; | 617 return false; |
610 } | 618 } |
611 | 619 |
612 return true; | 620 return true; |
613 } | 621 } |
614 | 622 |
615 bool GrGLGpu::onWritePixels(GrSurface* surface, | 623 bool GrGLGpu::onWritePixels(GrSurface* surface, |
616 int left, int top, int width, int height, | 624 int left, int top, int width, int height, |
617 GrPixelConfig config, const void* buffer, | 625 GrPixelConfig config, const void* buffer, |
618 size_t rowBytes) { | 626 size_t rowBytes) { |
(...skipping 2276 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2895 } | 2903 } |
2896 | 2904 |
2897 return false; | 2905 return false; |
2898 } | 2906 } |
2899 | 2907 |
2900 void GrGLGpu::createCopyPrograms() { | 2908 void GrGLGpu::createCopyPrograms() { |
2901 for (size_t i = 0; i < SK_ARRAY_COUNT(fCopyPrograms); ++i) { | 2909 for (size_t i = 0; i < SK_ARRAY_COUNT(fCopyPrograms); ++i) { |
2902 fCopyPrograms[i].fProgram = 0; | 2910 fCopyPrograms[i].fProgram = 0; |
2903 } | 2911 } |
2904 const char* version = this->glCaps().glslCaps()->versionDeclString(); | 2912 const char* version = this->glCaps().glslCaps()->versionDeclString(); |
2905 static const GrSLType kSamplerTypes[2] = { kSampler2D_GrSLType, kSamplerExte rnal_GrSLType }; | 2913 static const GrSLType kSamplerTypes[3] = { kSampler2D_GrSLType, kSamplerExte rnal_GrSLType, |
2906 SkASSERT(2 == SK_ARRAY_COUNT(fCopyPrograms)); | 2914 kSampler2DRect_GrSLType }; |
2907 int programCount = this->glCaps().externalTextureSupport() ? 2 : 1; | 2915 SkASSERT(3 == SK_ARRAY_COUNT(fCopyPrograms)); |
2908 for (int i = 0; i < programCount; ++i) { | 2916 for (int i = 0; i < 3; ++i) { |
2917 if (kSamplerExternal_GrSLType == kSamplerTypes[i] && | |
2918 !this->glCaps().externalTextureSupport()) { | |
2919 continue; | |
2920 } | |
2921 if (kSampler2DRect_GrSLType == kSamplerTypes[i] && | |
2922 !this->glCaps().rectangleTextureSupport()) { | |
2923 continue; | |
2924 } | |
2909 GrGLSLShaderVar aVertex("a_vertex", kVec2f_GrSLType, GrShaderVar::kAttri bute_TypeModifier); | 2925 GrGLSLShaderVar aVertex("a_vertex", kVec2f_GrSLType, GrShaderVar::kAttri bute_TypeModifier); |
2910 GrGLSLShaderVar uTexCoordXform("u_texCoordXform", kVec4f_GrSLType, | 2926 GrGLSLShaderVar uTexCoordXform("u_texCoordXform", kVec4f_GrSLType, |
2911 GrShaderVar::kUniform_TypeModifier); | 2927 GrShaderVar::kUniform_TypeModifier); |
2912 GrGLSLShaderVar uPosXform("u_posXform", kVec4f_GrSLType, | 2928 GrGLSLShaderVar uPosXform("u_posXform", kVec4f_GrSLType, |
2913 GrShaderVar::kUniform_TypeModifier); | 2929 GrShaderVar::kUniform_TypeModifier); |
2914 GrGLSLShaderVar uTexture("u_texture", kSamplerTypes[i], | 2930 GrGLSLShaderVar uTexture("u_texture", kSamplerTypes[i], |
2915 GrShaderVar::kUniform_TypeModifier); | 2931 GrShaderVar::kUniform_TypeModifier); |
2916 GrGLSLShaderVar vTexCoord("v_texCoord", kVec2f_GrSLType, | 2932 GrGLSLShaderVar vTexCoord("v_texCoord", kVec2f_GrSLType, |
2917 GrShaderVar::kVaryingOut_TypeModifier); | 2933 GrShaderVar::kVaryingOut_TypeModifier); |
2918 GrGLSLShaderVar oFragColor("o_FragColor", kVec4f_GrSLType, | 2934 GrGLSLShaderVar oFragColor("o_FragColor", kVec4f_GrSLType, |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2957 fsOutName = oFragColor.c_str(); | 2973 fsOutName = oFragColor.c_str(); |
2958 } else { | 2974 } else { |
2959 fsOutName = "gl_FragColor"; | 2975 fsOutName = "gl_FragColor"; |
2960 } | 2976 } |
2961 fshaderTxt.appendf( | 2977 fshaderTxt.appendf( |
2962 "// Copy Program FS\n" | 2978 "// Copy Program FS\n" |
2963 "void main() {" | 2979 "void main() {" |
2964 " %s = %s(u_texture, v_texCoord);" | 2980 " %s = %s(u_texture, v_texCoord);" |
2965 "}", | 2981 "}", |
2966 fsOutName, | 2982 fsOutName, |
2967 GrGLSLTexture2DFunctionName(kVec2f_GrSLType, this->glslGeneration()) | 2983 GrGLSLTexture2DFunctionName(kVec2f_GrSLType, kSamplerTypes[i], this- >glslGeneration()) |
2968 ); | 2984 ); |
2969 | 2985 |
2970 GL_CALL_RET(fCopyPrograms[i].fProgram, CreateProgram()); | 2986 GL_CALL_RET(fCopyPrograms[i].fProgram, CreateProgram()); |
2971 const char* str; | 2987 const char* str; |
2972 GrGLint length; | 2988 GrGLint length; |
2973 | 2989 |
2974 str = vshaderTxt.c_str(); | 2990 str = vshaderTxt.c_str(); |
2975 length = SkToInt(vshaderTxt.size()); | 2991 length = SkToInt(vshaderTxt.size()); |
2976 GrGLuint vshader = GrGLCompileAndAttachShader(*fGLContext, fCopyPrograms [i].fProgram, | 2992 GrGLuint vshader = GrGLCompileAndAttachShader(*fGLContext, fCopyPrograms [i].fProgram, |
2977 GR_GL_VERTEX_SHADER, &str, &length, 1, | 2993 GR_GL_VERTEX_SHADER, &str, &length, 1, |
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3202 int dh = dst->height(); | 3218 int dh = dst->height(); |
3203 GrGLfloat dx0 = 2.f * dstPoint.fX / dw - 1.f; | 3219 GrGLfloat dx0 = 2.f * dstPoint.fX / dw - 1.f; |
3204 GrGLfloat dx1 = 2.f * (dstPoint.fX + w) / dw - 1.f; | 3220 GrGLfloat dx1 = 2.f * (dstPoint.fX + w) / dw - 1.f; |
3205 GrGLfloat dy0 = 2.f * dstPoint.fY / dh - 1.f; | 3221 GrGLfloat dy0 = 2.f * dstPoint.fY / dh - 1.f; |
3206 GrGLfloat dy1 = 2.f * (dstPoint.fY + h) / dh - 1.f; | 3222 GrGLfloat dy1 = 2.f * (dstPoint.fY + h) / dh - 1.f; |
3207 if (kBottomLeft_GrSurfaceOrigin == dst->origin()) { | 3223 if (kBottomLeft_GrSurfaceOrigin == dst->origin()) { |
3208 dy0 = -dy0; | 3224 dy0 = -dy0; |
3209 dy1 = -dy1; | 3225 dy1 = -dy1; |
3210 } | 3226 } |
3211 | 3227 |
3212 // src rect edges in normalized texture space (0 to 1) | 3228 GrGLfloat sx0 = (GrGLfloat)srcRect.fLeft; |
3213 int sw = src->width(); | 3229 GrGLfloat sx1 = (GrGLfloat)(srcRect.fLeft + w); |
3230 GrGLfloat sy0 = (GrGLfloat)srcRect.fTop; | |
3231 GrGLfloat sy1 = (GrGLfloat)(srcRect.fTop + h); | |
3214 int sh = src->height(); | 3232 int sh = src->height(); |
3215 GrGLfloat sx0 = (GrGLfloat)srcRect.fLeft / sw; | |
3216 GrGLfloat sx1 = (GrGLfloat)(srcRect.fLeft + w) / sw; | |
3217 GrGLfloat sy0 = (GrGLfloat)srcRect.fTop / sh; | |
3218 GrGLfloat sy1 = (GrGLfloat)(srcRect.fTop + h) / sh; | |
3219 if (kBottomLeft_GrSurfaceOrigin == src->origin()) { | 3233 if (kBottomLeft_GrSurfaceOrigin == src->origin()) { |
3220 sy0 = 1.f - sy0; | 3234 sy0 = sh - sy0; |
3221 sy1 = 1.f - sy1; | 3235 sy1 = sh - sy1; |
3236 } | |
3237 // src rect edges in normalized texture space (0 to 1) unless we're using a RECTANGLE texture. | |
3238 GrGLenum srcTarget = srcTex->target(); | |
3239 if (GR_GL_TEXTURE_RECTANGLE != srcTarget) { | |
3240 int sw = src->width(); | |
3241 sx0 /= sw; | |
3242 sx1 /= sw; | |
3243 sy0 /= sh; | |
3244 sy1 /= sh; | |
3222 } | 3245 } |
3223 | 3246 |
3224 GL_CALL(Uniform4f(fCopyPrograms[progIdx].fPosXformUniform, dx1 - dx0, dy1 - dy0, dx0, dy0)); | 3247 GL_CALL(Uniform4f(fCopyPrograms[progIdx].fPosXformUniform, dx1 - dx0, dy1 - dy0, dx0, dy0)); |
3225 GL_CALL(Uniform4f(fCopyPrograms[progIdx].fTexCoordXformUniform, | 3248 GL_CALL(Uniform4f(fCopyPrograms[progIdx].fTexCoordXformUniform, |
3226 sx1 - sx0, sy1 - sy0, sx0, sy0)); | 3249 sx1 - sx0, sy1 - sy0, sx0, sy0)); |
3227 GL_CALL(Uniform1i(fCopyPrograms[progIdx].fTextureUniform, 0)); | 3250 GL_CALL(Uniform1i(fCopyPrograms[progIdx].fTextureUniform, 0)); |
3228 | 3251 |
3229 GrXferProcessor::BlendInfo blendInfo; | 3252 GrXferProcessor::BlendInfo blendInfo; |
3230 blendInfo.reset(); | 3253 blendInfo.reset(); |
3231 this->flushBlend(blendInfo, GrSwizzle::RGBA()); | 3254 this->flushBlend(blendInfo, GrSwizzle::RGBA()); |
(...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3487 this->setVertexArrayID(gpu, 0); | 3510 this->setVertexArrayID(gpu, 0); |
3488 } | 3511 } |
3489 int attrCount = gpu->glCaps().maxVertexAttributes(); | 3512 int attrCount = gpu->glCaps().maxVertexAttributes(); |
3490 if (fDefaultVertexArrayAttribState.count() != attrCount) { | 3513 if (fDefaultVertexArrayAttribState.count() != attrCount) { |
3491 fDefaultVertexArrayAttribState.resize(attrCount); | 3514 fDefaultVertexArrayAttribState.resize(attrCount); |
3492 } | 3515 } |
3493 attribState = &fDefaultVertexArrayAttribState; | 3516 attribState = &fDefaultVertexArrayAttribState; |
3494 } | 3517 } |
3495 return attribState; | 3518 return attribState; |
3496 } | 3519 } |
OLD | NEW |