SkAAClip.h revision 322878907f6c5c5fb8abdbce7d348a3cd66ff2fa
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 15#define SkAAClip_gEmptyPtr ((SkAAClip::RunHead*)-1) 16#define SkAAClip_gRectPtr NULL 17 18class SkAAClip { 19public: 20 SkAAClip(); 21 SkAAClip(const SkAAClip&); 22 ~SkAAClip(); 23 24 SkAAClip& operator=(const SkAAClip&); 25 friend bool operator==(const SkAAClip&, const SkAAClip&); 26 friend bool operator!=(const SkAAClip& a, const SkAAClip& b) { 27 return !(a == b); 28 } 29 30 void swap(SkAAClip&); 31 32 bool isEmpty() const { return SkAAClip_gEmptyPtr == fRunHead; } 33// bool isRect() const { return SkAAClip_gRectPtr == fRunHead; } 34 bool isComplex() const { return !this->isEmpty() /*&& !this->isRect()*/; } 35 const SkIRect& getBounds() const { return fBounds; } 36 37 bool setEmpty(); 38 bool setRect(const SkIRect&); 39 bool setRect(const SkRect&); 40 bool setPath(const SkPath&, const SkRegion* clip = NULL); 41 bool set(const SkAAClip&); 42 43 bool op(const SkAAClip&, const SkAAClip&, SkRegion::Op); 44 45 /** 46 * Allocates a mask the size of the aaclip, and expands its data into 47 * the mask, using kA8_Format 48 */ 49 void copyToMask(SkMask*) const; 50 51 // called internally 52 53 bool quickContains(int left, int top, int right, int bottom) const; 54 const uint8_t* findRow(int y, int* lastYForRow) const; 55 const uint8_t* findX(const uint8_t data[], int x, int* initialCount) const; 56 57 class Iter; 58 struct RunHead; 59 struct YOffset; 60 class Builder; 61 62private: 63 SkIRect fBounds; 64 RunHead* fRunHead; 65 66 void freeRuns(); 67 68 friend class Builder; 69 class BuilderBlitter; 70 friend class BuilderBlitter; 71}; 72 73/////////////////////////////////////////////////////////////////////////////// 74 75class SkAAClipBlitter : public SkBlitter { 76public: 77 SkAAClipBlitter() : fRuns(NULL) {} 78 virtual ~SkAAClipBlitter(); 79 80 void init(SkBlitter* blitter, const SkAAClip* aaclip) { 81 SkASSERT(aaclip && !aaclip->isEmpty()); 82 fBlitter = blitter; 83 fAAClip = aaclip; 84 fAAClipBounds = aaclip->getBounds(); 85 } 86 87 virtual void blitH(int x, int y, int width) SK_OVERRIDE; 88 virtual void blitAntiH(int x, int y, const SkAlpha[], 89 const int16_t runs[]) SK_OVERRIDE; 90 virtual void blitV(int x, int y, int height, SkAlpha alpha) SK_OVERRIDE; 91 virtual void blitRect(int x, int y, int width, int height) SK_OVERRIDE; 92 virtual void blitMask(const SkMask&, const SkIRect& clip) SK_OVERRIDE; 93 virtual const SkBitmap* justAnOpaqueColor(uint32_t* value) SK_OVERRIDE; 94 95private: 96 SkBlitter* fBlitter; 97 const SkAAClip* fAAClip; 98 SkIRect fAAClipBounds; 99 100 // lazily allocated 101 int16_t* fRuns; 102 SkAlpha* fAA; // points into fRuns allocation 103 104 void ensureRunsAndAA(); 105}; 106 107#endif 108