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