aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/core/SkBitmapProvider.cpp
blob: 9575ae2cf890d15dd839979e9023f7f5704affcc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
/*
 * Copyright 2015 Google Inc.
 *
 * Use of this source code is governed by a BSD-style license that can be
 * found in the LICENSE file.
 */

#include "SkBitmapProvider.h"
#include "SkImage_Base.h"
#include "SkImageCacherator.h"
#include "SkPixelRef.h"

int SkBitmapProvider::width() const {
    return fImage->width();
}

int SkBitmapProvider::height() const {
    return fImage->height();
}

uint32_t SkBitmapProvider::getID() const {
    return fImage->uniqueID();
}

SkImageInfo SkBitmapProvider::info() const {
    return as_IB(fImage)->onImageInfo();
}

bool SkBitmapProvider::isVolatile() const {
    // add flag to images?
    const SkBitmap* bm = as_IB(fImage)->onPeekBitmap();
    return bm ? bm->isVolatile() : false;
}

SkBitmapCacheDesc SkBitmapProvider::makeCacheDesc(int w, int h) const {
    return SkBitmapCacheDesc::Make(fImage, w, h);
}

SkBitmapCacheDesc SkBitmapProvider::makeCacheDesc() const {
    return SkBitmapCacheDesc::Make(fImage);
}

void SkBitmapProvider::notifyAddedToCache() const {
    as_IB(fImage)->notifyAddedToCache();
}

bool SkBitmapProvider::asBitmap(SkBitmap* bm) const {
    return as_IB(fImage)->getROPixels(bm, fDstColorSpace, SkImage::kAllow_CachingHint);
}

bool SkBitmapProvider::accessScaledImage(const SkRect& srcRect,
                                         const SkMatrix& invMatrix,
                                         SkFilterQuality fq,
                                         SkBitmap* scaledBitmap,
                                         SkRect* adjustedSrcRect,
                                         SkFilterQuality* adjustedFilterQuality) const {
    if (!fImage) {
        return false;
    }

    SkImageCacherator* cacherator = as_IB(fImage)->peekCacherator();
    if (!cacherator) {
        return false;
    }

    // TODO: stash the matrix someplace to avoid invert()?
    SkMatrix m;
    if (!invMatrix.invert(&m)) {
        return false;
    }

    SkImageGenerator::ScaledImageRec rec;
    if (!cacherator->directAccessScaledImage(srcRect, m, fq, &rec) ||
        !scaledBitmap->installPixels(rec.fPixmap.info(), const_cast<void*>(rec.fPixmap.addr()),
                                     rec.fPixmap.rowBytes(), rec.fPixmap.ctable(),
                                     rec.fReleaseProc, rec.fReleaseCtx)) {
        return false;
    }

    *adjustedSrcRect       = rec.fSrcRect;
    *adjustedFilterQuality = rec.fQuality;

    return true;
}