| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2012 Google Inc. | 2 * Copyright 2012 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 "SkCanvas.h" | 9 #include "SkCanvas.h" |
| 10 #include "SkImagePriv.h" | 10 #include "SkImagePriv.h" |
| 11 #include "SkImage_Base.h" | 11 #include "SkImage_Base.h" |
| 12 | 12 #include "SkSurface.h" |
| 13 static SkImage_Base* as_IB(SkImage* image) { | |
| 14 return static_cast<SkImage_Base*>(image); | |
| 15 } | |
| 16 | |
| 17 static const SkImage_Base* as_IB(const SkImage* image) { | |
| 18 return static_cast<const SkImage_Base*>(image); | |
| 19 } | |
| 20 | 13 |
| 21 uint32_t SkImage::NextUniqueID() { | 14 uint32_t SkImage::NextUniqueID() { |
| 22 static int32_t gUniqueID; | 15 static int32_t gUniqueID; |
| 23 | 16 |
| 24 // never return 0; | 17 // never return 0; |
| 25 uint32_t id; | 18 uint32_t id; |
| 26 do { | 19 do { |
| 27 id = sk_atomic_inc(&gUniqueID) + 1; | 20 id = sk_atomic_inc(&gUniqueID) + 1; |
| 28 } while (0 == id); | 21 } while (0 == id); |
| 29 return id; | 22 return id; |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 84 } | 77 } |
| 85 | 78 |
| 86 SkData* SkImage::encode(SkImageEncoder::Type type, int quality) const { | 79 SkData* SkImage::encode(SkImageEncoder::Type type, int quality) const { |
| 87 SkBitmap bm; | 80 SkBitmap bm; |
| 88 if (as_IB(this)->getROPixels(&bm)) { | 81 if (as_IB(this)->getROPixels(&bm)) { |
| 89 return SkImageEncoder::EncodeData(bm, type, quality); | 82 return SkImageEncoder::EncodeData(bm, type, quality); |
| 90 } | 83 } |
| 91 return NULL; | 84 return NULL; |
| 92 } | 85 } |
| 93 | 86 |
| 87 SkSurface* SkImage::newSurface(const SkImageInfo& info, const SkSurfaceProps* pr
ops) const { |
| 88 if (NULL == props) { |
| 89 props = &as_IB(this)->props(); |
| 90 } |
| 91 return as_IB(this)->onNewSurface(info, *props); |
| 92 } |
| 93 |
| 94 /////////////////////////////////////////////////////////////////////////////// | 94 /////////////////////////////////////////////////////////////////////////////// |
| 95 | 95 |
| 96 static bool raster_canvas_supports(const SkImageInfo& info) { | 96 static bool raster_canvas_supports(const SkImageInfo& info) { |
| 97 switch (info.colorType()) { | 97 switch (info.colorType()) { |
| 98 case kN32_SkColorType: | 98 case kN32_SkColorType: |
| 99 return kUnpremul_SkAlphaType != info.alphaType(); | 99 return kUnpremul_SkAlphaType != info.alphaType(); |
| 100 case kRGB_565_SkColorType: | 100 case kRGB_565_SkColorType: |
| 101 return true; | 101 return true; |
| 102 case kAlpha_8_SkColorType: | 102 case kAlpha_8_SkColorType: |
| 103 return true; | 103 return true; |
| (...skipping 27 matching lines...) Expand all Loading... |
| 131 | 131 |
| 132 SkCanvas canvas(*bitmap); | 132 SkCanvas canvas(*bitmap); |
| 133 | 133 |
| 134 SkPaint paint; | 134 SkPaint paint; |
| 135 paint.setXfermodeMode(SkXfermode::kClear_Mode); | 135 paint.setXfermodeMode(SkXfermode::kClear_Mode); |
| 136 canvas.drawRect(dstR, paint); | 136 canvas.drawRect(dstR, paint); |
| 137 | 137 |
| 138 canvas.drawImageRect(this, &srcR, dstR); | 138 canvas.drawImageRect(this, &srcR, dstR); |
| 139 return true; | 139 return true; |
| 140 } | 140 } |
| OLD | NEW |