Chromium Code Reviews| 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 "GrContext.h" | |
| 9 #include "GrGLGLSL.h" | 10 #include "GrGLGLSL.h" |
| 10 #include "GrGLStencilAttachment.h" | 11 #include "GrGLStencilAttachment.h" |
| 11 #include "GrGLTextureRenderTarget.h" | 12 #include "GrGLTextureRenderTarget.h" |
| 12 #include "GrGpuResourcePriv.h" | 13 #include "GrGpuResourcePriv.h" |
| 13 #include "GrMesh.h" | 14 #include "GrMesh.h" |
| 14 #include "GrPipeline.h" | 15 #include "GrPipeline.h" |
| 15 #include "GrPLSGeometryProcessor.h" | 16 #include "GrPLSGeometryProcessor.h" |
| 16 #include "GrRenderTargetPriv.h" | 17 #include "GrRenderTargetPriv.h" |
| 18 #include "GrResourceProvider.h" | |
| 17 #include "GrSurfacePriv.h" | 19 #include "GrSurfacePriv.h" |
| 18 #include "GrTexturePriv.h" | 20 #include "GrTexturePriv.h" |
| 19 #include "GrTypes.h" | 21 #include "GrTypes.h" |
| 20 #include "builders/GrGLShaderStringBuilder.h" | 22 #include "builders/GrGLShaderStringBuilder.h" |
| 21 #include "glsl/GrGLSL.h" | 23 #include "glsl/GrGLSL.h" |
| 22 #include "glsl/GrGLSLCaps.h" | 24 #include "glsl/GrGLSLCaps.h" |
| 23 #include "glsl/GrGLSLPLSPathRendering.h" | 25 #include "glsl/GrGLSLPLSPathRendering.h" |
| 24 #include "SkMipMap.h" | 26 #include "SkMipMap.h" |
| 25 #include "SkPixmap.h" | 27 #include "SkPixmap.h" |
| 26 #include "SkStrokeRec.h" | 28 #include "SkStrokeRec.h" |
| (...skipping 560 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 587 } | 589 } |
| 588 | 590 |
| 589 // Sample count is interpreted to mean the number of samples that Gr code sh ould allocate | 591 // Sample count is interpreted to mean the number of samples that Gr code sh ould allocate |
| 590 // for a render buffer that resolves to the texture. We don't support MSAA t extures. | 592 // for a render buffer that resolves to the texture. We don't support MSAA t extures. |
| 591 if (desc.fSampleCnt && !renderTarget) { | 593 if (desc.fSampleCnt && !renderTarget) { |
| 592 return nullptr; | 594 return nullptr; |
| 593 } | 595 } |
| 594 | 596 |
| 595 switch (ownership) { | 597 switch (ownership) { |
| 596 case kAdopt_GrWrapOwnership: | 598 case kAdopt_GrWrapOwnership: |
| 597 idDesc.fLifeCycle = GrGpuResource::kAdopted_LifeCycle; | 599 idDesc.fLifeCycle = GrBackendObjectLifeCycle::kAdopted; |
| 598 break; | 600 break; |
| 599 case kBorrow_GrWrapOwnership: | 601 case kBorrow_GrWrapOwnership: |
| 600 idDesc.fLifeCycle = GrGpuResource::kBorrowed_LifeCycle; | 602 idDesc.fLifeCycle = GrBackendObjectLifeCycle::kBorrowed; |
| 601 break; | 603 break; |
| 602 } | 604 } |
| 603 | 605 |
| 604 surfDesc.fFlags = (GrSurfaceFlags) desc.fFlags; | 606 surfDesc.fFlags = (GrSurfaceFlags) desc.fFlags; |
| 605 surfDesc.fWidth = desc.fWidth; | 607 surfDesc.fWidth = desc.fWidth; |
| 606 surfDesc.fHeight = desc.fHeight; | 608 surfDesc.fHeight = desc.fHeight; |
| 607 surfDesc.fConfig = desc.fConfig; | 609 surfDesc.fConfig = desc.fConfig; |
| 608 surfDesc.fSampleCnt = SkTMin(desc.fSampleCnt, this->caps()->maxSampleCount() ); | 610 surfDesc.fSampleCnt = SkTMin(desc.fSampleCnt, this->caps()->maxSampleCount() ); |
| 609 // FIXME: this should be calling resolve_origin(), but Chrome code is curre ntly | 611 // FIXME: this should be calling resolve_origin(), but Chrome code is curre ntly |
| 610 // assuming the old behaviour, which is that backend textures are always | 612 // assuming the old behaviour, which is that backend textures are always |
| 611 // BottomLeft, even for non-RT's. Once Chrome is fixed, change this to: | 613 // BottomLeft, even for non-RT's. Once Chrome is fixed, change this to: |
| 612 // glTexDesc.fOrigin = resolve_origin(desc.fOrigin, renderTarget); | 614 // glTexDesc.fOrigin = resolve_origin(desc.fOrigin, renderTarget); |
| 613 if (kDefault_GrSurfaceOrigin == desc.fOrigin) { | 615 if (kDefault_GrSurfaceOrigin == desc.fOrigin) { |
| 614 surfDesc.fOrigin = kBottomLeft_GrSurfaceOrigin; | 616 surfDesc.fOrigin = kBottomLeft_GrSurfaceOrigin; |
| 615 } else { | 617 } else { |
| 616 surfDesc.fOrigin = desc.fOrigin; | 618 surfDesc.fOrigin = desc.fOrigin; |
| 617 } | 619 } |
| 618 | 620 |
| 619 GrGLTexture* texture = nullptr; | 621 GrGLTexture* texture = nullptr; |
| 620 if (renderTarget) { | 622 if (renderTarget) { |
| 621 GrGLRenderTarget::IDDesc rtIDDesc; | 623 GrGLRenderTarget::IDDesc rtIDDesc; |
| 622 if (!this->createRenderTargetObjects(surfDesc, GrGpuResource::kUncached_ LifeCycle, | 624 if (!this->createRenderTargetObjects(surfDesc, idDesc.fInfo, |
| 623 idDesc.fInfo, &rtIDDesc)) { | 625 GrBackendObjectLifeCycle::kBorrowed , &rtIDDesc)) { |
| 624 return nullptr; | 626 return nullptr; |
| 625 } | 627 } |
| 626 texture = new GrGLTextureRenderTarget(this, surfDesc, idDesc, rtIDDesc); | 628 texture = new GrGLTextureRenderTarget(this, SkBudgeted::kNo, surfDesc, i dDesc, rtIDDesc); |
| 627 } else { | 629 } else { |
| 628 texture = new GrGLTexture(this, surfDesc, idDesc); | 630 texture = new GrGLTexture(this, SkBudgeted::kNo, surfDesc, idDesc); |
| 629 } | 631 } |
| 630 if (nullptr == texture) { | 632 if (nullptr == texture) { |
| 631 return nullptr; | 633 return nullptr; |
| 632 } | 634 } |
| 633 | 635 |
| 634 return texture; | 636 return texture; |
| 635 } | 637 } |
| 636 | 638 |
| 637 GrRenderTarget* GrGLGpu::onWrapBackendRenderTarget(const GrBackendRenderTargetDe sc& wrapDesc, | 639 GrRenderTarget* GrGLGpu::onWrapBackendRenderTarget(const GrBackendRenderTargetDe sc& wrapDesc, |
| 638 GrWrapOwnership ownership) { | 640 GrWrapOwnership ownership) { |
| 639 GrGLRenderTarget::IDDesc idDesc; | 641 GrGLRenderTarget::IDDesc idDesc; |
| 640 idDesc.fRTFBOID = static_cast<GrGLuint>(wrapDesc.fRenderTargetHandle); | 642 idDesc.fRTFBOID = static_cast<GrGLuint>(wrapDesc.fRenderTargetHandle); |
| 641 idDesc.fMSColorRenderbufferID = 0; | |
| 642 idDesc.fTexFBOID = GrGLRenderTarget::kUnresolvableFBOID; | |
| 643 switch (ownership) { | 643 switch (ownership) { |
| 644 case kAdopt_GrWrapOwnership: | 644 case kAdopt_GrWrapOwnership: |
| 645 idDesc.fLifeCycle = GrGpuResource::kAdopted_LifeCycle; | 645 idDesc.fRTFBOLifeCycle = GrBackendObjectLifeCycle::kAdopted; |
| 646 break; | 646 break; |
| 647 case kBorrow_GrWrapOwnership: | 647 case kBorrow_GrWrapOwnership: |
| 648 idDesc.fLifeCycle = GrGpuResource::kBorrowed_LifeCycle; | 648 idDesc.fRTFBOLifeCycle = GrBackendObjectLifeCycle::kBorrowed; |
| 649 break; | 649 break; |
| 650 } | 650 } |
| 651 idDesc.fSampleConfig = GrRenderTarget::kUnified_SampleConfig; | 651 idDesc.fSampleConfig = GrRenderTarget::kUnified_SampleConfig; |
| 652 | 652 |
| 653 GrSurfaceDesc desc; | 653 GrSurfaceDesc desc; |
| 654 desc.fConfig = wrapDesc.fConfig; | 654 desc.fConfig = wrapDesc.fConfig; |
| 655 desc.fFlags = kCheckAllocation_GrSurfaceFlag | kRenderTarget_GrSurfaceFlag; | 655 desc.fFlags = kCheckAllocation_GrSurfaceFlag | kRenderTarget_GrSurfaceFlag; |
| 656 desc.fWidth = wrapDesc.fWidth; | 656 desc.fWidth = wrapDesc.fWidth; |
| 657 desc.fHeight = wrapDesc.fHeight; | 657 desc.fHeight = wrapDesc.fHeight; |
| 658 desc.fSampleCnt = SkTMin(wrapDesc.fSampleCnt, this->caps()->maxSampleCount() ); | 658 desc.fSampleCnt = SkTMin(wrapDesc.fSampleCnt, this->caps()->maxSampleCount() ); |
| 659 desc.fOrigin = resolve_origin(wrapDesc.fOrigin, true); | 659 desc.fOrigin = resolve_origin(wrapDesc.fOrigin, true); |
| 660 | 660 |
| 661 return GrGLRenderTarget::CreateWrapped(this, desc, idDesc, wrapDesc.fStencil Bits); | 661 return GrGLRenderTarget::CreateWrapped(this, SkBudgeted::kNo, desc, idDesc, wrapDesc.fStencilBits); |
| 662 } | 662 } |
| 663 | 663 |
| 664 GrRenderTarget* GrGLGpu::onWrapBackendTextureAsRenderTarget(const GrBackendTextu reDesc& desc, | 664 GrRenderTarget* GrGLGpu::onWrapBackendTextureAsRenderTarget(const GrBackendTextu reDesc& desc, |
| 665 GrWrapOwnership owne rship) { | 665 GrWrapOwnership owne rship) { |
|
Kimmo Kinnunen
2016/03/18 20:02:19
This is the implementation.
| |
| 666 // NOTE: the potential backing color renderbuffer is not initialized with | |
| 667 // the backend texture contents, so blended rendering and pixel reading migh t | |
| 668 // not be correct, since wrapped render targets are not cleared. | |
| 669 GrGLTextureInfo texInfo; | |
| 666 #ifdef SK_IGNORE_GL_TEXTURE_TARGET | 670 #ifdef SK_IGNORE_GL_TEXTURE_TARGET |
| 667 if (!desc.fTextureHandle) { | 671 if (!desc.fTextureHandle) { |
| 668 return nullptr; | 672 return nullptr; |
| 669 } | 673 } |
| 674 texInfo.fID = static_cast<GrGLuint>(desc.fTextureHandle); | |
| 675 // We only support GL_TEXTURE_2D at the moment. | |
| 676 texInfo.fTarget = GR_GL_TEXTURE_2D; | |
| 670 #else | 677 #else |
| 671 const GrGLTextureInfo* info = reinterpret_cast<const GrGLTextureInfo*>(desc. fTextureHandle); | 678 const GrGLTextureInfo* info = reinterpret_cast<const GrGLTextureInfo*>(desc. fTextureHandle); |
| 672 if (!info || !info->fID) { | 679 if (!info || !info->fID) { |
| 673 return nullptr; | 680 return nullptr; |
| 674 } | 681 } |
| 682 texInfo = *info; | |
| 675 #endif | 683 #endif |
| 676 | 684 |
| 677 GrGLTexture::IDDesc idDesc; | 685 if (GR_GL_TEXTURE_RECTANGLE != texInfo.fTarget && |
| 678 GrSurfaceDesc surfDesc; | 686 GR_GL_TEXTURE_2D != texInfo.fTarget) { |
| 679 | |
| 680 #ifdef SK_IGNORE_GL_TEXTURE_TARGET | |
| 681 idDesc.fInfo.fID = static_cast<GrGLuint>(desc.fTextureHandle); | |
| 682 // We only support GL_TEXTURE_2D at the moment. | |
| 683 idDesc.fInfo.fTarget = GR_GL_TEXTURE_2D; | |
| 684 #else | |
| 685 idDesc.fInfo = *info; | |
| 686 #endif | |
| 687 | |
| 688 if (GR_GL_TEXTURE_RECTANGLE != idDesc.fInfo.fTarget && | |
| 689 GR_GL_TEXTURE_2D != idDesc.fInfo.fTarget) { | |
| 690 // Only texture rectangle and texture 2d are supported. We do not check whether texture | 687 // Only texture rectangle and texture 2d are supported. We do not check whether texture |
| 691 // rectangle is supported by Skia - if the caller provided us with a tex ture rectangle, | 688 // rectangle is supported by Skia - if the caller provided us with a tex ture rectangle, |
| 692 // we assume the necessary support exists. | 689 // we assume the necessary support exists. |
| 693 return nullptr; | 690 return nullptr; |
| 694 } | 691 } |
| 695 | 692 |
| 693 GrBackendObjectLifeCycle texLifeCycle = GrBackendObjectLifeCycle::kBorrowed; | |
| 696 switch (ownership) { | 694 switch (ownership) { |
| 697 case kAdopt_GrWrapOwnership: | 695 case kAdopt_GrWrapOwnership: |
| 698 idDesc.fLifeCycle = GrGpuResource::kAdopted_LifeCycle; | 696 texLifeCycle = GrBackendObjectLifeCycle::kAdopted; |
| 699 break; | 697 break; |
| 700 case kBorrow_GrWrapOwnership: | 698 case kBorrow_GrWrapOwnership: |
| 701 idDesc.fLifeCycle = GrGpuResource::kBorrowed_LifeCycle; | 699 texLifeCycle = GrBackendObjectLifeCycle::kBorrowed; |
| 702 break; | 700 break; |
| 703 } | 701 } |
| 704 | 702 |
| 703 static const GrUniqueKey::Domain kDomain = GrUniqueKey::GenerateDomain(); | |
| 704 GrUniqueKey key; | |
| 705 GrUniqueKey::Builder builder(&key, kDomain, 3); | |
| 706 builder[0] = desc.fWidth; | |
| 707 builder[1] = desc.fHeight; | |
| 708 builder[2] = desc.fConfig | (desc.fFlags << 5) | (desc.fSampleCnt << 6) | (d esc.fOrigin << 14) | |
| 709 | (ownership << 15) | ((texInfo.fTarget == GR_GL_TEXTURE_2D) << 17); | |
| 710 builder.finish(); | |
| 711 | |
| 712 GrGLRenderTarget *rt = static_cast<GrGLRenderTarget*>( | |
| 713 getContext()->resourceProvider()->findAndRefRenderTargetByUniqueKey(key) ); | |
| 714 if (rt) { | |
| 715 fStats.incRenderTargetBinds(); | |
| 716 GL_CALL(BindFramebuffer(GR_GL_FRAMEBUFFER, rt->textureFBOID())); | |
| 717 GL_CALL(FramebufferTexture2D(GR_GL_FRAMEBUFFER, | |
| 718 GR_GL_COLOR_ATTACHMENT0, | |
| 719 texInfo.fTarget, | |
| 720 texInfo.fID, 0)); | |
| 721 return rt; | |
| 722 } | |
| 723 | |
| 724 GrSurfaceDesc surfDesc; | |
| 705 surfDesc.fFlags = (GrSurfaceFlags) desc.fFlags; | 725 surfDesc.fFlags = (GrSurfaceFlags) desc.fFlags; |
| 706 surfDesc.fWidth = desc.fWidth; | 726 surfDesc.fWidth = desc.fWidth; |
| 707 surfDesc.fHeight = desc.fHeight; | 727 surfDesc.fHeight = desc.fHeight; |
| 708 surfDesc.fConfig = desc.fConfig; | 728 surfDesc.fConfig = desc.fConfig; |
| 709 surfDesc.fSampleCnt = SkTMin(desc.fSampleCnt, this->caps()->maxSampleCount() ); | 729 surfDesc.fSampleCnt = SkTMin(desc.fSampleCnt, this->caps()->maxSampleCount() ); |
| 710 // FIXME: this should be calling resolve_origin(), but Chrome code is curre ntly | 730 // FIXME: this should be calling resolve_origin(), but Chrome code is curre ntly |
| 711 // assuming the old behaviour, which is that backend textures are always | 731 // assuming the old behaviour, which is that backend textures are always |
| 712 // BottomLeft, even for non-RT's. Once Chrome is fixed, change this to: | 732 // BottomLeft, even for non-RT's. Once Chrome is fixed, change this to: |
| 713 // glTexDesc.fOrigin = resolve_origin(desc.fOrigin, renderTarget); | 733 // glTexDesc.fOrigin = resolve_origin(desc.fOrigin, renderTarget); |
| 714 if (kDefault_GrSurfaceOrigin == desc.fOrigin) { | 734 if (kDefault_GrSurfaceOrigin == desc.fOrigin) { |
| 715 surfDesc.fOrigin = kBottomLeft_GrSurfaceOrigin; | 735 surfDesc.fOrigin = kBottomLeft_GrSurfaceOrigin; |
| 716 } else { | 736 } else { |
| 717 surfDesc.fOrigin = desc.fOrigin; | 737 surfDesc.fOrigin = desc.fOrigin; |
| 718 } | 738 } |
| 719 | 739 |
| 720 GrGLRenderTarget::IDDesc rtIDDesc; | 740 GrGLRenderTarget::IDDesc rtIDDesc; |
| 721 if (!this->createRenderTargetObjects(surfDesc, GrGpuResource::kUncached_Life Cycle, | 741 if (!this->createRenderTargetObjects(surfDesc, texInfo, texLifeCycle, &rtIDD esc)) { |
| 722 idDesc.fInfo, &rtIDDesc)) { | |
| 723 return nullptr; | 742 return nullptr; |
| 724 } | 743 } |
| 725 return GrGLRenderTarget::CreateWrapped(this, surfDesc, rtIDDesc, 0); | 744 rt = GrGLRenderTarget::CreateWrapped(this, SkBudgeted::kYes, surfDesc, rtIDD esc, 0); |
| 745 rt->resourcePriv().setUniqueKey(key); | |
| 746 return rt; | |
| 726 } | 747 } |
| 727 | 748 |
| 728 //////////////////////////////////////////////////////////////////////////////// | 749 //////////////////////////////////////////////////////////////////////////////// |
| 729 | 750 |
| 730 bool GrGLGpu::onGetWritePixelsInfo(GrSurface* dstSurface, int width, int height, | 751 bool GrGLGpu::onGetWritePixelsInfo(GrSurface* dstSurface, int width, int height, |
| 731 GrPixelConfig srcConfig, | 752 GrPixelConfig srcConfig, |
| 732 DrawPreference* drawPreference, | 753 DrawPreference* drawPreference, |
| 733 WritePixelTempDrawInfo* tempDrawInfo) { | 754 WritePixelTempDrawInfo* tempDrawInfo) { |
| 734 if (kIndex_8_GrPixelConfig == srcConfig || GrPixelConfigIsCompressed(dstSurf ace->config())) { | 755 if (kIndex_8_GrPixelConfig == srcConfig || GrPixelConfigIsCompressed(dstSurf ace->config())) { |
| 735 return false; | 756 return false; |
| (...skipping 693 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1429 width, height)); | 1450 width, height)); |
| 1430 break; | 1451 break; |
| 1431 case GrGLCaps::kNone_MSFBOType: | 1452 case GrGLCaps::kNone_MSFBOType: |
| 1432 SkFAIL("Shouldn't be here if we don't support multisampled renderbuf fers."); | 1453 SkFAIL("Shouldn't be here if we don't support multisampled renderbuf fers."); |
| 1433 break; | 1454 break; |
| 1434 } | 1455 } |
| 1435 return (GR_GL_NO_ERROR == CHECK_ALLOC_ERROR(ctx.interface())); | 1456 return (GR_GL_NO_ERROR == CHECK_ALLOC_ERROR(ctx.interface())); |
| 1436 } | 1457 } |
| 1437 | 1458 |
| 1438 bool GrGLGpu::createRenderTargetObjects(const GrSurfaceDesc& desc, | 1459 bool GrGLGpu::createRenderTargetObjects(const GrSurfaceDesc& desc, |
| 1439 GrGpuResource::LifeCycle lifeCycle, | |
| 1440 const GrGLTextureInfo& texInfo, | 1460 const GrGLTextureInfo& texInfo, |
| 1461 GrBackendObjectLifeCycle texLifeCycle, | |
| 1441 GrGLRenderTarget::IDDesc* idDesc) { | 1462 GrGLRenderTarget::IDDesc* idDesc) { |
| 1442 idDesc->fMSColorRenderbufferID = 0; | |
| 1443 idDesc->fRTFBOID = 0; | |
| 1444 idDesc->fTexFBOID = 0; | |
| 1445 idDesc->fLifeCycle = lifeCycle; | |
| 1446 idDesc->fSampleConfig = (GrGLCaps::kMixedSamples_MSFBOType == this->glCaps() .msFBOType() && | 1463 idDesc->fSampleConfig = (GrGLCaps::kMixedSamples_MSFBOType == this->glCaps() .msFBOType() && |
| 1447 desc.fSampleCnt > 0) ? GrRenderTarget::kStencil_Samp leConfig : | 1464 desc.fSampleCnt > 0) ? GrRenderTarget::kStencil_Samp leConfig : |
| 1448 GrRenderTarget::kUnified_Samp leConfig; | 1465 GrRenderTarget::kUnified_Samp leConfig; |
| 1449 | 1466 idDesc->fTexID = texInfo.fID; |
| 1467 idDesc->fTexLifeCycle = texLifeCycle; | |
| 1468 idDesc->fRTFBOLifeCycle = GrBackendObjectLifeCycle::kInternal; | |
| 1450 GrGLenum status; | 1469 GrGLenum status; |
| 1451 | 1470 |
| 1452 GrGLenum colorRenderbufferFormat = 0; // suppress warning | 1471 GrGLenum colorRenderbufferFormat = 0; // suppress warning |
| 1453 | 1472 |
| 1454 if (desc.fSampleCnt > 0 && GrGLCaps::kNone_MSFBOType == this->glCaps().msFBO Type()) { | 1473 if (desc.fSampleCnt > 0 && GrGLCaps::kNone_MSFBOType == this->glCaps().msFBO Type()) { |
| 1455 goto FAILED; | 1474 goto FAILED; |
| 1456 } | 1475 } |
| 1457 | 1476 |
| 1458 GL_CALL(GenFramebuffers(1, &idDesc->fTexFBOID)); | 1477 GL_CALL(GenFramebuffers(1, &idDesc->fTexFBOID)); |
| 1459 if (!idDesc->fTexFBOID) { | 1478 if (!idDesc->fTexFBOID) { |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1547 // SkDEBUGFAIL("null texture"); | 1566 // SkDEBUGFAIL("null texture"); |
| 1548 return nullptr; | 1567 return nullptr; |
| 1549 } | 1568 } |
| 1550 | 1569 |
| 1551 #if 0 && defined(SK_DEBUG) | 1570 #if 0 && defined(SK_DEBUG) |
| 1552 static size_t as_size_t(int x) { | 1571 static size_t as_size_t(int x) { |
| 1553 return x; | 1572 return x; |
| 1554 } | 1573 } |
| 1555 #endif | 1574 #endif |
| 1556 | 1575 |
| 1557 static GrGLTexture::IDDesc generate_gl_texture(const GrGLInterface* interface, | 1576 static GrGLTexture::IDDesc generate_gl_texture(const GrGLInterface* interface) { |
| 1558 GrGpuResource::LifeCycle lifeCycl e) { | |
| 1559 GrGLTexture::IDDesc idDesc; | 1577 GrGLTexture::IDDesc idDesc; |
| 1560 idDesc.fInfo.fID = 0; | 1578 idDesc.fInfo.fID = 0; |
| 1561 GR_GL_CALL(interface, GenTextures(1, &idDesc.fInfo.fID)); | 1579 GR_GL_CALL(interface, GenTextures(1, &idDesc.fInfo.fID)); |
| 1562 idDesc.fLifeCycle = lifeCycle; | 1580 idDesc.fLifeCycle = GrBackendObjectLifeCycle::kInternal; |
| 1563 // When we create the texture, we only | 1581 // When we create the texture, we only |
| 1564 // create GL_TEXTURE_2D at the moment. | 1582 // create GL_TEXTURE_2D at the moment. |
| 1565 // External clients can do something different. | 1583 // External clients can do something different. |
| 1566 idDesc.fInfo.fTarget = GR_GL_TEXTURE_2D; | 1584 idDesc.fInfo.fTarget = GR_GL_TEXTURE_2D; |
| 1567 return idDesc; | 1585 return idDesc; |
| 1568 } | 1586 } |
| 1569 | 1587 |
| 1570 static void set_initial_texture_params(const GrGLInterface* interface, | 1588 static void set_initial_texture_params(const GrGLInterface* interface, |
| 1571 const GrGLTextureInfo& info, | 1589 const GrGLTextureInfo& info, |
| 1572 GrGLTexture::TexParams* initialTexParams) { | 1590 GrGLTexture::TexParams* initialTexParams) { |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 1587 initialTexParams->fMinFilter)); | 1605 initialTexParams->fMinFilter)); |
| 1588 GR_GL_CALL(interface, TexParameteri(info.fTarget, | 1606 GR_GL_CALL(interface, TexParameteri(info.fTarget, |
| 1589 GR_GL_TEXTURE_WRAP_S, | 1607 GR_GL_TEXTURE_WRAP_S, |
| 1590 initialTexParams->fWrapS)); | 1608 initialTexParams->fWrapS)); |
| 1591 GR_GL_CALL(interface, TexParameteri(info.fTarget, | 1609 GR_GL_CALL(interface, TexParameteri(info.fTarget, |
| 1592 GR_GL_TEXTURE_WRAP_T, | 1610 GR_GL_TEXTURE_WRAP_T, |
| 1593 initialTexParams->fWrapT)); | 1611 initialTexParams->fWrapT)); |
| 1594 } | 1612 } |
| 1595 | 1613 |
| 1596 GrTexture* GrGLGpu::onCreateTexture(const GrSurfaceDesc& desc, | 1614 GrTexture* GrGLGpu::onCreateTexture(const GrSurfaceDesc& desc, |
| 1597 GrGpuResource::LifeCycle lifeCycle, | 1615 SkBudgeted budgeted, |
| 1598 const SkTArray<GrMipLevel>& texels) { | 1616 const SkTArray<GrMipLevel>& texels) { |
| 1599 // We fail if the MSAA was requested and is not available. | 1617 // We fail if the MSAA was requested and is not available. |
| 1600 if (GrGLCaps::kNone_MSFBOType == this->glCaps().msFBOType() && desc.fSampleC nt) { | 1618 if (GrGLCaps::kNone_MSFBOType == this->glCaps().msFBOType() && desc.fSampleC nt) { |
| 1601 //SkDebugf("MSAA RT requested but not supported on this platform."); | 1619 //SkDebugf("MSAA RT requested but not supported on this platform."); |
| 1602 return return_null_texture(); | 1620 return return_null_texture(); |
| 1603 } | 1621 } |
| 1604 | 1622 |
| 1605 bool renderTarget = SkToBool(desc.fFlags & kRenderTarget_GrSurfaceFlag); | 1623 bool renderTarget = SkToBool(desc.fFlags & kRenderTarget_GrSurfaceFlag); |
| 1606 | 1624 |
| 1607 GrGLTexture::IDDesc idDesc; | 1625 GrGLTexture::IDDesc idDesc; |
| 1608 idDesc.fLifeCycle = lifeCycle; | 1626 idDesc.fLifeCycle = GrBackendObjectLifeCycle::kInternal; |
| 1609 GrGLTexture::TexParams initialTexParams; | 1627 GrGLTexture::TexParams initialTexParams; |
| 1610 if (!this->createTextureImpl(desc, &idDesc.fInfo, renderTarget, &initialTexP arams, texels)) { | 1628 if (!this->createTextureImpl(desc, &idDesc.fInfo, renderTarget, &initialTexP arams, texels)) { |
| 1611 return return_null_texture(); | 1629 return return_null_texture(); |
| 1612 } | 1630 } |
| 1613 | 1631 |
| 1614 GrGLTexture* tex; | 1632 GrGLTexture* tex; |
| 1615 if (renderTarget) { | 1633 if (renderTarget) { |
| 1616 // unbind the texture from the texture unit before binding it to the fra me buffer | 1634 // unbind the texture from the texture unit before binding it to the fra me buffer |
| 1617 GL_CALL(BindTexture(idDesc.fInfo.fTarget, 0)); | 1635 GL_CALL(BindTexture(idDesc.fInfo.fTarget, 0)); |
| 1618 GrGLRenderTarget::IDDesc rtIDDesc; | 1636 GrGLRenderTarget::IDDesc rtIDDesc; |
| 1619 | 1637 |
| 1620 if (!this->createRenderTargetObjects(desc, lifeCycle, idDesc.fInfo, &rtI DDesc)) { | 1638 if (!this->createRenderTargetObjects(desc, idDesc.fInfo, |
| 1639 GrBackendObjectLifeCycle::kBorrowed , &rtIDDesc)) { | |
| 1621 GL_CALL(DeleteTextures(1, &idDesc.fInfo.fID)); | 1640 GL_CALL(DeleteTextures(1, &idDesc.fInfo.fID)); |
| 1622 return return_null_texture(); | 1641 return return_null_texture(); |
| 1623 } | 1642 } |
| 1624 tex = new GrGLTextureRenderTarget(this, desc, idDesc, rtIDDesc); | 1643 tex = new GrGLTextureRenderTarget(this, budgeted, desc, idDesc, rtIDDesc ); |
| 1625 } else { | 1644 } else { |
| 1626 bool wasMipMapDataProvided = false; | 1645 bool wasMipMapDataProvided = false; |
| 1627 if (texels.count() > 1) { | 1646 if (texels.count() > 1) { |
| 1628 wasMipMapDataProvided = true; | 1647 wasMipMapDataProvided = true; |
| 1629 } | 1648 } |
| 1630 tex = new GrGLTexture(this, desc, idDesc, wasMipMapDataProvided); | 1649 tex = new GrGLTexture(this, budgeted, desc, idDesc, wasMipMapDataProvide d); |
| 1631 } | 1650 } |
| 1632 tex->setCachedTexParams(initialTexParams, this->getResetTimestamp()); | 1651 tex->setCachedTexParams(initialTexParams, this->getResetTimestamp()); |
| 1633 #ifdef TRACE_TEXTURE_CREATION | 1652 #ifdef TRACE_TEXTURE_CREATION |
| 1634 SkDebugf("--- new texture [%d] size=(%d %d) config=%d\n", | 1653 SkDebugf("--- new texture [%d] size=(%d %d) config=%d\n", |
| 1635 glTexDesc.fInfo.fID, desc.fWidth, desc.fHeight, desc.fConfig); | 1654 glTexDesc.fInfo.fID, desc.fWidth, desc.fHeight, desc.fConfig); |
| 1636 #endif | 1655 #endif |
| 1637 return tex; | 1656 return tex; |
| 1638 } | 1657 } |
| 1639 | 1658 |
| 1640 GrTexture* GrGLGpu::onCreateCompressedTexture(const GrSurfaceDesc& desc, | 1659 GrTexture* GrGLGpu::onCreateCompressedTexture(const GrSurfaceDesc& desc, |
| 1641 GrGpuResource::LifeCycle lifeCycle , | 1660 SkBudgeted budgeted, |
| 1642 const SkTArray<GrMipLevel>& texels ) { | 1661 const SkTArray<GrMipLevel>& texels ) { |
| 1643 // Make sure that we're not flipping Y. | 1662 // Make sure that we're not flipping Y. |
| 1644 if (kBottomLeft_GrSurfaceOrigin == desc.fOrigin) { | 1663 if (kBottomLeft_GrSurfaceOrigin == desc.fOrigin) { |
| 1645 return return_null_texture(); | 1664 return return_null_texture(); |
| 1646 } | 1665 } |
| 1647 | 1666 |
| 1648 GrGLTexture::IDDesc idDesc = generate_gl_texture(this->glInterface(), lifeCy cle); | 1667 GrGLTexture::IDDesc idDesc = generate_gl_texture(this->glInterface()); |
| 1649 if (!idDesc.fInfo.fID) { | 1668 if (!idDesc.fInfo.fID) { |
| 1650 return return_null_texture(); | 1669 return return_null_texture(); |
| 1651 } | 1670 } |
| 1652 | 1671 |
| 1653 this->setScratchTextureUnit(); | 1672 this->setScratchTextureUnit(); |
| 1654 GL_CALL(BindTexture(idDesc.fInfo.fTarget, idDesc.fInfo.fID)); | 1673 GL_CALL(BindTexture(idDesc.fInfo.fTarget, idDesc.fInfo.fID)); |
| 1655 | 1674 |
| 1656 GrGLTexture::TexParams initialTexParams; | 1675 GrGLTexture::TexParams initialTexParams; |
| 1657 set_initial_texture_params(this->glInterface(), idDesc.fInfo, &initialTexPar ams); | 1676 set_initial_texture_params(this->glInterface(), idDesc.fInfo, &initialTexPar ams); |
| 1658 | 1677 |
| 1659 if (!this->uploadCompressedTexData(desc, idDesc.fInfo.fTarget, texels)) { | 1678 if (!this->uploadCompressedTexData(desc, idDesc.fInfo.fTarget, texels)) { |
| 1660 GL_CALL(DeleteTextures(1, &idDesc.fInfo.fID)); | 1679 GL_CALL(DeleteTextures(1, &idDesc.fInfo.fID)); |
| 1661 return return_null_texture(); | 1680 return return_null_texture(); |
| 1662 } | 1681 } |
| 1663 | 1682 |
| 1664 GrGLTexture* tex; | 1683 GrGLTexture* tex; |
| 1665 tex = new GrGLTexture(this, desc, idDesc); | 1684 tex = new GrGLTexture(this, budgeted, desc, idDesc); |
| 1666 tex->setCachedTexParams(initialTexParams, this->getResetTimestamp()); | 1685 tex->setCachedTexParams(initialTexParams, this->getResetTimestamp()); |
| 1667 #ifdef TRACE_TEXTURE_CREATION | 1686 #ifdef TRACE_TEXTURE_CREATION |
| 1668 SkDebugf("--- new compressed texture [%d] size=(%d %d) config=%d\n", | 1687 SkDebugf("--- new compressed texture [%d] size=(%d %d) config=%d\n", |
| 1669 glTexDesc.fInfo.fID, desc.fWidth, desc.fHeight, desc.fConfig); | 1688 glTexDesc.fInfo.fID, desc.fWidth, desc.fHeight, desc.fConfig); |
| 1670 #endif | 1689 #endif |
| 1671 return tex; | 1690 return tex; |
| 1672 } | 1691 } |
| 1673 | 1692 |
| 1674 namespace { | 1693 namespace { |
| 1675 | 1694 |
| (...skipping 2714 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4390 if (GR_GL_TEXTURE_EXTERNAL == glTexture->target() || | 4409 if (GR_GL_TEXTURE_EXTERNAL == glTexture->target() || |
| 4391 GR_GL_TEXTURE_RECTANGLE == glTexture->target()) { | 4410 GR_GL_TEXTURE_RECTANGLE == glTexture->target()) { |
| 4392 copyParams->fFilter = GrTextureParams::kNone_FilterMode; | 4411 copyParams->fFilter = GrTextureParams::kNone_FilterMode; |
| 4393 copyParams->fWidth = texture->width(); | 4412 copyParams->fWidth = texture->width(); |
| 4394 copyParams->fHeight = texture->height(); | 4413 copyParams->fHeight = texture->height(); |
| 4395 return true; | 4414 return true; |
| 4396 } | 4415 } |
| 4397 } | 4416 } |
| 4398 return false; | 4417 return false; |
| 4399 } | 4418 } |
| OLD | NEW |