WindowRectanglesTest.cpp 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /*
  2. * Copyright 2016 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/SkTypes.h"
  8. #include "tests/Test.h"
  9. #include "include/utils/SkRandom.h"
  10. #include "src/core/SkRectPriv.h"
  11. #include "src/gpu/GrWindowRectangles.h"
  12. static SkIRect next_irect(SkRandom& r) {
  13. return {r.nextS(), r.nextS(), r.nextS(), r.nextS()};
  14. }
  15. DEF_TEST(WindowRectangles, reporter) {
  16. SkRandom r;
  17. SkIRect windowData[GrWindowRectangles::kMaxWindows];
  18. for (int i = 0; i < GrWindowRectangles::kMaxWindows; ++i) {
  19. windowData[i] = next_irect(r);
  20. }
  21. GrWindowRectangles wr;
  22. for (int i = 0; i < GrWindowRectangles::kMaxWindows - 1; ++i) {
  23. REPORTER_ASSERT(reporter, wr.count() == i);
  24. REPORTER_ASSERT(reporter, !memcmp(wr.data(), windowData, i * sizeof(SkIRect)));
  25. GrWindowRectangles wr2(wr);
  26. REPORTER_ASSERT(reporter, wr2 == wr);
  27. REPORTER_ASSERT(reporter, wr2.count() == wr.count());
  28. REPORTER_ASSERT(reporter, !memcmp(wr2.data(), wr.data(), i * sizeof(SkIRect)));
  29. wr.addWindow(windowData[i]);
  30. }
  31. SkASSERT(wr.count() == GrWindowRectangles::kMaxWindows - 1);
  32. {
  33. GrWindowRectangles A(wr), B(wr);
  34. REPORTER_ASSERT(reporter, B == A);
  35. REPORTER_ASSERT(reporter, B.data() == A.data()); // Should use copy-on-write.
  36. A.addWindow(windowData[GrWindowRectangles::kMaxWindows - 1]);
  37. REPORTER_ASSERT(reporter, B.data() != A.data());
  38. REPORTER_ASSERT(reporter, B != A);
  39. B.addWindow(SkRectPriv::MakeILarge());
  40. REPORTER_ASSERT(reporter, B != A);
  41. REPORTER_ASSERT(reporter, !memcmp(A.data(), windowData,
  42. GrWindowRectangles::kMaxWindows * sizeof(SkIRect)));
  43. REPORTER_ASSERT(reporter, !memcmp(B.data(), windowData,
  44. (GrWindowRectangles::kMaxWindows - 1) * sizeof(SkIRect)));
  45. REPORTER_ASSERT(reporter,
  46. B.data()[GrWindowRectangles::kMaxWindows - 1] == SkRectPriv::MakeILarge());
  47. }
  48. {
  49. GrWindowRectangles A(wr), B(wr);
  50. REPORTER_ASSERT(reporter, B == A);
  51. REPORTER_ASSERT(reporter, B.data() == A.data()); // Should use copy-on-write.
  52. A.addWindow(windowData[GrWindowRectangles::kMaxWindows - 1]);
  53. B.addWindow(windowData[GrWindowRectangles::kMaxWindows - 1]);
  54. REPORTER_ASSERT(reporter, B == A);
  55. REPORTER_ASSERT(reporter, B.data() != A.data());
  56. REPORTER_ASSERT(reporter, !memcmp(B.data(), A.data(),
  57. GrWindowRectangles::kMaxWindows * sizeof(SkIRect)));
  58. REPORTER_ASSERT(reporter, !memcmp(A.data(), windowData,
  59. GrWindowRectangles::kMaxWindows * sizeof(SkIRect)));
  60. }
  61. }