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 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
136 stretch->fType = Stretch::kNone_Type; | 136 stretch->fType = Stretch::kNone_Type; |
137 } | 137 } |
138 } | 138 } |
139 | 139 |
140 static bool make_stretched_key(const GrUniqueKey& origKey, const Stretch& stretc
h, | 140 static bool make_stretched_key(const GrUniqueKey& origKey, const Stretch& stretc
h, |
141 GrUniqueKey* stretchedKey) { | 141 GrUniqueKey* stretchedKey) { |
142 if (origKey.isValid() && Stretch::kNone_Type != stretch.fType) { | 142 if (origKey.isValid() && Stretch::kNone_Type != stretch.fType) { |
143 uint32_t width = SkToU16(stretch.fWidth); | 143 uint32_t width = SkToU16(stretch.fWidth); |
144 uint32_t height = SkToU16(stretch.fHeight); | 144 uint32_t height = SkToU16(stretch.fHeight); |
145 static const GrUniqueKey::Domain kDomain = GrUniqueKey::GenerateDomain()
; | 145 static const GrUniqueKey::Domain kDomain = GrUniqueKey::GenerateDomain()
; |
146 GrUniqueKey::Builder builder(stretchedKey, origKey, kDomain, 3); | 146 GrUniqueKey::Builder builder(stretchedKey, origKey, kDomain, 2); |
147 builder[0] = stretch.fType; | 147 builder[0] = stretch.fType; |
148 builder[1] = width | (height << 16); | 148 builder[1] = width | (height << 16); |
149 builder.finish(); | 149 builder.finish(); |
150 return true; | 150 return true; |
151 } | 151 } |
152 SkASSERT(!stretchedKey->isValid()); | 152 SkASSERT(!stretchedKey->isValid()); |
153 return false; | 153 return false; |
154 } | 154 } |
155 | 155 |
156 static void make_unstretched_key(const SkBitmap& bitmap, GrUniqueKey* key) { | 156 static void make_unstretched_key(GrUniqueKey* key, uint32_t imageID, |
157 // Our id includes the offset, width, and height so that bitmaps created by
extractSubset() | 157 U16CPU width, U16CPU height, SkIPoint origin) { |
158 // are unique. | 158 SkASSERT((uint16_t)width == width); |
159 uint32_t genID = bitmap.getGenerationID(); | 159 SkASSERT((uint16_t)height == height); |
160 SkIPoint origin = bitmap.pixelRefOrigin(); | |
161 uint32_t width = SkToU16(bitmap.width()); | |
162 uint32_t height = SkToU16(bitmap.height()); | |
163 | 160 |
164 static const GrUniqueKey::Domain kDomain = GrUniqueKey::GenerateDomain(); | 161 static const GrUniqueKey::Domain kDomain = GrUniqueKey::GenerateDomain(); |
165 GrUniqueKey::Builder builder(key, kDomain, 4); | 162 GrUniqueKey::Builder builder(key, kDomain, 4); |
166 builder[0] = genID; | 163 builder[0] = imageID; |
167 builder[1] = origin.fX; | 164 builder[1] = origin.fX; |
168 builder[2] = origin.fY; | 165 builder[2] = origin.fY; |
169 builder[3] = width | (height << 16); | 166 builder[3] = width | (height << 16); |
170 } | 167 } |
171 | 168 |
| 169 void GrMakeKeyFromImageID(GrUniqueKey* key, uint32_t imageID, |
| 170 U16CPU width, U16CPU height, SkIPoint origin, |
| 171 const GrCaps& caps, SkImageUsageType usage) { |
| 172 const Stretch::Type stretches[] = { |
| 173 Stretch::kNone_Type, // kUntiled_SkImageUsageType |
| 174 Stretch::kNearest_Type, // kTiled_Unfiltered_SkImageUsageType |
| 175 Stretch::kBilerp_Type, // kTiled_Filtered_SkImageUsageType |
| 176 }; |
| 177 |
| 178 const bool isPow2 = SkIsPow2(width) && SkIsPow2(height); |
| 179 const bool needToStretch = !isPow2 && |
| 180 usage != kUntiled_SkImageUsageType && |
| 181 !caps.npotTextureTileSupport(); |
| 182 |
| 183 if (needToStretch) { |
| 184 GrUniqueKey tmpKey; |
| 185 make_unstretched_key(&tmpKey, imageID, width, height, origin); |
| 186 |
| 187 Stretch stretch; |
| 188 stretch.fType = stretches[usage]; |
| 189 stretch.fWidth = SkNextPow2(width); |
| 190 stretch.fHeight = SkNextPow2(height); |
| 191 if (!make_stretched_key(tmpKey, stretch, key)) { |
| 192 goto UNSTRETCHED; |
| 193 } |
| 194 } else { |
| 195 UNSTRETCHED: |
| 196 make_unstretched_key(key, imageID, width, height, origin); |
| 197 } |
| 198 } |
| 199 |
| 200 static void make_unstretched_key(const SkBitmap& bitmap, GrUniqueKey* key) { |
| 201 make_unstretched_key(key, bitmap.getGenerationID(), bitmap.width(), bitmap.h
eight(), |
| 202 bitmap.pixelRefOrigin()); |
| 203 } |
| 204 |
172 static void make_bitmap_keys(const SkBitmap& bitmap, | 205 static void make_bitmap_keys(const SkBitmap& bitmap, |
173 const Stretch& stretch, | 206 const Stretch& stretch, |
174 GrUniqueKey* key, | 207 GrUniqueKey* key, |
175 GrUniqueKey* stretchedKey) { | 208 GrUniqueKey* stretchedKey) { |
176 make_unstretched_key(bitmap, key); | 209 make_unstretched_key(bitmap, key); |
177 if (Stretch::kNone_Type != stretch.fType) { | 210 if (Stretch::kNone_Type != stretch.fType) { |
178 make_stretched_key(*key, stretch, stretchedKey); | 211 make_stretched_key(*key, stretch, stretchedKey); |
179 } | 212 } |
180 } | 213 } |
181 | 214 |
(...skipping 460 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
642 if (result) { | 675 if (result) { |
643 return result; | 676 return result; |
644 } | 677 } |
645 | 678 |
646 SkErrorInternals::SetError( kInternalError_SkError, | 679 SkErrorInternals::SetError( kInternalError_SkError, |
647 "---- failed to create texture for cache [%d %d]
\n", | 680 "---- failed to create texture for cache [%d %d]
\n", |
648 bitmap.width(), bitmap.height()); | 681 bitmap.width(), bitmap.height()); |
649 | 682 |
650 return NULL; | 683 return NULL; |
651 } | 684 } |
| 685 |
| 686 // TODO: make this be the canonical signature, and turn the version that takes G
rTextureParams* |
| 687 // into a wrapper that contains the inverse of these tables. |
| 688 GrTexture* GrRefCachedBitmapTexture(GrContext* ctx, |
| 689 const SkBitmap& bitmap, |
| 690 SkImageUsageType usage) { |
| 691 // Just need a params that will trigger the correct cache key / etc, since t
he usage doesn't |
| 692 // tell us the specifics about filter level or specific tiling. |
| 693 |
| 694 const SkShader::TileMode tiles[] = { |
| 695 SkShader::kClamp_TileMode, // kUntiled_SkImageUsageType |
| 696 SkShader::kRepeat_TileMode, // kTiled_Unfiltered_SkImageUsageType |
| 697 SkShader::kRepeat_TileMode, // kTiled_Filtered_SkImageUsageType |
| 698 }; |
| 699 |
| 700 const GrTextureParams::FilterMode filters[] = { |
| 701 GrTextureParams::kNone_FilterMode, // kUntiled_SkImageUsageType |
| 702 GrTextureParams::kNone_FilterMode, // kTiled_Unfiltered_SkImageUsag
eType |
| 703 GrTextureParams::kBilerp_FilterMode, // kTiled_Filtered_SkImageUsageT
ype |
| 704 }; |
| 705 |
| 706 GrTextureParams params(tiles[usage], filters[usage]); |
| 707 return GrRefCachedBitmapTexture(ctx, bitmap, ¶ms); |
| 708 } |
| 709 |
652 /////////////////////////////////////////////////////////////////////////////// | 710 /////////////////////////////////////////////////////////////////////////////// |
653 | 711 |
654 // alphatype is ignore for now, but if GrPixelConfig is expanded to encompass | 712 // alphatype is ignore for now, but if GrPixelConfig is expanded to encompass |
655 // alpha info, that will be considered. | 713 // alpha info, that will be considered. |
656 GrPixelConfig SkImageInfo2GrPixelConfig(SkColorType ct, SkAlphaType, SkColorProf
ileType pt) { | 714 GrPixelConfig SkImageInfo2GrPixelConfig(SkColorType ct, SkAlphaType, SkColorProf
ileType pt) { |
657 switch (ct) { | 715 switch (ct) { |
658 case kUnknown_SkColorType: | 716 case kUnknown_SkColorType: |
659 return kUnknown_GrPixelConfig; | 717 return kUnknown_GrPixelConfig; |
660 case kAlpha_8_SkColorType: | 718 case kAlpha_8_SkColorType: |
661 return kAlpha_8_GrPixelConfig; | 719 return kAlpha_8_GrPixelConfig; |
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
871 SkErrorInternals::SetError( kInvalidPaint_SkError, | 929 SkErrorInternals::SetError( kInvalidPaint_SkError, |
872 "Sorry, I don't understand the filtering
" | 930 "Sorry, I don't understand the filtering
" |
873 "mode you asked for. Falling back to " | 931 "mode you asked for. Falling back to " |
874 "MIPMaps."); | 932 "MIPMaps."); |
875 textureFilterMode = GrTextureParams::kMipMap_FilterMode; | 933 textureFilterMode = GrTextureParams::kMipMap_FilterMode; |
876 break; | 934 break; |
877 | 935 |
878 } | 936 } |
879 return textureFilterMode; | 937 return textureFilterMode; |
880 } | 938 } |
OLD | NEW |