ClipBoundsTest.cpp 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. /*
  2. * Copyright 2015 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/SkMatrix.h"
  8. #include "include/core/SkRect.h"
  9. #include "src/core/SkClipOpPriv.h"
  10. #include "src/core/SkClipStack.h"
  11. #include "src/gpu/GrClipStackClip.h"
  12. #include "tests/Test.h"
  13. // Ensure that the 'getConservativeBounds' calls are returning bounds clamped
  14. // to the render target
  15. DEF_GPUTEST_FOR_RENDERING_CONTEXTS(GrClipBounds, reporter, ctxInfo) {
  16. static const int kXSize = 100;
  17. static const int kYSize = 100;
  18. const SkIRect intScreen = SkIRect::MakeWH(kXSize, kYSize);
  19. const SkRect screen = SkRect::Make(intScreen);
  20. SkRect clipRect(screen);
  21. clipRect.outset(10, 10);
  22. // create a clip stack that will (trivially) reduce to a single rect that
  23. // is larger than the screen
  24. SkClipStack stack;
  25. stack.clipRect(clipRect, SkMatrix::I(), kReplace_SkClipOp, false);
  26. bool isIntersectionOfRects = true;
  27. SkRect devStackBounds;
  28. stack.getConservativeBounds(0, 0, kXSize, kYSize,
  29. &devStackBounds,
  30. &isIntersectionOfRects);
  31. // make sure that the SkClipStack is behaving itself
  32. REPORTER_ASSERT(reporter, screen == devStackBounds);
  33. REPORTER_ASSERT(reporter, isIntersectionOfRects);
  34. // wrap the SkClipStack in a GrClip
  35. GrClipStackClip clipData(&stack);
  36. SkIRect devGrClipBound;
  37. clipData.getConservativeBounds(kXSize, kYSize,
  38. &devGrClipBound,
  39. &isIntersectionOfRects);
  40. // make sure that GrClip is behaving itself
  41. REPORTER_ASSERT(reporter, intScreen == devGrClipBound);
  42. REPORTER_ASSERT(reporter, isIntersectionOfRects);
  43. }