Home | History | Annotate | Download | only in core
      1 /* libs/graphics/sgl/SkCoreBlitters.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 SkCoreBlitters_DEFINED
     19 #define SkCoreBlitters_DEFINED
     20 
     21 #include "SkBlitter.h"
     22 #include "SkBlitRow.h"
     23 
     24 class SkRasterBlitter : public SkBlitter {
     25 public:
     26     SkRasterBlitter(const SkBitmap& device) : fDevice(device) {}
     27 
     28 protected:
     29     const SkBitmap& fDevice;
     30 
     31 private:
     32     typedef SkBlitter INHERITED;
     33 };
     34 
     35 class SkShaderBlitter : public SkRasterBlitter {
     36 public:
     37     SkShaderBlitter(const SkBitmap& device, const SkPaint& paint);
     38     virtual ~SkShaderBlitter();
     39 
     40 protected:
     41     uint32_t    fShaderFlags;
     42     SkShader*   fShader;
     43 
     44 private:
     45     // illegal
     46     SkShaderBlitter& operator=(const SkShaderBlitter&);
     47 
     48     typedef SkRasterBlitter INHERITED;
     49 };
     50 
     51 ///////////////////////////////////////////////////////////////////////////////
     52 
     53 class SkA8_Blitter : public SkRasterBlitter {
     54 public:
     55     SkA8_Blitter(const SkBitmap& device, const SkPaint& paint);
     56     virtual void blitH(int x, int y, int width);
     57     virtual void blitAntiH(int x, int y, const SkAlpha antialias[], const int16_t runs[]);
     58     virtual void blitV(int x, int y, int height, SkAlpha alpha);
     59     virtual void blitRect(int x, int y, int width, int height);
     60     virtual void blitMask(const SkMask&, const SkIRect&);
     61     virtual const SkBitmap* justAnOpaqueColor(uint32_t*);
     62 
     63 private:
     64     unsigned fSrcA;
     65 
     66     // illegal
     67     SkA8_Blitter& operator=(const SkA8_Blitter&);
     68 
     69     typedef SkRasterBlitter INHERITED;
     70 };
     71 
     72 class SkA8_Shader_Blitter : public SkShaderBlitter {
     73 public:
     74     SkA8_Shader_Blitter(const SkBitmap& device, const SkPaint& paint);
     75     virtual ~SkA8_Shader_Blitter();
     76     virtual void blitH(int x, int y, int width);
     77     virtual void blitAntiH(int x, int y, const SkAlpha antialias[], const int16_t runs[]);
     78     virtual void blitMask(const SkMask&, const SkIRect&);
     79 
     80 private:
     81     SkXfermode* fXfermode;
     82     SkPMColor*  fBuffer;
     83     uint8_t*    fAAExpand;
     84 
     85     // illegal
     86     SkA8_Shader_Blitter& operator=(const SkA8_Shader_Blitter&);
     87 
     88     typedef SkShaderBlitter INHERITED;
     89 };
     90 
     91 ////////////////////////////////////////////////////////////////
     92 
     93 class SkARGB32_Blitter : public SkRasterBlitter {
     94 public:
     95     SkARGB32_Blitter(const SkBitmap& device, const SkPaint& paint);
     96     virtual void blitH(int x, int y, int width);
     97     virtual void blitAntiH(int x, int y, const SkAlpha antialias[], const int16_t runs[]);
     98     virtual void blitV(int x, int y, int height, SkAlpha alpha);
     99     virtual void blitRect(int x, int y, int width, int height);
    100     virtual void blitMask(const SkMask&, const SkIRect&);
    101     virtual const SkBitmap* justAnOpaqueColor(uint32_t*);
    102 
    103 protected:
    104     SkColor fPMColor;
    105 
    106 private:
    107     unsigned fSrcA, fSrcR, fSrcG, fSrcB;
    108 
    109     // illegal
    110     SkARGB32_Blitter& operator=(const SkARGB32_Blitter&);
    111 
    112     typedef SkRasterBlitter INHERITED;
    113 };
    114 
    115 class SkARGB32_Opaque_Blitter : public SkARGB32_Blitter {
    116 public:
    117     SkARGB32_Opaque_Blitter(const SkBitmap& device, const SkPaint& paint)
    118         : INHERITED(device, paint) { SkASSERT(paint.getAlpha() == 0xFF); }
    119     virtual void blitMask(const SkMask&, const SkIRect&);
    120 
    121 private:
    122     typedef SkARGB32_Blitter INHERITED;
    123 };
    124 
    125 class SkARGB32_Black_Blitter : public SkARGB32_Opaque_Blitter {
    126 public:
    127     SkARGB32_Black_Blitter(const SkBitmap& device, const SkPaint& paint)
    128         : INHERITED(device, paint) {}
    129     virtual void blitMask(const SkMask&, const SkIRect&);
    130     virtual void blitAntiH(int x, int y, const SkAlpha antialias[], const int16_t runs[]);
    131 
    132 private:
    133     typedef SkARGB32_Opaque_Blitter INHERITED;
    134 };
    135 
    136 class SkARGB32_Shader_Blitter : public SkShaderBlitter {
    137 public:
    138     SkARGB32_Shader_Blitter(const SkBitmap& device, const SkPaint& paint);
    139     virtual ~SkARGB32_Shader_Blitter();
    140     virtual void blitH(int x, int y, int width);
    141     virtual void blitAntiH(int x, int y, const SkAlpha antialias[], const int16_t runs[]);
    142 
    143 private:
    144     SkXfermode*         fXfermode;
    145     SkPMColor*          fBuffer;
    146     SkBlitRow::Proc32   fProc32;
    147     SkBlitRow::Proc32   fProc32Blend;
    148 
    149     // illegal
    150     SkARGB32_Shader_Blitter& operator=(const SkARGB32_Shader_Blitter&);
    151 
    152     typedef SkShaderBlitter INHERITED;
    153 };
    154 
    155 ///////////////////////////////////////////////////////////////////////////////
    156 
    157 class SkA1_Blitter : public SkRasterBlitter {
    158 public:
    159     SkA1_Blitter(const SkBitmap& device, const SkPaint& paint);
    160     virtual void blitH(int x, int y, int width);
    161 
    162 private:
    163     uint8_t fSrcA;
    164 
    165     // illegal
    166     SkA1_Blitter& operator=(const SkA1_Blitter&);
    167 
    168     typedef SkRasterBlitter INHERITED;
    169 };
    170 
    171 ///////////////////////////////////////////////////////////////////////////////
    172 
    173 /*  These return the correct subclass of blitter for their device config.
    174 
    175     Currently, they make the following assumptions about the state of the
    176     paint:
    177 
    178     1. If there is an xfermode, there will also be a shader
    179     2. If there is a colorfilter, there will be a shader that itself handles
    180        calling the filter, so the blitter can always ignore the colorfilter obj
    181 
    182     These pre-conditions must be handled by the caller, in our case
    183     SkBlitter::Choose(...)
    184  */
    185 
    186 extern SkBlitter* SkBlitter_ChooseD4444(const SkBitmap& device,
    187                                         const SkPaint& paint,
    188                                         void* storage, size_t storageSize);
    189 
    190 extern SkBlitter* SkBlitter_ChooseD565(const SkBitmap& device,
    191                                        const SkPaint& paint,
    192                                        void* storage, size_t storageSize);
    193 
    194 #endif
    195 
    196