BlitMaskClip.cpp 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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/SkColor.h"
  8. #include "include/core/SkRect.h"
  9. #include "include/core/SkTypes.h"
  10. #include "src/core/SkBlitter.h"
  11. #include "src/core/SkMask.h"
  12. #include "tests/Test.h"
  13. #include <string.h>
  14. class TestBlitter : public SkBlitter {
  15. public:
  16. TestBlitter(SkIRect bounds, skiatest::Reporter* reporter)
  17. : fBounds(bounds)
  18. , fReporter(reporter) { }
  19. void blitH(int x, int y, int width) override {
  20. REPORTER_ASSERT(fReporter, x >= fBounds.fLeft && x < fBounds.fRight);
  21. REPORTER_ASSERT(fReporter, y >= fBounds.fTop && y < fBounds.fBottom);
  22. int right = x + width;
  23. REPORTER_ASSERT(fReporter, right > fBounds.fLeft && right <= fBounds.fRight);
  24. }
  25. void blitAntiH(int x, int y, const SkAlpha antialias[], const int16_t runs[]) override {
  26. SkDEBUGFAIL("blitAntiH not implemented");
  27. }
  28. private:
  29. SkIRect fBounds;
  30. skiatest::Reporter* fReporter;
  31. };
  32. // Exercise all clips compared with different widths of bitMask. Make sure that no buffer
  33. // overruns happen.
  34. DEF_TEST(BlitAndClip, reporter) {
  35. const int originX = 100;
  36. const int originY = 100;
  37. for (int width = 1; width <= 32; width++) {
  38. const int height = 2;
  39. int rowBytes = (width + 7) >> 3;
  40. uint8_t* bits = new uint8_t[rowBytes * height];
  41. memset(bits, 0xAA, rowBytes * height);
  42. SkIRect b = {originX, originY, originX + width, originY + height};
  43. SkMask mask;
  44. mask.fFormat = SkMask::kBW_Format;
  45. mask.fBounds = b;
  46. mask.fImage = (uint8_t*)bits;
  47. mask.fRowBytes = rowBytes;
  48. TestBlitter tb(mask.fBounds, reporter);
  49. for (int top = b.fTop; top < b.fBottom; top++) {
  50. for (int bottom = top + 1; bottom <= b.fBottom; bottom++) {
  51. for (int left = b.fLeft; left < b.fRight; left++) {
  52. for (int right = left + 1; right <= b.fRight; right++) {
  53. SkIRect clipRect = {left, top, right, bottom};
  54. tb.blitMask(mask, clipRect);
  55. }
  56. }
  57. }
  58. }
  59. delete [] bits;
  60. }
  61. }