gfx/skia/trunk/src/core/SkAAClip.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/gfx/skia/trunk/src/core/SkAAClip.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,132 @@
     1.4 +
     1.5 +/*
     1.6 + * Copyright 2011 Google Inc.
     1.7 + *
     1.8 + * Use of this source code is governed by a BSD-style license that can be
     1.9 + * found in the LICENSE file.
    1.10 + */
    1.11 +
    1.12 +#ifndef SkAAClip_DEFINED
    1.13 +#define SkAAClip_DEFINED
    1.14 +
    1.15 +#include "SkBlitter.h"
    1.16 +#include "SkRegion.h"
    1.17 +
    1.18 +class SkAAClip {
    1.19 +public:
    1.20 +    SkAAClip();
    1.21 +    SkAAClip(const SkAAClip&);
    1.22 +    ~SkAAClip();
    1.23 +
    1.24 +    SkAAClip& operator=(const SkAAClip&);
    1.25 +    friend bool operator==(const SkAAClip&, const SkAAClip&);
    1.26 +    friend bool operator!=(const SkAAClip& a, const SkAAClip& b) {
    1.27 +        return !(a == b);
    1.28 +    }
    1.29 +
    1.30 +    void swap(SkAAClip&);
    1.31 +
    1.32 +    bool isEmpty() const { return NULL == fRunHead; }
    1.33 +    const SkIRect& getBounds() const { return fBounds; }
    1.34 +
    1.35 +    bool setEmpty();
    1.36 +    bool setRect(const SkIRect&);
    1.37 +    bool setRect(const SkRect&, bool doAA = true);
    1.38 +    bool setPath(const SkPath&, const SkRegion* clip = NULL, bool doAA = true);
    1.39 +    bool setRegion(const SkRegion&);
    1.40 +    bool set(const SkAAClip&);
    1.41 +
    1.42 +    bool op(const SkAAClip&, const SkAAClip&, SkRegion::Op);
    1.43 +
    1.44 +    // Helpers for op()
    1.45 +    bool op(const SkIRect&, SkRegion::Op);
    1.46 +    bool op(const SkRect&, SkRegion::Op, bool doAA);
    1.47 +    bool op(const SkAAClip&, SkRegion::Op);
    1.48 +
    1.49 +    bool translate(int dx, int dy, SkAAClip* dst) const;
    1.50 +    bool translate(int dx, int dy) {
    1.51 +        return this->translate(dx, dy, this);
    1.52 +    }
    1.53 +
    1.54 +    /**
    1.55 +     *  Allocates a mask the size of the aaclip, and expands its data into
    1.56 +     *  the mask, using kA8_Format
    1.57 +     */
    1.58 +    void copyToMask(SkMask*) const;
    1.59 +
    1.60 +    // called internally
    1.61 +
    1.62 +    bool quickContains(int left, int top, int right, int bottom) const;
    1.63 +    bool quickContains(const SkIRect& r) const {
    1.64 +        return this->quickContains(r.fLeft, r.fTop, r.fRight, r.fBottom);
    1.65 +    }
    1.66 +
    1.67 +    const uint8_t* findRow(int y, int* lastYForRow = NULL) const;
    1.68 +    const uint8_t* findX(const uint8_t data[], int x, int* initialCount = NULL) const;
    1.69 +
    1.70 +    class Iter;
    1.71 +    struct RunHead;
    1.72 +    struct YOffset;
    1.73 +    class Builder;
    1.74 +
    1.75 +#ifdef SK_DEBUG
    1.76 +    void validate() const;
    1.77 +#else
    1.78 +    void validate() const {}
    1.79 +#endif
    1.80 +
    1.81 +private:
    1.82 +    SkIRect  fBounds;
    1.83 +    RunHead* fRunHead;
    1.84 +
    1.85 +    void freeRuns();
    1.86 +    bool trimBounds();
    1.87 +    bool trimTopBottom();
    1.88 +    bool trimLeftRight();
    1.89 +
    1.90 +    friend class Builder;
    1.91 +    class BuilderBlitter;
    1.92 +    friend class BuilderBlitter;
    1.93 +};
    1.94 +
    1.95 +///////////////////////////////////////////////////////////////////////////////
    1.96 +
    1.97 +class SkAAClipBlitter : public SkBlitter {
    1.98 +public:
    1.99 +    SkAAClipBlitter() : fScanlineScratch(NULL) {}
   1.100 +    virtual ~SkAAClipBlitter();
   1.101 +
   1.102 +    void init(SkBlitter* blitter, const SkAAClip* aaclip) {
   1.103 +        SkASSERT(aaclip && !aaclip->isEmpty());
   1.104 +        fBlitter = blitter;
   1.105 +        fAAClip = aaclip;
   1.106 +        fAAClipBounds = aaclip->getBounds();
   1.107 +    }
   1.108 +
   1.109 +    virtual void blitH(int x, int y, int width) SK_OVERRIDE;
   1.110 +    virtual void blitAntiH(int x, int y, const SkAlpha[],
   1.111 +                           const int16_t runs[]) SK_OVERRIDE;
   1.112 +    virtual void blitV(int x, int y, int height, SkAlpha alpha) SK_OVERRIDE;
   1.113 +    virtual void blitRect(int x, int y, int width, int height) SK_OVERRIDE;
   1.114 +    virtual void blitMask(const SkMask&, const SkIRect& clip) SK_OVERRIDE;
   1.115 +    virtual const SkBitmap* justAnOpaqueColor(uint32_t* value) SK_OVERRIDE;
   1.116 +
   1.117 +private:
   1.118 +    SkBlitter*      fBlitter;
   1.119 +    const SkAAClip* fAAClip;
   1.120 +    SkIRect         fAAClipBounds;
   1.121 +
   1.122 +    // point into fScanlineScratch
   1.123 +    int16_t*        fRuns;
   1.124 +    SkAlpha*        fAA;
   1.125 +
   1.126 +    enum {
   1.127 +        kSize = 32 * 32
   1.128 +    };
   1.129 +    SkAutoSMalloc<kSize> fGrayMaskScratch;  // used for blitMask
   1.130 +    void* fScanlineScratch;  // enough for a mask at 32bit, or runs+aa
   1.131 +
   1.132 +    void ensureRunsAndAA();
   1.133 +};
   1.134 +
   1.135 +#endif

mercurial