| 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 "SkData.h" |
| 10 #include "SkImageGenerator.h" | 11 #include "SkImageGenerator.h" |
| 11 #include "SkImagePriv.h" | 12 #include "SkImagePriv.h" |
| 12 #include "SkImage_Base.h" | 13 #include "SkImage_Base.h" |
| 13 #include "SkReadPixelsRec.h" | 14 #include "SkReadPixelsRec.h" |
| 14 #include "SkString.h" | 15 #include "SkString.h" |
| 15 #include "SkSurface.h" | 16 #include "SkSurface.h" |
| 16 #if SK_SUPPORT_GPU | 17 #if SK_SUPPORT_GPU |
| 17 #include "GrTexture.h" | 18 #include "GrTexture.h" |
| 18 #include "GrContext.h" | 19 #include "GrContext.h" |
| 19 #endif | 20 #endif |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 57 } | 58 } |
| 58 | 59 |
| 59 SkData* SkImage::encode(SkImageEncoder::Type type, int quality) const { | 60 SkData* SkImage::encode(SkImageEncoder::Type type, int quality) const { |
| 60 SkBitmap bm; | 61 SkBitmap bm; |
| 61 if (as_IB(this)->getROPixels(&bm)) { | 62 if (as_IB(this)->getROPixels(&bm)) { |
| 62 return SkImageEncoder::EncodeData(bm, type, quality); | 63 return SkImageEncoder::EncodeData(bm, type, quality); |
| 63 } | 64 } |
| 64 return NULL; | 65 return NULL; |
| 65 } | 66 } |
| 66 | 67 |
| 67 SkImage* SkImage::NewFromData(SkData* data) { | 68 SkData* SkImage::refEncoded() const { |
| 68 if (NULL == data) { | 69 return as_IB(this)->onRefEncoded(); |
| 70 } |
| 71 |
| 72 SkImage* SkImage::NewFromEncoded(SkData* encoded, const SkIRect* subset) { |
| 73 if (NULL == encoded || 0 == encoded->size()) { |
| 69 return NULL; | 74 return NULL; |
| 70 } | 75 } |
| 71 SkImageGenerator* generator = SkImageGenerator::NewFromData(data); | 76 SkImageGenerator* generator = SkImageGenerator::NewFromData(encoded); |
| 72 return generator ? SkImage::NewFromGenerator(generator) : NULL; | 77 return generator ? SkImage::NewFromGenerator(generator, subset) : NULL; |
| 73 } | 78 } |
| 74 | 79 |
| 75 SkSurface* SkImage::newSurface(const SkImageInfo& info, const SkSurfaceProps* pr
ops) const { | 80 SkSurface* SkImage::newSurface(const SkImageInfo& info, const SkSurfaceProps* pr
ops) const { |
| 76 if (NULL == props) { | 81 if (NULL == props) { |
| 77 props = &as_IB(this)->props(); | 82 props = &as_IB(this)->props(); |
| 78 } | 83 } |
| 79 return as_IB(this)->onNewSurface(info, *props); | 84 return as_IB(this)->onNewSurface(info, *props); |
| 80 } | 85 } |
| 81 | 86 |
| 82 const char* SkImage::toString(SkString* str) const { | 87 const char* SkImage::toString(SkString* str) const { |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 194 surface->getCanvas()->scale(newWidth / src.width(), newHeight / src.height()
); | 199 surface->getCanvas()->scale(newWidth / src.width(), newHeight / src.height()
); |
| 195 surface->getCanvas()->translate(-src.x(), -src.y()); | 200 surface->getCanvas()->translate(-src.x(), -src.y()); |
| 196 | 201 |
| 197 SkPaint paint; | 202 SkPaint paint; |
| 198 paint.setXfermodeMode(SkXfermode::kSrc_Mode); | 203 paint.setXfermodeMode(SkXfermode::kSrc_Mode); |
| 199 paint.setFilterQuality(quality); | 204 paint.setFilterQuality(quality); |
| 200 surface->getCanvas()->drawImage(this, 0, 0, &paint); | 205 surface->getCanvas()->drawImage(this, 0, 0, &paint); |
| 201 return surface->newImageSnapshot(); | 206 return surface->newImageSnapshot(); |
| 202 } | 207 } |
| 203 | 208 |
| 204 ////////////////////////////////////////////////////////////////////////////////
////// | 209 ////////////////////////////////////////////////////////////////////////////////
/////////////////// |
| 210 |
| 211 bool SkImage::peekPixels(SkPixmap* pmap) const { |
| 212 SkImageInfo info; |
| 213 size_t rowBytes; |
| 214 const void* pixels = this->peekPixels(&info, &rowBytes); |
| 215 if (pixels) { |
| 216 if (pmap) { |
| 217 pmap->reset(info, pixels, rowBytes); |
| 218 } |
| 219 return true; |
| 220 } |
| 221 return false; |
| 222 } |
| 223 |
| 224 bool SkImage::readPixels(const SkPixmap& pmap, int srcX, int srcY) const { |
| 225 return this->readPixels(pmap.info(), pmap.writable_addr(), pmap.rowBytes(),
srcX, srcY); |
| 226 } |
| 227 |
| 228 ////////////////////////////////////////////////////////////////////////////////
/////////////////// |
| 205 | 229 |
| 206 #if !SK_SUPPORT_GPU | 230 #if !SK_SUPPORT_GPU |
| 207 | 231 |
| 208 SkImage* SkImage::NewFromTexture(GrContext*, const GrBackendTextureDesc&, SkAlph
aType, | 232 SkImage* SkImage::NewFromTexture(GrContext*, const GrBackendTextureDesc&, SkAlph
aType, |
| 209 TextureReleaseProc, ReleaseContext) { | 233 TextureReleaseProc, ReleaseContext) { |
| 210 return NULL; | 234 return NULL; |
| 211 } | 235 } |
| 212 | 236 |
| 213 SkImage* SkImage::NewFromAdoptedTexture(GrContext*, const GrBackendTextureDesc&,
SkAlphaType) { | 237 SkImage* SkImage::NewFromAdoptedTexture(GrContext*, const GrBackendTextureDesc&,
SkAlphaType) { |
| 214 return NULL; | 238 return NULL; |
| 215 } | 239 } |
| 216 | 240 |
| 217 SkImage* SkImage::NewFromTextureCopy(GrContext*, const GrBackendTextureDesc&, Sk
AlphaType) { | 241 SkImage* SkImage::NewFromTextureCopy(GrContext*, const GrBackendTextureDesc&, Sk
AlphaType) { |
| 218 return NULL; | 242 return NULL; |
| 219 } | 243 } |
| 220 | 244 |
| 221 #endif | 245 #endif |
| OLD | NEW |