PictureShaderTest.cpp 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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. #include "include/core/SkCanvas.h"
  8. #include "include/core/SkPicture.h"
  9. #include "include/core/SkPictureRecorder.h"
  10. #include "include/core/SkShader.h"
  11. #include "include/core/SkSurface.h"
  12. #include "src/shaders/SkPictureShader.h"
  13. #include "tests/Test.h"
  14. // Test that the SkPictureShader cache is purged on shader deletion.
  15. DEF_TEST(PictureShader_caching, reporter) {
  16. auto makePicture = [] () {
  17. SkPictureRecorder recorder;
  18. recorder.beginRecording(100, 100)->drawColor(SK_ColorGREEN);
  19. return recorder.finishRecordingAsPicture();
  20. };
  21. sk_sp<SkPicture> picture = makePicture();
  22. REPORTER_ASSERT(reporter, picture->unique());
  23. sk_sp<SkSurface> surface = SkSurface::MakeRasterN32Premul(100, 100);
  24. {
  25. SkPaint paint;
  26. paint.setShader(picture->makeShader(SkTileMode::kRepeat, SkTileMode::kRepeat));
  27. surface->getCanvas()->drawPaint(paint);
  28. // We should have about 3 refs by now: local + shader + shader cache.
  29. REPORTER_ASSERT(reporter, !picture->unique());
  30. }
  31. // Draw another picture shader to have a chance to purge.
  32. {
  33. SkPaint paint;
  34. paint.setShader(makePicture()->makeShader(SkTileMode::kRepeat, SkTileMode::kRepeat));
  35. surface->getCanvas()->drawPaint(paint);
  36. }
  37. // All but the local ref should be gone now.
  38. REPORTER_ASSERT(reporter, picture->unique());
  39. }