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