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