blob: 1698724b2b631b6efed381434b9564d419f212e8 [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
Mike Kleinc0bd9f92019-04-23 12:05:21 -05008#include "include/core/SkCanvas.h"
9#include "include/core/SkPicture.h"
10#include "include/core/SkPictureRecorder.h"
11#include "include/core/SkShader.h"
12#include "include/core/SkSurface.h"
13#include "src/shaders/SkPictureShader.h"
14#include "tests/Test.h"
commit-bot@chromium.org855e88e2014-04-21 19:33:12 +000015
Florin Malitab00a3602017-07-13 22:34:04 -040016// Test that the SkPictureShader cache is purged on shader deletion.
17DEF_TEST(PictureShader_caching, reporter) {
18 auto makePicture = [] () {
19 SkPictureRecorder recorder;
20 recorder.beginRecording(100, 100)->drawColor(SK_ColorGREEN);
21 return recorder.finishRecordingAsPicture();
22 };
23
24 sk_sp<SkPicture> picture = makePicture();
25 REPORTER_ASSERT(reporter, picture->unique());
26
27 sk_sp<SkSurface> surface = SkSurface::MakeRasterN32Premul(100, 100);
28
29 {
30 SkPaint paint;
Mike Reede25b4472019-04-02 17:49:12 -040031 paint.setShader(picture->makeShader(SkTileMode::kRepeat, SkTileMode::kRepeat));
Florin Malitab00a3602017-07-13 22:34:04 -040032 surface->getCanvas()->drawPaint(paint);
33
34 // We should have about 3 refs by now: local + shader + shader cache.
35 REPORTER_ASSERT(reporter, !picture->unique());
36 }
37
38 // Draw another picture shader to have a chance to purge.
39 {
40 SkPaint paint;
Mike Reede25b4472019-04-02 17:49:12 -040041 paint.setShader(makePicture()->makeShader(SkTileMode::kRepeat, SkTileMode::kRepeat));
Florin Malitab00a3602017-07-13 22:34:04 -040042 surface->getCanvas()->drawPaint(paint);
43
44 }
45
46 // All but the local ref should be gone now.
47 REPORTER_ASSERT(reporter, picture->unique());
48}