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 "GrGpuGL.h" | 9 #include "GrGpuGL.h" |
10 #include "GrGLNameAllocator.h" | 10 #include "GrGLNameAllocator.h" |
(...skipping 558 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
569 size_t bpp = GrBytesPerPixel(dataConfig); | 569 size_t bpp = GrBytesPerPixel(dataConfig); |
570 if (!adjust_pixel_ops_params(desc.fWidth, desc.fHeight, bpp, &left, &top, | 570 if (!adjust_pixel_ops_params(desc.fWidth, desc.fHeight, bpp, &left, &top, |
571 &width, &height, &data, &rowBytes)) { | 571 &width, &height, &data, &rowBytes)) { |
572 return false; | 572 return false; |
573 } | 573 } |
574 size_t trimRowBytes = width * bpp; | 574 size_t trimRowBytes = width * bpp; |
575 | 575 |
576 // in case we need a temporary, trimmed copy of the src pixels | 576 // in case we need a temporary, trimmed copy of the src pixels |
577 SkAutoSMalloc<128 * 128> tempStorage; | 577 SkAutoSMalloc<128 * 128> tempStorage; |
578 | 578 |
579 // paletted textures cannot be partially updated | |
580 // We currently lazily create MIPMAPs when the we see a draw with | 579 // We currently lazily create MIPMAPs when the we see a draw with |
581 // GrTextureParams::kMipMap_FilterMode. Using texture storage requires that
the | 580 // GrTextureParams::kMipMap_FilterMode. Using texture storage requires that
the |
582 // MIP levels are all created when the texture is created. So for now we don
't use | 581 // MIP levels are all created when the texture is created. So for now we don
't use |
583 // texture storage. | 582 // texture storage. |
584 bool useTexStorage = false && | 583 bool useTexStorage = false && |
585 isNewTexture && | 584 isNewTexture && |
586 kIndex_8_GrPixelConfig != desc.fConfig && | |
587 this->glCaps().texStorageSupport(); | 585 this->glCaps().texStorageSupport(); |
588 | 586 |
589 if (useTexStorage && kGL_GrGLStandard == this->glStandard()) { | 587 if (useTexStorage && kGL_GrGLStandard == this->glStandard()) { |
590 // 565 is not a sized internal format on desktop GL. So on desktop with | 588 // 565 is not a sized internal format on desktop GL. So on desktop with |
591 // 565 we always use an unsized internal format to let the system pick | 589 // 565 we always use an unsized internal format to let the system pick |
592 // the best sized format to convert the 565 data to. Since TexStorage | 590 // the best sized format to convert the 565 data to. Since TexStorage |
593 // only allows sized internal formats we will instead use TexImage2D. | 591 // only allows sized internal formats we will instead use TexImage2D. |
594 useTexStorage = desc.fConfig != kRGB_565_GrPixelConfig; | 592 useTexStorage = desc.fConfig != kRGB_565_GrPixelConfig; |
595 } | 593 } |
596 | 594 |
(...skipping 10 matching lines...) Expand all Loading... |
607 // glTexImage2D for the internal format but will accept GL_R8. | 605 // glTexImage2D for the internal format but will accept GL_R8. |
608 if (!useSizedFormat && kNVIDIA_GrGLVendor == this->glContext().vendor() && | 606 if (!useSizedFormat && kNVIDIA_GrGLVendor == this->glContext().vendor() && |
609 kGLES_GrGLStandard == this->glStandard() && this->glVersion() >= GR_GL_V
ER(3, 0)) { | 607 kGLES_GrGLStandard == this->glStandard() && this->glVersion() >= GR_GL_V
ER(3, 0)) { |
610 useSizedFormat = true; | 608 useSizedFormat = true; |
611 } | 609 } |
612 if (!this->configToGLFormats(dataConfig, useSizedFormat, &internalFormat, | 610 if (!this->configToGLFormats(dataConfig, useSizedFormat, &internalFormat, |
613 &externalFormat, &externalType)) { | 611 &externalFormat, &externalType)) { |
614 return false; | 612 return false; |
615 } | 613 } |
616 | 614 |
617 if (!isNewTexture && GR_GL_PALETTE8_RGBA8 == internalFormat) { | |
618 // paletted textures cannot be updated | |
619 return false; | |
620 } | |
621 | |
622 /* | 615 /* |
623 * check whether to allocate a temporary buffer for flipping y or | 616 * check whether to allocate a temporary buffer for flipping y or |
624 * because our srcData has extra bytes past each row. If so, we need | 617 * because our srcData has extra bytes past each row. If so, we need |
625 * to trim those off here, since GL ES may not let us specify | 618 * to trim those off here, since GL ES may not let us specify |
626 * GL_UNPACK_ROW_LENGTH. | 619 * GL_UNPACK_ROW_LENGTH. |
627 */ | 620 */ |
628 bool restoreGLRowLength = false; | 621 bool restoreGLRowLength = false; |
629 bool swFlipY = false; | 622 bool swFlipY = false; |
630 bool glFlipY = false; | 623 bool glFlipY = false; |
631 if (NULL != data) { | 624 if (NULL != data) { |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
677 desc.fWidth == width && desc.fHeight == height) { | 670 desc.fWidth == width && desc.fHeight == height) { |
678 CLEAR_ERROR_BEFORE_ALLOC(this->glInterface()); | 671 CLEAR_ERROR_BEFORE_ALLOC(this->glInterface()); |
679 if (useTexStorage) { | 672 if (useTexStorage) { |
680 // We never resize or change formats of textures. | 673 // We never resize or change formats of textures. |
681 GL_ALLOC_CALL(this->glInterface(), | 674 GL_ALLOC_CALL(this->glInterface(), |
682 TexStorage2D(GR_GL_TEXTURE_2D, | 675 TexStorage2D(GR_GL_TEXTURE_2D, |
683 1, // levels | 676 1, // levels |
684 internalFormat, | 677 internalFormat, |
685 desc.fWidth, desc.fHeight)); | 678 desc.fWidth, desc.fHeight)); |
686 } else { | 679 } else { |
687 if (GR_GL_PALETTE8_RGBA8 == internalFormat) { | 680 GL_ALLOC_CALL(this->glInterface(), |
688 GrGLsizei imageSize = desc.fWidth * desc.fHeight + | 681 TexImage2D(GR_GL_TEXTURE_2D, |
689 kGrColorTableSize; | 682 0, // level |
690 GL_ALLOC_CALL(this->glInterface(), | 683 internalFormat, |
691 CompressedTexImage2D(GR_GL_TEXTURE_2D, | 684 desc.fWidth, desc.fHeight, |
692 0, // level | 685 0, // border |
693 internalFormat, | 686 externalFormat, externalType, |
694 desc.fWidth, desc.fHeight, | 687 data)); |
695 0, // border | |
696 imageSize, | |
697 data)); | |
698 } else { | |
699 GL_ALLOC_CALL(this->glInterface(), | |
700 TexImage2D(GR_GL_TEXTURE_2D, | |
701 0, // level | |
702 internalFormat, | |
703 desc.fWidth, desc.fHeight, | |
704 0, // border | |
705 externalFormat, externalType, | |
706 data)); | |
707 } | |
708 } | 688 } |
709 GrGLenum error = check_alloc_error(desc, this->glInterface()); | 689 GrGLenum error = check_alloc_error(desc, this->glInterface()); |
710 if (error != GR_GL_NO_ERROR) { | 690 if (error != GR_GL_NO_ERROR) { |
711 succeeded = false; | 691 succeeded = false; |
712 } else { | 692 } else { |
713 // if we have data and we used TexStorage to create the texture, we | 693 // if we have data and we used TexStorage to create the texture, we |
714 // now upload with TexSubImage. | 694 // now upload with TexSubImage. |
715 if (NULL != data && useTexStorage) { | 695 if (NULL != data && useTexStorage) { |
716 GL_CALL(TexSubImage2D(GR_GL_TEXTURE_2D, | 696 GL_CALL(TexSubImage2D(GR_GL_TEXTURE_2D, |
717 0, // level | 697 0, // level |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
777 // Make sure that the width and height that we pass to OpenGL | 757 // Make sure that the width and height that we pass to OpenGL |
778 // is a multiple of the block size. | 758 // is a multiple of the block size. |
779 int dataSize = GrCompressedFormatDataSize(desc.fConfig, width, height); | 759 int dataSize = GrCompressedFormatDataSize(desc.fConfig, width, height); |
780 | 760 |
781 // We only need the internal format for compressed 2D textures. | 761 // We only need the internal format for compressed 2D textures. |
782 GrGLenum internalFormat = 0; | 762 GrGLenum internalFormat = 0; |
783 if (!this->configToGLFormats(desc.fConfig, false, &internalFormat, NULL, NUL
L)) { | 763 if (!this->configToGLFormats(desc.fConfig, false, &internalFormat, NULL, NUL
L)) { |
784 return false; | 764 return false; |
785 } | 765 } |
786 | 766 |
787 bool succeeded = true; | |
788 CLEAR_ERROR_BEFORE_ALLOC(this->glInterface()); | |
789 | |
790 if (isNewTexture) { | 767 if (isNewTexture) { |
| 768 CLEAR_ERROR_BEFORE_ALLOC(this->glInterface()); |
791 GL_ALLOC_CALL(this->glInterface(), | 769 GL_ALLOC_CALL(this->glInterface(), |
792 CompressedTexImage2D(GR_GL_TEXTURE_2D, | 770 CompressedTexImage2D(GR_GL_TEXTURE_2D, |
793 0, // level | 771 0, // level |
794 internalFormat, | 772 internalFormat, |
795 width, height, | 773 width, height, |
796 0, // border | 774 0, // border |
797 dataSize, | 775 dataSize, |
798 data)); | 776 data)); |
| 777 GrGLenum error = check_alloc_error(desc, this->glInterface()); |
| 778 if (error != GR_GL_NO_ERROR) { |
| 779 return false; |
| 780 } |
799 } else { | 781 } else { |
800 GL_ALLOC_CALL(this->glInterface(), | 782 // Paletted textures can't be updated. |
801 CompressedTexSubImage2D(GR_GL_TEXTURE_2D, | 783 if (GR_GL_PALETTE8_RGBA8 == internalFormat) { |
802 0, // level | 784 return false; |
803 left, top, | 785 } |
804 width, height, | 786 GL_CALL(CompressedTexSubImage2D(GR_GL_TEXTURE_2D, |
805 internalFormat, | 787 0, // level |
806 dataSize, | 788 left, top, |
807 data)); | 789 width, height, |
| 790 internalFormat, |
| 791 dataSize, |
| 792 data)); |
808 } | 793 } |
809 | 794 |
810 GrGLenum error = check_alloc_error(desc, this->glInterface()); | 795 return true; |
811 if (error != GR_GL_NO_ERROR) { | |
812 succeeded = false; | |
813 } | |
814 return succeeded; | |
815 } | 796 } |
816 | 797 |
817 static bool renderbuffer_storage_msaa(GrGLContext& ctx, | 798 static bool renderbuffer_storage_msaa(GrGLContext& ctx, |
818 int sampleCount, | 799 int sampleCount, |
819 GrGLenum format, | 800 GrGLenum format, |
820 int width, int height) { | 801 int width, int height) { |
821 CLEAR_ERROR_BEFORE_ALLOC(ctx.interface()); | 802 CLEAR_ERROR_BEFORE_ALLOC(ctx.interface()); |
822 SkASSERT(GrGLCaps::kNone_MSFBOType != ctx.caps()->msFBOType()); | 803 SkASSERT(GrGLCaps::kNone_MSFBOType != ctx.caps()->msFBOType()); |
823 switch (ctx.caps()->msFBOType()) { | 804 switch (ctx.caps()->msFBOType()) { |
824 case GrGLCaps::kDesktop_ARB_MSFBOType: | 805 case GrGLCaps::kDesktop_ARB_MSFBOType: |
(...skipping 1784 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2609 *internalFormat = GR_GL_RGBA; | 2590 *internalFormat = GR_GL_RGBA; |
2610 *externalFormat = GR_GL_RGBA; | 2591 *externalFormat = GR_GL_RGBA; |
2611 if (getSizedInternalFormat) { | 2592 if (getSizedInternalFormat) { |
2612 *internalFormat = GR_GL_RGBA4; | 2593 *internalFormat = GR_GL_RGBA4; |
2613 } else { | 2594 } else { |
2614 *internalFormat = GR_GL_RGBA; | 2595 *internalFormat = GR_GL_RGBA; |
2615 } | 2596 } |
2616 *externalType = GR_GL_UNSIGNED_SHORT_4_4_4_4; | 2597 *externalType = GR_GL_UNSIGNED_SHORT_4_4_4_4; |
2617 break; | 2598 break; |
2618 case kIndex_8_GrPixelConfig: | 2599 case kIndex_8_GrPixelConfig: |
2619 // glCompressedTexImage doesn't take external params | |
2620 *externalFormat = GR_GL_PALETTE8_RGBA8; | |
2621 // no sized/unsized internal format distinction here | 2600 // no sized/unsized internal format distinction here |
2622 *internalFormat = GR_GL_PALETTE8_RGBA8; | 2601 *internalFormat = GR_GL_PALETTE8_RGBA8; |
2623 // unused with CompressedTexImage | |
2624 *externalType = GR_GL_UNSIGNED_BYTE; | |
2625 break; | 2602 break; |
2626 case kAlpha_8_GrPixelConfig: | 2603 case kAlpha_8_GrPixelConfig: |
2627 if (this->glCaps().textureRedSupport()) { | 2604 if (this->glCaps().textureRedSupport()) { |
2628 *internalFormat = GR_GL_RED; | 2605 *internalFormat = GR_GL_RED; |
2629 *externalFormat = GR_GL_RED; | 2606 *externalFormat = GR_GL_RED; |
2630 if (getSizedInternalFormat) { | 2607 if (getSizedInternalFormat) { |
2631 *internalFormat = GR_GL_R8; | 2608 *internalFormat = GR_GL_R8; |
2632 } else { | 2609 } else { |
2633 *internalFormat = GR_GL_RED; | 2610 *internalFormat = GR_GL_RED; |
2634 } | 2611 } |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2743 } | 2720 } |
2744 const GrGLRenderTarget* srcRT = static_cast<const GrGLRenderTarget*>(src->as
RenderTarget()); | 2721 const GrGLRenderTarget* srcRT = static_cast<const GrGLRenderTarget*>(src->as
RenderTarget()); |
2745 // If the src is multisampled (and uses an extension where there is a separa
te MSAA | 2722 // If the src is multisampled (and uses an extension where there is a separa
te MSAA |
2746 // renderbuffer) then it is an invalid operation to call CopyTexSubImage | 2723 // renderbuffer) then it is an invalid operation to call CopyTexSubImage |
2747 if (NULL != srcRT && srcRT->renderFBOID() != srcRT->textureFBOID()) { | 2724 if (NULL != srcRT && srcRT->renderFBOID() != srcRT->textureFBOID()) { |
2748 return false; | 2725 return false; |
2749 } | 2726 } |
2750 if (gpu->glCaps().isConfigRenderable(src->config(), src->desc().fSampleCnt >
0) && | 2727 if (gpu->glCaps().isConfigRenderable(src->config(), src->desc().fSampleCnt >
0) && |
2751 NULL != dst->asTexture() && | 2728 NULL != dst->asTexture() && |
2752 dst->origin() == src->origin() && | 2729 dst->origin() == src->origin() && |
2753 kIndex_8_GrPixelConfig != src->config() && | |
2754 !GrPixelConfigIsCompressed(src->config())) { | 2730 !GrPixelConfigIsCompressed(src->config())) { |
2755 if (NULL != wouldNeedTempFBO) { | 2731 if (NULL != wouldNeedTempFBO) { |
2756 *wouldNeedTempFBO = NULL == src->asRenderTarget(); | 2732 *wouldNeedTempFBO = NULL == src->asRenderTarget(); |
2757 } | 2733 } |
2758 return true; | 2734 return true; |
2759 } else { | 2735 } else { |
2760 return false; | 2736 return false; |
2761 } | 2737 } |
2762 } | 2738 } |
2763 | 2739 |
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2995 this->setVertexArrayID(gpu, 0); | 2971 this->setVertexArrayID(gpu, 0); |
2996 } | 2972 } |
2997 int attrCount = gpu->glCaps().maxVertexAttributes(); | 2973 int attrCount = gpu->glCaps().maxVertexAttributes(); |
2998 if (fDefaultVertexArrayAttribState.count() != attrCount) { | 2974 if (fDefaultVertexArrayAttribState.count() != attrCount) { |
2999 fDefaultVertexArrayAttribState.resize(attrCount); | 2975 fDefaultVertexArrayAttribState.resize(attrCount); |
3000 } | 2976 } |
3001 attribState = &fDefaultVertexArrayAttribState; | 2977 attribState = &fDefaultVertexArrayAttribState; |
3002 } | 2978 } |
3003 return attribState; | 2979 return attribState; |
3004 } | 2980 } |
OLD | NEW |