skbug_8664.cpp 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /*
  2. * Copyright 2019 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 "gm/gm.h"
  8. #include "include/core/SkCanvas.h"
  9. #include "include/core/SkFilterQuality.h"
  10. #include "include/core/SkImage.h"
  11. #include "include/core/SkPaint.h"
  12. #include "include/core/SkRect.h"
  13. #include "include/core/SkRefCnt.h"
  14. #include "include/core/SkScalar.h"
  15. #include "tools/Resources.h"
  16. DEF_SIMPLE_GM(skbug_8664, canvas, 830, 550) {
  17. const struct {
  18. SkScalar fSx, fSy, fTx, fTy;
  19. } xforms[] = {
  20. { 1, 1, 0, 0 },
  21. { 0.5f, 0.5f, 530, 0 },
  22. { 0.25f, 0.25f, 530, 275 },
  23. { 0.125f, 0.125f, 530, 420 },
  24. };
  25. SkPaint imagePaint;
  26. // Must be at least medium to require mipmaps when we downscale the image
  27. imagePaint.setFilterQuality(kMedium_SkFilterQuality);
  28. sk_sp<SkImage> image(GetResourceAsImage("images/mandrill_512.png"));
  29. SkPaint overlayPaint;
  30. overlayPaint.setColor(0x80FFFFFF);
  31. // Make the overlay visible even when the downscaled images fail to render
  32. canvas->clear(0xFF888888);
  33. canvas->translate(20, 20);
  34. for (const auto& xform : xforms) {
  35. canvas->save();
  36. canvas->translate(xform.fTx, xform.fTy);
  37. canvas->scale(xform.fSx, xform.fSy);
  38. // Draw an image, possibly down sampled, which forces us to generate mipmaps inline
  39. // on the second iteration.
  40. canvas->drawImage(image, 0, 0, &imagePaint);
  41. // Draw an overlay that requires the scissor test for its clipping, so that the mipmap
  42. // generation + scissor interference bug is highlighted in Adreno 330 devices.
  43. SkRect inner = SkRect::MakeLTRB(32.f, 32.f, 480.f, 480.f);
  44. SkRect outer = inner.makeOutset(16.f, 16.f);
  45. // Clip to smaller rectangle
  46. canvas->save();
  47. canvas->clipRect(inner);
  48. // Then apply a rotation and draw a larger rectangle to ensure the clip cannot be dropped
  49. canvas->rotate(20.f);
  50. canvas->drawRect(outer, overlayPaint);
  51. canvas->restore();
  52. canvas->restore();
  53. }
  54. }