| 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 "SkBitmapCache.h" | 9 #include "SkBitmapCache.h" |
| 10 #include "SkCanvas.h" | 10 #include "SkCanvas.h" |
| (...skipping 30 matching lines...) Expand all Loading... |
| 41 if (nullptr == info) { | 41 if (nullptr == info) { |
| 42 info = &infoStorage; | 42 info = &infoStorage; |
| 43 } | 43 } |
| 44 if (nullptr == rowBytes) { | 44 if (nullptr == rowBytes) { |
| 45 rowBytes = &rowBytesStorage; | 45 rowBytes = &rowBytesStorage; |
| 46 } | 46 } |
| 47 return as_IB(this)->onPeekPixels(info, rowBytes); | 47 return as_IB(this)->onPeekPixels(info, rowBytes); |
| 48 } | 48 } |
| 49 | 49 |
| 50 bool SkImage::readPixels(const SkImageInfo& dstInfo, void* dstPixels, size_t dst
RowBytes, | 50 bool SkImage::readPixels(const SkImageInfo& dstInfo, void* dstPixels, size_t dst
RowBytes, |
| 51 int srcX, int srcY) const { | 51 int srcX, int srcY, CachingHint chint) const { |
| 52 SkReadPixelsRec rec(dstInfo, dstPixels, dstRowBytes, srcX, srcY); | 52 SkReadPixelsRec rec(dstInfo, dstPixels, dstRowBytes, srcX, srcY); |
| 53 if (!rec.trim(this->width(), this->height())) { | 53 if (!rec.trim(this->width(), this->height())) { |
| 54 return false; | 54 return false; |
| 55 } | 55 } |
| 56 return as_IB(this)->onReadPixels(rec.fInfo, rec.fPixels, rec.fRowBytes, rec.
fX, rec.fY); | 56 return as_IB(this)->onReadPixels(rec.fInfo, rec.fPixels, rec.fRowBytes, rec.
fX, rec.fY, chint); |
| 57 } |
| 58 |
| 59 bool SkImage::scalePixels(const SkPixmap& dst, SkFilterQuality quality, CachingH
int chint) const { |
| 60 // Idea: If/when SkImageGenerator supports a native-scaling API (where the g
enerator itself |
| 61 // can scale more efficiently) we should take advantage of it here. |
| 62 // |
| 63 SkBitmap bm; |
| 64 if (as_IB(this)->getROPixels(&bm, chint)) { |
| 65 bm.lockPixels(); |
| 66 SkPixmap pmap; |
| 67 // Note: By calling the pixmap scaler, we never cache the final result,
so the chint |
| 68 // is (currently) only being applied to the getROPixels. If we get
a request to |
| 69 // also attempt to cache the final (scaled) result, we would add t
hat logic here. |
| 70 // |
| 71 return bm.peekPixels(&pmap) && pmap.scalePixels(dst, quality); |
| 72 } |
| 73 return false; |
| 57 } | 74 } |
| 58 | 75 |
| 59 void SkImage::preroll(GrContext* ctx) const { | 76 void SkImage::preroll(GrContext* ctx) const { |
| 60 // For now, and to maintain parity w/ previous pixelref behavior, we just fo
rce the image | 77 // For now, and to maintain parity w/ previous pixelref behavior, we just fo
rce the image |
| 61 // to produce a cached raster-bitmap form, so that drawing to a raster canva
s should be fast. | 78 // to produce a cached raster-bitmap form, so that drawing to a raster canva
s should be fast. |
| 62 // | 79 // |
| 63 SkBitmap bm; | 80 SkBitmap bm; |
| 64 if (as_IB(this)->getROPixels(&bm)) { | 81 if (as_IB(this)->getROPixels(&bm)) { |
| 65 bm.lockPixels(); | 82 bm.lockPixels(); |
| 66 bm.unlockPixels(); | 83 bm.unlockPixels(); |
| (...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 279 , fAddedToCache(false) | 296 , fAddedToCache(false) |
| 280 {} | 297 {} |
| 281 | 298 |
| 282 SkImage_Base::~SkImage_Base() { | 299 SkImage_Base::~SkImage_Base() { |
| 283 if (fAddedToCache.load()) { | 300 if (fAddedToCache.load()) { |
| 284 SkNotifyBitmapGenIDIsStale(this->uniqueID()); | 301 SkNotifyBitmapGenIDIsStale(this->uniqueID()); |
| 285 } | 302 } |
| 286 } | 303 } |
| 287 | 304 |
| 288 bool SkImage_Base::onReadPixels(const SkImageInfo& dstInfo, void* dstPixels, siz
e_t dstRowBytes, | 305 bool SkImage_Base::onReadPixels(const SkImageInfo& dstInfo, void* dstPixels, siz
e_t dstRowBytes, |
| 289 int srcX, int srcY) const { | 306 int srcX, int srcY, CachingHint) const { |
| 290 if (!raster_canvas_supports(dstInfo)) { | 307 if (!raster_canvas_supports(dstInfo)) { |
| 291 return false; | 308 return false; |
| 292 } | 309 } |
| 293 | 310 |
| 294 SkBitmap bm; | 311 SkBitmap bm; |
| 295 bm.installPixels(dstInfo, dstPixels, dstRowBytes); | 312 bm.installPixels(dstInfo, dstPixels, dstRowBytes); |
| 296 SkCanvas canvas(bm); | 313 SkCanvas canvas(bm); |
| 297 | 314 |
| 298 SkPaint paint; | 315 SkPaint paint; |
| 299 paint.setXfermodeMode(SkXfermode::kSrc_Mode); | 316 paint.setXfermodeMode(SkXfermode::kSrc_Mode); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 310 const void* pixels = this->peekPixels(&info, &rowBytes); | 327 const void* pixels = this->peekPixels(&info, &rowBytes); |
| 311 if (pixels) { | 328 if (pixels) { |
| 312 if (pmap) { | 329 if (pmap) { |
| 313 pmap->reset(info, pixels, rowBytes); | 330 pmap->reset(info, pixels, rowBytes); |
| 314 } | 331 } |
| 315 return true; | 332 return true; |
| 316 } | 333 } |
| 317 return false; | 334 return false; |
| 318 } | 335 } |
| 319 | 336 |
| 320 bool SkImage::readPixels(const SkPixmap& pmap, int srcX, int srcY) const { | 337 bool SkImage::readPixels(const SkPixmap& pmap, int srcX, int srcY, CachingHint c
hint) const { |
| 321 return this->readPixels(pmap.info(), pmap.writable_addr(), pmap.rowBytes(),
srcX, srcY); | 338 return this->readPixels(pmap.info(), pmap.writable_addr(), pmap.rowBytes(),
srcX, srcY, chint); |
| 322 } | 339 } |
| 323 | 340 |
| 324 ////////////////////////////////////////////////////////////////////////////////
/////////////////// | 341 ////////////////////////////////////////////////////////////////////////////////
/////////////////// |
| 325 | 342 |
| 326 SkImage* SkImage::NewFromBitmap(const SkBitmap& bm) { | 343 SkImage* SkImage::NewFromBitmap(const SkBitmap& bm) { |
| 327 SkPixelRef* pr = bm.pixelRef(); | 344 SkPixelRef* pr = bm.pixelRef(); |
| 328 if (nullptr == pr) { | 345 if (nullptr == pr) { |
| 329 return nullptr; | 346 return nullptr; |
| 330 } | 347 } |
| 331 | 348 |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 396 | 413 |
| 397 SkImage* SkImage::NewFromAdoptedTexture(GrContext*, const GrBackendTextureDesc&,
SkAlphaType) { | 414 SkImage* SkImage::NewFromAdoptedTexture(GrContext*, const GrBackendTextureDesc&,
SkAlphaType) { |
| 398 return nullptr; | 415 return nullptr; |
| 399 } | 416 } |
| 400 | 417 |
| 401 SkImage* SkImage::NewFromTextureCopy(GrContext*, const GrBackendTextureDesc&, Sk
AlphaType) { | 418 SkImage* SkImage::NewFromTextureCopy(GrContext*, const GrBackendTextureDesc&, Sk
AlphaType) { |
| 402 return nullptr; | 419 return nullptr; |
| 403 } | 420 } |
| 404 | 421 |
| 405 #endif | 422 #endif |
| OLD | NEW |