OLD | NEW |
(Empty) | |
| 1 /* |
| 2 * Copyright 2015 Google Inc. |
| 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. |
| 6 */ |
| 7 |
| 8 #include "SkBitmapProvider.h" |
| 9 #include "SkImage_Base.h" |
| 10 #include "SkPixelRef.h" |
| 11 |
| 12 int SkBitmapProvider::width() const { |
| 13 return fImage ? fImage->width() : fBitmap.width(); |
| 14 } |
| 15 |
| 16 int SkBitmapProvider::height() const { |
| 17 return fImage ? fImage->height() : fBitmap.height(); |
| 18 } |
| 19 |
| 20 uint32_t SkBitmapProvider::getID() const { |
| 21 return fImage ? fImage->uniqueID() : fBitmap.getGenerationID(); |
| 22 } |
| 23 |
| 24 bool SkBitmapProvider::validForDrawing() const { |
| 25 if (!fImage) { |
| 26 if (0 == fBitmap.width() || 0 == fBitmap.height()) { |
| 27 return false; |
| 28 } |
| 29 if (nullptr == fBitmap.pixelRef()) { |
| 30 return false; // no pixels to read |
| 31 } |
| 32 if (fBitmap.getTexture()) { |
| 33 // we can handle texture (ugh) since lockPixels will perform a read-
back |
| 34 return true; |
| 35 } |
| 36 if (kIndex_8_SkColorType == fBitmap.colorType()) { |
| 37 SkAutoLockPixels alp(fBitmap); // but we need to call it before getC
olorTable() is safe. |
| 38 if (!fBitmap.getColorTable()) { |
| 39 return false; |
| 40 } |
| 41 } |
| 42 } |
| 43 return true; |
| 44 } |
| 45 |
| 46 SkImageInfo SkBitmapProvider::info() const { |
| 47 if (fImage) { |
| 48 SkAlphaType at = fImage->isOpaque() ? kOpaque_SkAlphaType : kPremul_SkAl
phaType; |
| 49 return SkImageInfo::MakeN32(fImage->width(), fImage->height(), at); |
| 50 } else { |
| 51 return fBitmap.info(); |
| 52 } |
| 53 } |
| 54 |
| 55 SkBitmapCacheDesc SkBitmapProvider::makeCacheDesc(int w, int h) const { |
| 56 return fImage ? SkBitmapCacheDesc::Make(fImage, w, h) : SkBitmapCacheDesc::M
ake(fBitmap, w, h); |
| 57 } |
| 58 |
| 59 SkBitmapCacheDesc SkBitmapProvider::makeCacheDesc() const { |
| 60 return fImage ? SkBitmapCacheDesc::Make(fImage) : SkBitmapCacheDesc::Make(fB
itmap); |
| 61 } |
| 62 |
| 63 void SkBitmapProvider::notifyAddedToCache() const { |
| 64 if (fImage) { |
| 65 // TODO |
| 66 } else { |
| 67 fBitmap.pixelRef()->notifyAddedToCache(); |
| 68 } |
| 69 } |
| 70 |
| 71 bool SkBitmapProvider::asBitmap(SkBitmap* bm) const { |
| 72 if (fImage) { |
| 73 return as_IB(fImage)->getROPixels(bm); |
| 74 } else { |
| 75 *bm = fBitmap; |
| 76 return true; |
| 77 } |
| 78 } |
| 79 |
OLD | NEW |