OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2015 Google Inc. | 2 * Copyright 2015 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 "SkBitmap.h" | 8 #include "SkBitmap.h" |
9 #include "SkBitmapCache.h" | 9 #include "SkBitmapCache.h" |
10 #include "SkImage_Base.h" | 10 #include "SkImage_Base.h" |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
101 return false; | 101 return false; |
102 } | 102 } |
103 if (!bitmap->tryAllocPixels(fInfo, nullptr, full.getColorTable())) { | 103 if (!bitmap->tryAllocPixels(fInfo, nullptr, full.getColorTable())) { |
104 return false; | 104 return false; |
105 } | 105 } |
106 return full.readPixels(bitmap->info(), bitmap->getPixels(), bitmap->rowB
ytes(), | 106 return full.readPixels(bitmap->info(), bitmap->getPixels(), bitmap->rowB
ytes(), |
107 fOrigin.x(), fOrigin.y()); | 107 fOrigin.x(), fOrigin.y()); |
108 } | 108 } |
109 } | 109 } |
110 | 110 |
| 111 bool SkImageCacherator::directGeneratePixels(const SkImageInfo& info, void* pixe
ls, size_t rb, |
| 112 int srcX, int srcY) { |
| 113 ScopedGenerator generator(this); |
| 114 const SkImageInfo& genInfo = generator->getInfo(); |
| 115 // Currently generators do not natively handle subsets, so check that first. |
| 116 if (srcX || srcY || genInfo.width() != info.width() || genInfo.height() != i
nfo.height()) { |
| 117 return false; |
| 118 } |
| 119 return generator->getPixels(info, pixels, rb); |
| 120 } |
| 121 |
111 ////////////////////////////////////////////////////////////////////////////////
////////////////// | 122 ////////////////////////////////////////////////////////////////////////////////
////////////////// |
112 | 123 |
| 124 bool SkImageCacherator::lockAsBitmapOnlyIfAlreadyCached(SkBitmap* bitmap) { |
| 125 return SkBitmapCache::Find(fUniqueID, bitmap) && check_output_bitmap(*bitmap
, fUniqueID); |
| 126 } |
| 127 |
113 bool SkImageCacherator::tryLockAsBitmap(SkBitmap* bitmap, const SkImage* client, | 128 bool SkImageCacherator::tryLockAsBitmap(SkBitmap* bitmap, const SkImage* client, |
114 SkImage::CachingHint chint) { | 129 SkImage::CachingHint chint) { |
115 if (SkBitmapCache::Find(fUniqueID, bitmap)) { | 130 if (this->lockAsBitmapOnlyIfAlreadyCached(bitmap)) { |
116 return check_output_bitmap(*bitmap, fUniqueID); | 131 return true; |
117 } | 132 } |
118 | |
119 if (!this->generateBitmap(bitmap)) { | 133 if (!this->generateBitmap(bitmap)) { |
120 return false; | 134 return false; |
121 } | 135 } |
122 | 136 |
123 bitmap->pixelRef()->setImmutableWithID(fUniqueID); | 137 bitmap->pixelRef()->setImmutableWithID(fUniqueID); |
124 if (SkImage::kAllow_CachingHint == chint) { | 138 if (SkImage::kAllow_CachingHint == chint) { |
125 SkBitmapCache::Add(fUniqueID, *bitmap); | 139 SkBitmapCache::Add(fUniqueID, *bitmap); |
126 if (client) { | 140 if (client) { |
127 as_IB(client)->notifyAddedToCache(); | 141 as_IB(client)->notifyAddedToCache(); |
128 } | 142 } |
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
332 } | 346 } |
333 | 347 |
334 #else | 348 #else |
335 | 349 |
336 GrTexture* SkImageCacherator::lockAsTexture(GrContext* ctx, const GrTextureParam
s&, | 350 GrTexture* SkImageCacherator::lockAsTexture(GrContext* ctx, const GrTextureParam
s&, |
337 const SkImage* client, SkImage::Cach
ingHint) { | 351 const SkImage* client, SkImage::Cach
ingHint) { |
338 return nullptr; | 352 return nullptr; |
339 } | 353 } |
340 | 354 |
341 #endif | 355 #endif |
OLD | NEW |