| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2010 Google Inc. | 2 * Copyright 2010 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 "SkGr.h" | 8 #include "SkGr.h" |
| 9 | 9 |
| 10 #include "GrCaps.h" | 10 #include "GrCaps.h" |
| (...skipping 628 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 639 if (result) { | 639 if (result) { |
| 640 return result; | 640 return result; |
| 641 } | 641 } |
| 642 | 642 |
| 643 SkErrorInternals::SetError( kInternalError_SkError, | 643 SkErrorInternals::SetError( kInternalError_SkError, |
| 644 "---- failed to create texture for cache [%d %d]
\n", | 644 "---- failed to create texture for cache [%d %d]
\n", |
| 645 bitmap.width(), bitmap.height()); | 645 bitmap.width(), bitmap.height()); |
| 646 | 646 |
| 647 return NULL; | 647 return NULL; |
| 648 } | 648 } |
| 649 |
| 650 GrTexture* GrMipmapTexture(GrContext* ctx, |
| 651 const SkBitmap& bitmap, |
| 652 SkDiscardableFactoryProc fact, |
| 653 const GrTextureParams* params) { |
| 654 GrTexture* result = bitmap.getTexture(); |
| 655 // TODO: What if the bitmap already contains a non-mipmapped texture? |
| 656 if (result) { |
| 657 // TODO: Add stretching. After reading get_stretch(), it appears small |
| 658 // textures can have issues. |
| 659 return SkRef(result); |
| 660 } |
| 661 |
| 662 GrSurfaceDesc desc; |
| 663 generate_bitmap_texture_desc(bitmap, &desc); |
| 664 |
| 665 auto mipmap = SkMipMap::Build(bitmap, fact); |
| 666 if (mipmap == NULL) { |
| 667 // could not create the mipmap |
| 668 return NULL; |
| 669 } else { |
| 670 return ctx->textureProvider()->createMipmappedTexture(desc, true, *mipma
p); |
| 671 // TODO: BitmapInvalidator support |
| 672 } |
| 673 } |
| 674 |
| 649 /////////////////////////////////////////////////////////////////////////////// | 675 /////////////////////////////////////////////////////////////////////////////// |
| 650 | 676 |
| 651 // alphatype is ignore for now, but if GrPixelConfig is expanded to encompass | 677 // alphatype is ignore for now, but if GrPixelConfig is expanded to encompass |
| 652 // alpha info, that will be considered. | 678 // alpha info, that will be considered. |
| 653 GrPixelConfig SkImageInfo2GrPixelConfig(SkColorType ct, SkAlphaType, SkColorProf
ileType pt) { | 679 GrPixelConfig SkImageInfo2GrPixelConfig(SkColorType ct, SkAlphaType, SkColorProf
ileType pt) { |
| 654 switch (ct) { | 680 switch (ct) { |
| 655 case kUnknown_SkColorType: | 681 case kUnknown_SkColorType: |
| 656 return kUnknown_GrPixelConfig; | 682 return kUnknown_GrPixelConfig; |
| 657 case kAlpha_8_SkColorType: | 683 case kAlpha_8_SkColorType: |
| 658 return kAlpha_8_GrPixelConfig; | 684 return kAlpha_8_GrPixelConfig; |
| (...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 826 } | 852 } |
| 827 return SkImageInfo::Make(w, h, ct, at); | 853 return SkImageInfo::Make(w, h, ct, at); |
| 828 } | 854 } |
| 829 | 855 |
| 830 | 856 |
| 831 void GrWrapTextureInBitmap(GrTexture* src, int w, int h, bool isOpaque, SkBitmap
* dst) { | 857 void GrWrapTextureInBitmap(GrTexture* src, int w, int h, bool isOpaque, SkBitmap
* dst) { |
| 832 const SkImageInfo info = GrMakeInfoFromTexture(src, w, h, isOpaque); | 858 const SkImageInfo info = GrMakeInfoFromTexture(src, w, h, isOpaque); |
| 833 dst->setInfo(info); | 859 dst->setInfo(info); |
| 834 dst->setPixelRef(SkNEW_ARGS(SkGrPixelRef, (info, src)))->unref(); | 860 dst->setPixelRef(SkNEW_ARGS(SkGrPixelRef, (info, src)))->unref(); |
| 835 } | 861 } |
| OLD | NEW |