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 "SkImage_Base.h" | 8 #include "SkImage_Base.h" |
9 #include "SkBitmap.h" | 9 #include "SkBitmap.h" |
10 #include "SkCanvas.h" | 10 #include "SkCanvas.h" |
(...skipping 23 matching lines...) Expand all Loading... |
34 SkAutoTDelete<SkImageCacherator> fCache; | 34 SkAutoTDelete<SkImageCacherator> fCache; |
35 | 35 |
36 typedef SkImage_Base INHERITED; | 36 typedef SkImage_Base INHERITED; |
37 }; | 37 }; |
38 | 38 |
39 /////////////////////////////////////////////////////////////////////////////// | 39 /////////////////////////////////////////////////////////////////////////////// |
40 | 40 |
41 bool SkImage_Generator::onReadPixels(const SkImageInfo& dstInfo, void* dstPixels
, size_t dstRB, | 41 bool SkImage_Generator::onReadPixels(const SkImageInfo& dstInfo, void* dstPixels
, size_t dstRB, |
42 int srcX, int srcY, CachingHint chint) cons
t { | 42 int srcX, int srcY, CachingHint chint) cons
t { |
43 SkBitmap bm; | 43 SkBitmap bm; |
| 44 if (kDisallow_CachingHint == chint) { |
| 45 if (fCache->lockAsBitmapOnlyIfAlreadyCached(&bm)) { |
| 46 return bm.readPixels(dstInfo, dstPixels, dstRB, srcX, srcY); |
| 47 } else { |
| 48 // Try passing the caller's buffer directly down to the generator. I
f this fails we |
| 49 // may still succeed in the general case, as the generator may prefe
r some other |
| 50 // config, which we could then convert via SkBitmap::readPixels. |
| 51 if (fCache->directGeneratePixels(dstInfo, dstPixels, dstRB, srcX, sr
cY)) { |
| 52 return true; |
| 53 } |
| 54 // else fall through |
| 55 } |
| 56 } |
| 57 |
44 if (this->getROPixels(&bm, chint)) { | 58 if (this->getROPixels(&bm, chint)) { |
45 return bm.readPixels(dstInfo, dstPixels, dstRB, srcX, srcY); | 59 return bm.readPixels(dstInfo, dstPixels, dstRB, srcX, srcY); |
46 } | 60 } |
47 return false; | 61 return false; |
48 } | 62 } |
49 | 63 |
50 const void* SkImage_Generator::onPeekPixels(SkImageInfo* infoPtr, size_t* rowByt
esPtr) const { | 64 const void* SkImage_Generator::onPeekPixels(SkImageInfo* infoPtr, size_t* rowByt
esPtr) const { |
51 return NULL; | 65 return NULL; |
52 } | 66 } |
53 | 67 |
(...skipping 25 matching lines...) Expand all Loading... |
79 return surface->newImageSnapshot(); | 93 return surface->newImageSnapshot(); |
80 } | 94 } |
81 | 95 |
82 SkImage* SkImage::NewFromGenerator(SkImageGenerator* generator, const SkIRect* s
ubset) { | 96 SkImage* SkImage::NewFromGenerator(SkImageGenerator* generator, const SkIRect* s
ubset) { |
83 SkImageCacherator* cache = SkImageCacherator::NewFromGenerator(generator, su
bset); | 97 SkImageCacherator* cache = SkImageCacherator::NewFromGenerator(generator, su
bset); |
84 if (!cache) { | 98 if (!cache) { |
85 return nullptr; | 99 return nullptr; |
86 } | 100 } |
87 return new SkImage_Generator(cache); | 101 return new SkImage_Generator(cache); |
88 } | 102 } |
OLD | NEW |