| 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 #include "SkConfig8888.h" | 9 #include "SkConfig8888.h" |
| 10 #include "SkMessageBus.h" | 10 #include "SkMessageBus.h" |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 90 memset(key.fData8 + kKeyDataSize, 0, sizeof(key) - kKeyDataSize); | 90 memset(key.fData8 + kKeyDataSize, 0, sizeof(key) - kKeyDataSize); |
| 91 GR_STATIC_ASSERT(sizeof(key) >= kKeyDataSize); | 91 GR_STATIC_ASSERT(sizeof(key) >= kKeyDataSize); |
| 92 static const GrCacheID::Domain gBitmapTextureDomain = GrCacheID::GenerateDom
ain(); | 92 static const GrCacheID::Domain gBitmapTextureDomain = GrCacheID::GenerateDom
ain(); |
| 93 id->reset(gBitmapTextureDomain, key); | 93 id->reset(gBitmapTextureDomain, key); |
| 94 } | 94 } |
| 95 | 95 |
| 96 static void generate_bitmap_texture_desc(const SkBitmap& bitmap, GrTextureDesc*
desc) { | 96 static void generate_bitmap_texture_desc(const SkBitmap& bitmap, GrTextureDesc*
desc) { |
| 97 desc->fFlags = kNone_GrTextureFlags; | 97 desc->fFlags = kNone_GrTextureFlags; |
| 98 desc->fWidth = bitmap.width(); | 98 desc->fWidth = bitmap.width(); |
| 99 desc->fHeight = bitmap.height(); | 99 desc->fHeight = bitmap.height(); |
| 100 desc->fConfig = SkBitmapConfig2GrPixelConfig(bitmap.config()); | 100 desc->fConfig = SkImageInfo2GrPixelConfig(bitmap.info()); |
| 101 desc->fSampleCnt = 0; | 101 desc->fSampleCnt = 0; |
| 102 } | 102 } |
| 103 | 103 |
| 104 namespace { | 104 namespace { |
| 105 | 105 |
| 106 // When the SkPixelRef genID changes, invalidate a corresponding GrResource desc
ribed by key. | 106 // When the SkPixelRef genID changes, invalidate a corresponding GrResource desc
ribed by key. |
| 107 class GrResourceInvalidator : public SkPixelRef::GenIDChangeListener { | 107 class GrResourceInvalidator : public SkPixelRef::GenIDChangeListener { |
| 108 public: | 108 public: |
| 109 explicit GrResourceInvalidator(GrResourceKey key) : fKey(key) {} | 109 explicit GrResourceInvalidator(GrResourceKey key) : fKey(key) {} |
| 110 private: | 110 private: |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 162 GrContext::kExact_Sc
ratchTexMatch); | 162 GrContext::kExact_Sc
ratchTexMatch); |
| 163 result->writePixels(0, 0, bitmap->width(), | 163 result->writePixels(0, 0, bitmap->width(), |
| 164 bitmap->height(), desc.fConfig, | 164 bitmap->height(), desc.fConfig, |
| 165 storage.get()); | 165 storage.get()); |
| 166 return result; | 166 return result; |
| 167 } | 167 } |
| 168 } else { | 168 } else { |
| 169 origBitmap.copyTo(&tmpBitmap, kN32_SkColorType); | 169 origBitmap.copyTo(&tmpBitmap, kN32_SkColorType); |
| 170 // now bitmap points to our temp, which has been promoted to 32bits | 170 // now bitmap points to our temp, which has been promoted to 32bits |
| 171 bitmap = &tmpBitmap; | 171 bitmap = &tmpBitmap; |
| 172 desc.fConfig = SkBitmapConfig2GrPixelConfig(bitmap->config()); | 172 desc.fConfig = SkImageInfo2GrPixelConfig(bitmap->info()); |
| 173 } | 173 } |
| 174 } | 174 } |
| 175 | 175 |
| 176 SkAutoLockPixels alp(*bitmap); | 176 SkAutoLockPixels alp(*bitmap); |
| 177 if (!bitmap->readyToDraw()) { | 177 if (!bitmap->readyToDraw()) { |
| 178 return NULL; | 178 return NULL; |
| 179 } | 179 } |
| 180 if (cache) { | 180 if (cache) { |
| 181 // This texture is likely to be used again so leave it in the cache | 181 // This texture is likely to be used again so leave it in the cache |
| 182 GrCacheID cacheID; | 182 GrCacheID cacheID; |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 316 ct = kBGRA_8888_SkColorType; | 316 ct = kBGRA_8888_SkColorType; |
| 317 break; | 317 break; |
| 318 default: | 318 default: |
| 319 return false; | 319 return false; |
| 320 } | 320 } |
| 321 if (ctOut) { | 321 if (ctOut) { |
| 322 *ctOut = ct; | 322 *ctOut = ct; |
| 323 } | 323 } |
| 324 return true; | 324 return true; |
| 325 } | 325 } |
| OLD | NEW |