blob: 83240478ad98c145762c6d70fe31ffb09e907e66 [file] [log] [blame]
reedf1ac1822016-08-01 11:24:14 -07001/*
2 * Copyright 2016 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8#include "Test.h"
9#include "SkBitmap.h"
10#include "SkImage.h"
11#include "SkShader.h"
12#include "SkSurface.h"
13#include "SkData.h"
14
15static void check_isabitmap(skiatest::Reporter* reporter, SkShader* shader,
16 int expectedW, int expectedH,
17 SkShader::TileMode expectedX, SkShader::TileMode expectedY,
reed320a40d2016-08-02 06:12:06 -070018 const SkMatrix& expectedM) {
reedf1ac1822016-08-01 11:24:14 -070019 SkBitmap bm;
20 SkShader::TileMode tileModes[2];
21 SkMatrix localM;
22 REPORTER_ASSERT(reporter, shader->isABitmap(&bm, &localM, tileModes));
23 REPORTER_ASSERT(reporter, bm.width() == expectedW);
24 REPORTER_ASSERT(reporter, bm.height() == expectedH);
25 REPORTER_ASSERT(reporter, localM == expectedM);
26 REPORTER_ASSERT(reporter, tileModes[0] == expectedX);
27 REPORTER_ASSERT(reporter, tileModes[1] == expectedY);
28
29 // wack these so we don't get a false positive
30 localM.setScale(9999, -9999);
31 tileModes[0] = tileModes[1] = (SkShader::TileMode)99;
32
33 SkImage* image = shader->isAImage(&localM, tileModes);
reed320a40d2016-08-02 06:12:06 -070034 REPORTER_ASSERT(reporter, image);
35 REPORTER_ASSERT(reporter, image->width() == expectedW);
36 REPORTER_ASSERT(reporter, image->height() == expectedH);
37 REPORTER_ASSERT(reporter, localM == expectedM);
38 REPORTER_ASSERT(reporter, tileModes[0] == expectedX);
39 REPORTER_ASSERT(reporter, tileModes[1] == expectedY);
reedf1ac1822016-08-01 11:24:14 -070040}
41
42DEF_TEST(Shader_isABitmap, reporter) {
43 const int W = 100;
44 const int H = 100;
45 SkBitmap bm;
46 bm.allocN32Pixels(W, H);
47 auto img = SkImage::MakeFromBitmap(bm);
48 const SkMatrix localM = SkMatrix::MakeScale(2, 3);
49 const SkShader::TileMode tmx = SkShader::kRepeat_TileMode;
50 const SkShader::TileMode tmy = SkShader::kMirror_TileMode;
51
52 auto shader0 = SkShader::MakeBitmapShader(bm, tmx, tmy, &localM);
53 auto shader1 = SkImage::MakeFromBitmap(bm)->makeShader(tmx, tmy, &localM);
54
reed320a40d2016-08-02 06:12:06 -070055 check_isabitmap(reporter, shader0.get(), W, H, tmx, tmy, localM);
56 check_isabitmap(reporter, shader1.get(), W, H, tmx, tmy, localM);
reedf1ac1822016-08-01 11:24:14 -070057}