Home | History | Annotate | Download | only in core
      1 /* libs/graphics/sgl/SkBlitter.h
      2 **
      3 ** Copyright 2006, The Android Open Source Project
      4 **
      5 ** Licensed under the Apache License, Version 2.0 (the "License");
      6 ** you may not use this file except in compliance with the License.
      7 ** You may obtain a copy of the License at
      8 **
      9 **     http://www.apache.org/licenses/LICENSE-2.0
     10 **
     11 ** Unless required by applicable law or agreed to in writing, software
     12 ** distributed under the License is distributed on an "AS IS" BASIS,
     13 ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     14 ** See the License for the specific language governing permissions and
     15 ** limitations under the License.
     16 */
     17 
     18 #ifndef SkBlitter_DEFINED
     19 #define SkBlitter_DEFINED
     20 
     21 #include "SkBitmap.h"
     22 #include "SkMatrix.h"
     23 #include "SkPaint.h"
     24 #include "SkRefCnt.h"
     25 #include "SkRegion.h"
     26 #include "SkMask.h"
     27 
     28 class SkBlitter {
     29 public:
     30     virtual ~SkBlitter();
     31 
     32     virtual void blitH(int x, int y, int width);
     33     virtual void blitAntiH(int x, int y, const SkAlpha[], const int16_t runs[]);
     34     virtual void blitV(int x, int y, int height, SkAlpha alpha);
     35     virtual void blitRect(int x, int y, int width, int height);
     36     virtual void blitMask(const SkMask&, const SkIRect& clip);
     37 
     38     /*  If the blitter just sets a single value for each pixel, return the
     39         bitmap it draws into, and assign value. If not, return NULL and ignore
     40         the value parameter.
     41     */
     42     virtual const SkBitmap* justAnOpaqueColor(uint32_t* value);
     43 
     44     // not virtual, just helpers
     45     void blitMaskRegion(const SkMask& mask, const SkRegion& clip);
     46     void blitRectRegion(const SkIRect& rect, const SkRegion& clip);
     47     void blitRegion(const SkRegion& clip);
     48 
     49     // factories
     50     static SkBlitter* Choose(const SkBitmap& device,
     51                              const SkMatrix& matrix,
     52                              const SkPaint& paint) {
     53         return Choose(device, matrix, paint, NULL, 0);
     54     }
     55 
     56     static SkBlitter* Choose(const SkBitmap& device,
     57                              const SkMatrix& matrix,
     58                              const SkPaint& paint,
     59                              void* storage, size_t storageSize);
     60 
     61     static SkBlitter* ChooseSprite(const SkBitmap& device,
     62                                    const SkPaint&,
     63                                    const SkBitmap& src,
     64                                    int left, int top,
     65                                    void* storage, size_t storageSize);
     66 
     67 private:
     68 };
     69 
     70 /** This blitter silently never draws anything.
     71 */
     72 class SkNullBlitter : public SkBlitter {
     73 public:
     74     virtual void blitH(int x, int y, int width);
     75     virtual void blitAntiH(int x, int y, const SkAlpha[], const int16_t runs[]);
     76     virtual void blitV(int x, int y, int height, SkAlpha alpha);
     77     virtual void blitRect(int x, int y, int width, int height);
     78     virtual void blitMask(const SkMask&, const SkIRect& clip);
     79     virtual const SkBitmap* justAnOpaqueColor(uint32_t* value);
     80 };
     81 
     82 /** Wraps another (real) blitter, and ensures that the real blitter is only
     83     called with coordinates that have been clipped by the specified clipRect.
     84     This means the caller need not perform the clipping ahead of time.
     85 */
     86 class SkRectClipBlitter : public SkBlitter {
     87 public:
     88     void init(SkBlitter* blitter, const SkIRect& clipRect) {
     89         SkASSERT(!clipRect.isEmpty());
     90         fBlitter = blitter;
     91         fClipRect = clipRect;
     92     }
     93 
     94     // overrides
     95     virtual void blitH(int x, int y, int width);
     96     virtual void blitAntiH(int x, int y, const SkAlpha[], const int16_t runs[]);
     97     virtual void blitV(int x, int y, int height, SkAlpha alpha);
     98     virtual void blitRect(int x, int y, int width, int height);
     99     virtual void blitMask(const SkMask&, const SkIRect& clip);
    100     virtual const SkBitmap* justAnOpaqueColor(uint32_t* value);
    101 
    102 private:
    103     SkBlitter*  fBlitter;
    104     SkIRect     fClipRect;
    105 };
    106 
    107 /** Wraps another (real) blitter, and ensures that the real blitter is only
    108 called with coordinates that have been clipped by the specified clipRgn.
    109 This means the caller need not perform the clipping ahead of time.
    110 */
    111 class SkRgnClipBlitter : public SkBlitter {
    112 public:
    113     void init(SkBlitter* blitter, const SkRegion* clipRgn) {
    114         SkASSERT(clipRgn && !clipRgn->isEmpty());
    115         fBlitter = blitter;
    116         fRgn = clipRgn;
    117     }
    118 
    119     // overrides
    120     virtual void blitH(int x, int y, int width);
    121     virtual void blitAntiH(int x, int y, const SkAlpha[], const int16_t runs[]);
    122     virtual void blitV(int x, int y, int height, SkAlpha alpha);
    123     virtual void blitRect(int x, int y, int width, int height);
    124     virtual void blitMask(const SkMask&, const SkIRect& clip);
    125     virtual const SkBitmap* justAnOpaqueColor(uint32_t* value);
    126 
    127 private:
    128     SkBlitter*      fBlitter;
    129     const SkRegion* fRgn;
    130 };
    131 
    132 class SkBlitterClipper {
    133 public:
    134     SkBlitter*  apply(SkBlitter* blitter, const SkRegion* clip,
    135                       const SkIRect* bounds = NULL);
    136 
    137 private:
    138     SkNullBlitter       fNullBlitter;
    139     SkRectClipBlitter   fRectBlitter;
    140     SkRgnClipBlitter    fRgnBlitter;
    141 };
    142 
    143 #endif
    144