blob: 14bdcf2d81fbecf110430d961c77a4f9c2212791 [file] [log] [blame]
commit-bot@chromium.org855e88e2014-04-21 19:33:12 +00001/*
2 * Copyright 2014 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
mtkleincfa90a12015-05-18 13:44:35 -07008#include "SkCanvas.h"
commit-bot@chromium.org855e88e2014-04-21 19:33:12 +00009#include "SkPicture.h"
10#include "SkPictureRecorder.h"
11#include "SkShader.h"
12#include "Test.h"
13
halcanary96fcdcc2015-08-27 07:41:13 -070014// Test that attempting to create a picture shader with a nullptr picture or
mtkleincfa90a12015-05-18 13:44:35 -070015// empty picture returns a shader that draws nothing.
commit-bot@chromium.org855e88e2014-04-21 19:33:12 +000016DEF_TEST(PictureShader_empty, reporter) {
mtkleincfa90a12015-05-18 13:44:35 -070017 SkPaint paint;
18
19 SkBitmap bitmap;
20 bitmap.allocN32Pixels(1,1);
21
22 SkCanvas canvas(bitmap);
23 canvas.clear(SK_ColorGREEN);
24
25 SkShader* shader = SkShader::CreatePictureShader(
halcanary96fcdcc2015-08-27 07:41:13 -070026 nullptr, SkShader::kClamp_TileMode, SkShader::kClamp_TileMode, nullptr, nullptr);
mtkleincfa90a12015-05-18 13:44:35 -070027 paint.setShader(shader)->unref();
28
29 canvas.drawRect(SkRect::MakeWH(1,1), paint);
30 REPORTER_ASSERT(reporter, *bitmap.getAddr32(0,0) == SK_ColorGREEN);
31
commit-bot@chromium.org855e88e2014-04-21 19:33:12 +000032
33 SkPictureRecorder factory;
halcanary96fcdcc2015-08-27 07:41:13 -070034 factory.beginRecording(0, 0, nullptr, 0);
commit-bot@chromium.org855e88e2014-04-21 19:33:12 +000035 SkAutoTUnref<SkPicture> picture(factory.endRecording());
mtkleincfa90a12015-05-18 13:44:35 -070036 shader = SkShader::CreatePictureShader(
halcanary96fcdcc2015-08-27 07:41:13 -070037 picture.get(), SkShader::kClamp_TileMode, SkShader::kClamp_TileMode, nullptr, nullptr);
mtkleincfa90a12015-05-18 13:44:35 -070038 paint.setShader(shader)->unref();
39
40 canvas.drawRect(SkRect::MakeWH(1,1), paint);
41 REPORTER_ASSERT(reporter, *bitmap.getAddr32(0,0) == SK_ColorGREEN);
commit-bot@chromium.org855e88e2014-04-21 19:33:12 +000042}