michael@0: michael@0: /* michael@0: * Copyright 2011 Google Inc. michael@0: * michael@0: * Use of this source code is governed by a BSD-style license that can be michael@0: * found in the LICENSE file. michael@0: */ michael@0: michael@0: #ifndef SkAAClip_DEFINED michael@0: #define SkAAClip_DEFINED michael@0: michael@0: #include "SkBlitter.h" michael@0: #include "SkRegion.h" michael@0: michael@0: class SkAAClip { michael@0: public: michael@0: SkAAClip(); michael@0: SkAAClip(const SkAAClip&); michael@0: ~SkAAClip(); michael@0: michael@0: SkAAClip& operator=(const SkAAClip&); michael@0: friend bool operator==(const SkAAClip&, const SkAAClip&); michael@0: friend bool operator!=(const SkAAClip& a, const SkAAClip& b) { michael@0: return !(a == b); michael@0: } michael@0: michael@0: void swap(SkAAClip&); michael@0: michael@0: bool isEmpty() const { return NULL == fRunHead; } michael@0: const SkIRect& getBounds() const { return fBounds; } michael@0: michael@0: bool setEmpty(); michael@0: bool setRect(const SkIRect&); michael@0: bool setRect(const SkRect&, bool doAA = true); michael@0: bool setPath(const SkPath&, const SkRegion* clip = NULL, bool doAA = true); michael@0: bool setRegion(const SkRegion&); michael@0: bool set(const SkAAClip&); michael@0: michael@0: bool op(const SkAAClip&, const SkAAClip&, SkRegion::Op); michael@0: michael@0: // Helpers for op() michael@0: bool op(const SkIRect&, SkRegion::Op); michael@0: bool op(const SkRect&, SkRegion::Op, bool doAA); michael@0: bool op(const SkAAClip&, SkRegion::Op); michael@0: michael@0: bool translate(int dx, int dy, SkAAClip* dst) const; michael@0: bool translate(int dx, int dy) { michael@0: return this->translate(dx, dy, this); michael@0: } michael@0: michael@0: /** michael@0: * Allocates a mask the size of the aaclip, and expands its data into michael@0: * the mask, using kA8_Format michael@0: */ michael@0: void copyToMask(SkMask*) const; michael@0: michael@0: // called internally michael@0: michael@0: bool quickContains(int left, int top, int right, int bottom) const; michael@0: bool quickContains(const SkIRect& r) const { michael@0: return this->quickContains(r.fLeft, r.fTop, r.fRight, r.fBottom); michael@0: } michael@0: michael@0: const uint8_t* findRow(int y, int* lastYForRow = NULL) const; michael@0: const uint8_t* findX(const uint8_t data[], int x, int* initialCount = NULL) const; michael@0: michael@0: class Iter; michael@0: struct RunHead; michael@0: struct YOffset; michael@0: class Builder; michael@0: michael@0: #ifdef SK_DEBUG michael@0: void validate() const; michael@0: #else michael@0: void validate() const {} michael@0: #endif michael@0: michael@0: private: michael@0: SkIRect fBounds; michael@0: RunHead* fRunHead; michael@0: michael@0: void freeRuns(); michael@0: bool trimBounds(); michael@0: bool trimTopBottom(); michael@0: bool trimLeftRight(); michael@0: michael@0: friend class Builder; michael@0: class BuilderBlitter; michael@0: friend class BuilderBlitter; michael@0: }; michael@0: michael@0: /////////////////////////////////////////////////////////////////////////////// michael@0: michael@0: class SkAAClipBlitter : public SkBlitter { michael@0: public: michael@0: SkAAClipBlitter() : fScanlineScratch(NULL) {} michael@0: virtual ~SkAAClipBlitter(); michael@0: michael@0: void init(SkBlitter* blitter, const SkAAClip* aaclip) { michael@0: SkASSERT(aaclip && !aaclip->isEmpty()); michael@0: fBlitter = blitter; michael@0: fAAClip = aaclip; michael@0: fAAClipBounds = aaclip->getBounds(); michael@0: } michael@0: michael@0: virtual void blitH(int x, int y, int width) SK_OVERRIDE; michael@0: virtual void blitAntiH(int x, int y, const SkAlpha[], michael@0: const int16_t runs[]) SK_OVERRIDE; michael@0: virtual void blitV(int x, int y, int height, SkAlpha alpha) SK_OVERRIDE; michael@0: virtual void blitRect(int x, int y, int width, int height) SK_OVERRIDE; michael@0: virtual void blitMask(const SkMask&, const SkIRect& clip) SK_OVERRIDE; michael@0: virtual const SkBitmap* justAnOpaqueColor(uint32_t* value) SK_OVERRIDE; michael@0: michael@0: private: michael@0: SkBlitter* fBlitter; michael@0: const SkAAClip* fAAClip; michael@0: SkIRect fAAClipBounds; michael@0: michael@0: // point into fScanlineScratch michael@0: int16_t* fRuns; michael@0: SkAlpha* fAA; michael@0: michael@0: enum { michael@0: kSize = 32 * 32 michael@0: }; michael@0: SkAutoSMalloc fGrayMaskScratch; // used for blitMask michael@0: void* fScanlineScratch; // enough for a mask at 32bit, or runs+aa michael@0: michael@0: void ensureRunsAndAA(); michael@0: }; michael@0: michael@0: #endif