tilemodes_alpha.cpp 1.2 KB

123456789101112131415161718192021222324252627282930313233343536
  1. // Copyright 2019 Google LLC.
  2. // Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
  3. #include "gm/gm.h"
  4. #include "include/core/SkCanvas.h"
  5. #include "include/core/SkImage.h"
  6. #include "include/core/SkMatrix.h"
  7. #include "include/core/SkPaint.h"
  8. #include "include/core/SkRect.h"
  9. #include "include/core/SkRefCnt.h"
  10. #include "include/core/SkShader.h"
  11. #include "include/core/SkTileMode.h"
  12. #include "tools/Resources.h"
  13. // http://crbug.com/957275
  14. DEF_SIMPLE_GM(tilemodes_alpha, canvas, 512, 512) {
  15. sk_sp<SkImage> image = GetResourceAsImage("images/mandrill_64.png");
  16. if (!image) {
  17. return;
  18. }
  19. constexpr SkTileMode kModes[4] = {
  20. SkTileMode::kClamp,
  21. SkTileMode::kRepeat,
  22. SkTileMode::kMirror,
  23. SkTileMode::kDecal,
  24. };
  25. for (int y = 0; y < 4; ++y) {
  26. for (int x = 0; x < 4; ++x) {
  27. SkRect rect = SkRect::MakeXYWH(128 * x + 1, 128 * y + 1, 126, 126);
  28. SkMatrix matrix = SkMatrix::MakeTrans(rect.x(), rect.y());
  29. SkPaint paint(SkColor4f{0, 0, 0, 0.5f});
  30. paint.setShader(image->makeShader(kModes[x], kModes[y], &matrix));
  31. canvas->drawRect(rect, paint);
  32. }
  33. }
  34. }