SkAAClip.h revision 045e62d715f5ee9b03deb5af3c750f8318096179
1 2/* 3 * Copyright 2011 Google Inc. 4 * 5 * Use of this source code is governed by a BSD-style license that can be 6 * found in the LICENSE file. 7 */ 8 9#ifndef SkAAClip_DEFINED 10#define SkAAClip_DEFINED 11 12#include "SkBlitter.h" 13#include "SkRegion.h" 14 15class SkAAClip { 16public: 17 SkAAClip(); 18 SkAAClip(const SkAAClip&); 19 ~SkAAClip(); 20 21 SkAAClip& operator=(const SkAAClip&); 22 friend bool operator==(const SkAAClip&, const SkAAClip&); 23 friend bool operator!=(const SkAAClip& a, const SkAAClip& b) { 24 return !(a == b); 25 } 26 27 void swap(SkAAClip&); 28 29 bool isEmpty() const { return NULL == fRunHead; } 30 const SkIRect& getBounds() const { return fBounds; } 31 32 bool setEmpty(); 33 bool setRect(const SkIRect&); 34 bool setRect(const SkRect&, bool doAA = true); 35 bool setPath(const SkPath&, const SkRegion* clip = NULL, bool doAA = true); 36 bool setRegion(const SkRegion&); 37 bool set(const SkAAClip&); 38 39 bool op(const SkAAClip&, const SkAAClip&, SkRegion::Op); 40 41 // Helpers for op() 42 bool op(const SkIRect&, SkRegion::Op); 43 bool op(const SkRect&, SkRegion::Op, bool doAA); 44 bool op(const SkAAClip&, SkRegion::Op); 45 46 bool translate(int dx, int dy, SkAAClip* dst) const; 47 bool translate(int dx, int dy) { 48 return this->translate(dx, dy, this); 49 } 50 51 /** 52 * Allocates a mask the size of the aaclip, and expands its data into 53 * the mask, using kA8_Format 54 */ 55 void copyToMask(SkMask*) const; 56 57 // called internally 58 59 bool quickContains(int left, int top, int right, int bottom) const; 60 bool quickContains(const SkIRect& r) const { 61 return this->quickContains(r.fLeft, r.fTop, r.fRight, r.fBottom); 62 } 63 64 const uint8_t* findRow(int y, int* lastYForRow) const; 65 const uint8_t* findX(const uint8_t data[], int x, int* initialCount) const; 66 67 class Iter; 68 struct RunHead; 69 struct YOffset; 70 class Builder; 71 72#ifdef SK_DEBUG 73 void validate() const; 74#else 75 void validate() const {} 76#endif 77 78private: 79 SkIRect fBounds; 80 RunHead* fRunHead; 81 82 void freeRuns(); 83 bool trimBounds(); 84 85 friend class Builder; 86 class BuilderBlitter; 87 friend class BuilderBlitter; 88}; 89 90/////////////////////////////////////////////////////////////////////////////// 91 92class SkAAClipBlitter : public SkBlitter { 93public: 94 SkAAClipBlitter() : fScanlineScratch(NULL) {} 95 virtual ~SkAAClipBlitter(); 96 97 void init(SkBlitter* blitter, const SkAAClip* aaclip) { 98 SkASSERT(aaclip && !aaclip->isEmpty()); 99 fBlitter = blitter; 100 fAAClip = aaclip; 101 fAAClipBounds = aaclip->getBounds(); 102 } 103 104 virtual void blitH(int x, int y, int width) SK_OVERRIDE; 105 virtual void blitAntiH(int x, int y, const SkAlpha[], 106 const int16_t runs[]) SK_OVERRIDE; 107 virtual void blitV(int x, int y, int height, SkAlpha alpha) SK_OVERRIDE; 108 virtual void blitRect(int x, int y, int width, int height) SK_OVERRIDE; 109 virtual void blitMask(const SkMask&, const SkIRect& clip) SK_OVERRIDE; 110 virtual const SkBitmap* justAnOpaqueColor(uint32_t* value) SK_OVERRIDE; 111 112private: 113 SkBlitter* fBlitter; 114 const SkAAClip* fAAClip; 115 SkIRect fAAClipBounds; 116 117 // point into fScanlineScratch 118 int16_t* fRuns; 119 SkAlpha* fAA; 120 121 enum { 122 kSize = 32 * 32 123 }; 124 SkAutoSMalloc<kSize> fGrayMaskScratch; // used for blitMask 125 void* fScanlineScratch; // enough for a mask at 32bit, or runs+aa 126 127 void ensureRunsAndAA(); 128}; 129 130#endif 131