SkAAClip.h revision e36707a4a82a4dea7d480d969220f3ed223305dc
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); 41 42 bool op(const SkAAClip&, const SkAAClip&, SkRegion::Op); 43 44 // called internally 45 46 bool quickContains(int left, int top, int right, int bottom) const; 47 const uint8_t* findRow(int y, int* lastYForRow) const; 48 const uint8_t* findX(const uint8_t data[], int x, int* initialCount) const; 49 50private: 51 struct RunHead; 52 struct YOffset; 53 54 SkIRect fBounds; 55 RunHead* fRunHead; 56 57 void freeRuns(); 58 59 class Builder; 60 friend class Builder; 61 class BuilderBlitter; 62 friend class BuilderBlitter; 63}; 64 65/////////////////////////////////////////////////////////////////////////////// 66 67class SkAAClipBlitter : public SkBlitter { 68public: 69 SkAAClipBlitter() : fRuns(NULL) {} 70 virtual ~SkAAClipBlitter(); 71 72 void init(SkBlitter* blitter, const SkAAClip* aaclip) { 73 SkASSERT(aaclip && !aaclip->isEmpty()); 74 fBlitter = blitter; 75 fAAClip = aaclip; 76 fAAClipBounds = aaclip->getBounds(); 77 } 78 79 virtual void blitH(int x, int y, int width) SK_OVERRIDE; 80 virtual void blitAntiH(int x, int y, const SkAlpha[], 81 const int16_t runs[]) SK_OVERRIDE; 82 virtual void blitV(int x, int y, int height, SkAlpha alpha) SK_OVERRIDE; 83 virtual void blitRect(int x, int y, int width, int height) SK_OVERRIDE; 84 virtual void blitMask(const SkMask&, const SkIRect& clip) SK_OVERRIDE; 85 virtual const SkBitmap* justAnOpaqueColor(uint32_t* value) SK_OVERRIDE; 86 87private: 88 SkBlitter* fBlitter; 89 const SkAAClip* fAAClip; 90 SkIRect fAAClipBounds; 91 92 // lazily allocated 93 int16_t* fRuns; 94 SkAlpha* fAA; // points into fRuns allocation 95 96 void ensureRunsAndAA(); 97}; 98 99#endif 100