• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
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 
8 #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"
15 
16 // Test that the SkPictureShader cache is purged on shader deletion.
DEF_TEST(PictureShader_caching,reporter)17 DEF_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;
31         paint.setShader(picture->makeShader(SkTileMode::kRepeat, SkTileMode::kRepeat));
32         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;
41         paint.setShader(makePicture()->makeShader(SkTileMode::kRepeat, SkTileMode::kRepeat));
42         surface->getCanvas()->drawPaint(paint);
43 
44     }
45 
46     // All but the local ref should be gone now.
47     REPORTER_ASSERT(reporter, picture->unique());
48 }
49