aboutsummaryrefslogtreecommitdiffhomepage
path: root/dm/DMUtil.cpp
blob: d5214849e6f4e72fea0cbd4ae3e975d9d1d52d98 (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
#include "DMUtil.h"

#include "SkPicture.h"

namespace DM {

SkString UnderJoin(const char* a, const char* b) {
    SkString s;
    s.appendf("%s_%s", a, b);
    return s;
}

SkString Png(SkString s) {
    s.appendf(".png");
    return s;
}

bool MeetsExpectations(const skiagm::Expectations& expectations, const SkBitmap bitmap) {
    if (expectations.ignoreFailure() || expectations.empty()) {
        return true;
    }
    const skiagm::GmResultDigest digest(bitmap);
    return expectations.match(digest);
}

void RecordPicture(skiagm::GM* gm, SkPicture* picture, uint32_t recordFlags) {
    SkCanvas* canvas = picture->beginRecording(SkScalarCeilToInt(gm->width()),
                                               SkScalarCeilToInt(gm->height()),
                                               recordFlags);
    canvas->concat(gm->getInitialTransform());
    gm->draw(canvas);
    canvas->flush();
    picture->endRecording();
}

void SetupBitmap(const SkBitmap::Config config, skiagm::GM* gm, SkBitmap* bitmap) {
    bitmap->setConfig(config, SkScalarCeilToInt(gm->width()), SkScalarCeilToInt(gm->height()));
    bitmap->allocPixels();
    bitmap->eraseColor(0x00000000);
}

void DrawPicture(SkPicture* picture, SkBitmap* bitmap) {
    SkASSERT(picture != NULL);
    SkASSERT(bitmap != NULL);
    SkCanvas canvas(*bitmap);
    canvas.drawPicture(*picture);
    canvas.flush();
}

bool BitmapsEqual(const SkBitmap& a, const SkBitmap& b) {
    const SkAutoLockPixels lockA(a), lockB(b);
    return a.getSize() == b.getSize() && 0 == memcmp(a.getPixels(), b.getPixels(), b.getSize());
}

}  // namespace DM