Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(195)

Side by Side Diff: tests/ShaderTest.cpp

Issue 2197323002: implement isABitmap for imageshader, return localmatrix for bitmap's impl (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: add isAImage api Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/pdf/SkPDFShader.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 /*
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
15 static void check_isabitmap(skiatest::Reporter* reporter, SkShader* shader,
16 int expectedW, int expectedH,
17 SkShader::TileMode expectedX, SkShader::TileMode exp ectedY,
18 const SkMatrix& expectedM,
19 bool expectedImage) {
20 SkBitmap bm;
21 SkShader::TileMode tileModes[2];
22 SkMatrix localM;
23 REPORTER_ASSERT(reporter, shader->isABitmap(&bm, &localM, tileModes));
24 REPORTER_ASSERT(reporter, bm.width() == expectedW);
25 REPORTER_ASSERT(reporter, bm.height() == expectedH);
26 REPORTER_ASSERT(reporter, localM == expectedM);
27 REPORTER_ASSERT(reporter, tileModes[0] == expectedX);
28 REPORTER_ASSERT(reporter, tileModes[1] == expectedY);
29
30 // wack these so we don't get a false positive
31 localM.setScale(9999, -9999);
32 tileModes[0] = tileModes[1] = (SkShader::TileMode)99;
33
34 SkImage* image = shader->isAImage(&localM, tileModes);
35 REPORTER_ASSERT(reporter, (image != nullptr) == expectedImage);
36 if (image) {
37 REPORTER_ASSERT(reporter, image->width() == expectedW);
38 REPORTER_ASSERT(reporter, image->height() == expectedH);
39 REPORTER_ASSERT(reporter, localM == expectedM);
40 REPORTER_ASSERT(reporter, tileModes[0] == expectedX);
41 REPORTER_ASSERT(reporter, tileModes[1] == expectedY);
42 }
43 }
44
45 DEF_TEST(Shader_isABitmap, reporter) {
46 const int W = 100;
47 const int H = 100;
48 SkBitmap bm;
49 bm.allocN32Pixels(W, H);
50 auto img = SkImage::MakeFromBitmap(bm);
51 const SkMatrix localM = SkMatrix::MakeScale(2, 3);
52 const SkShader::TileMode tmx = SkShader::kRepeat_TileMode;
53 const SkShader::TileMode tmy = SkShader::kMirror_TileMode;
54
55 auto shader0 = SkShader::MakeBitmapShader(bm, tmx, tmy, &localM);
56 auto shader1 = SkImage::MakeFromBitmap(bm)->makeShader(tmx, tmy, &localM);
57
58 check_isabitmap(reporter, shader0.get(), W, H, tmx, tmy, localM, false);
59 check_isabitmap(reporter, shader1.get(), W, H, tmx, tmy, localM, true);
60 }
OLDNEW
« no previous file with comments | « src/pdf/SkPDFShader.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698