2 * Copyright 2015 Google Inc.
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
8 #include "SkBitmapProvider.h"
9 #include "SkImage_Base.h"
10 #include "SkImageCacherator.h"
11 #include "SkPixelRef.h"
13 int SkBitmapProvider::width() const {
14 return fImage->width();
17 int SkBitmapProvider::height() const {
18 return fImage->height();
21 uint32_t SkBitmapProvider::getID() const {
22 return fImage->uniqueID();
25 SkImageInfo SkBitmapProvider::info() const {
26 return as_IB(fImage)->onImageInfo();
29 bool SkBitmapProvider::isVolatile() const {
30 // add flag to images?
31 const SkBitmap* bm = as_IB(fImage)->onPeekBitmap();
32 return bm ? bm->isVolatile() : false;
35 SkBitmapCacheDesc SkBitmapProvider::makeCacheDesc(int w, int h) const {
36 return SkBitmapCacheDesc::Make(fImage, w, h);
39 SkBitmapCacheDesc SkBitmapProvider::makeCacheDesc() const {
40 return SkBitmapCacheDesc::Make(fImage);
43 void SkBitmapProvider::notifyAddedToCache() const {
44 as_IB(fImage)->notifyAddedToCache();
47 bool SkBitmapProvider::asBitmap(SkBitmap* bm) const {
48 return as_IB(fImage)->getROPixels(bm, fDstColorSpace, SkImage::kAllow_CachingHint);
51 bool SkBitmapProvider::accessScaledImage(const SkRect& srcRect,
52 const SkMatrix& invMatrix,
54 SkBitmap* scaledBitmap,
55 SkRect* adjustedSrcRect,
56 SkFilterQuality* adjustedFilterQuality) const {
61 SkImageCacherator* cacherator = as_IB(fImage)->peekCacherator();
66 // TODO: stash the matrix someplace to avoid invert()?
68 if (!invMatrix.invert(&m)) {
72 SkImageGenerator::ScaledImageRec rec;
73 if (!cacherator->directAccessScaledImage(srcRect, m, fq, &rec) ||
74 !scaledBitmap->installPixels(rec.fPixmap.info(), const_cast<void*>(rec.fPixmap.addr()),
75 rec.fPixmap.rowBytes(), rec.fPixmap.ctable(),
76 rec.fReleaseProc, rec.fReleaseCtx)) {
80 *adjustedSrcRect = rec.fSrcRect;
81 *adjustedFilterQuality = rec.fQuality;