Home | History | Annotate | Download | only in gpu
      1 
      2 /*
      3  * Copyright 2010 Google Inc.
      4  *
      5  * Use of this source code is governed by a BSD-style license that can be
      6  * found in the LICENSE file.
      7  */
      8 
      9 
     10 
     11 #ifndef SkGr_DEFINED
     12 #define SkGr_DEFINED
     13 
     14 #include <stddef.h>
     15 
     16 // Gr headers
     17 #include "GrTypes.h"
     18 #include "GrContext.h"
     19 #include "GrFontScaler.h"
     20 
     21 // skia headers
     22 #include "SkBitmap.h"
     23 #include "SkPath.h"
     24 #include "SkPoint.h"
     25 #include "SkRegion.h"
     26 #include "SkClipStack.h"
     27 
     28 ////////////////////////////////////////////////////////////////////////////////
     29 // Sk to Gr Type conversions
     30 
     31 GR_STATIC_ASSERT((int)kZero_GrBlendCoeff == (int)SkXfermode::kZero_Coeff);
     32 GR_STATIC_ASSERT((int)kOne_GrBlendCoeff  == (int)SkXfermode::kOne_Coeff);
     33 GR_STATIC_ASSERT((int)kSC_GrBlendCoeff   == (int)SkXfermode::kSC_Coeff);
     34 GR_STATIC_ASSERT((int)kISC_GrBlendCoeff  == (int)SkXfermode::kISC_Coeff);
     35 GR_STATIC_ASSERT((int)kDC_GrBlendCoeff   == (int)SkXfermode::kDC_Coeff);
     36 GR_STATIC_ASSERT((int)kIDC_GrBlendCoeff  == (int)SkXfermode::kIDC_Coeff);
     37 GR_STATIC_ASSERT((int)kSA_GrBlendCoeff   == (int)SkXfermode::kSA_Coeff);
     38 GR_STATIC_ASSERT((int)kISA_GrBlendCoeff  == (int)SkXfermode::kISA_Coeff);
     39 GR_STATIC_ASSERT((int)kDA_GrBlendCoeff   == (int)SkXfermode::kDA_Coeff);
     40 GR_STATIC_ASSERT((int)kIDA_GrBlendCoeff  == (int)SkXfermode::kIDA_Coeff);
     41 
     42 #define sk_blend_to_grblend(X) ((GrBlendCoeff)(X))
     43 
     44 ///////////////////////////////////////////////////////////////////////////////
     45 
     46 #include "SkColorPriv.h"
     47 
     48 #ifdef SK_SUPPORT_LEGACY_BITMAP_CONFIG
     49 /**
     50  *  Convert the SkBitmap::Config to the corresponding PixelConfig, or
     51  *  kUnknown_PixelConfig if the conversion cannot be done.
     52  */
     53 GrPixelConfig SkBitmapConfig2GrPixelConfig(SkBitmap::Config);
     54 #endif
     55 GrPixelConfig SkImageInfo2GrPixelConfig(SkColorType, SkAlphaType);
     56 
     57 static inline GrPixelConfig SkImageInfo2GrPixelConfig(const SkImageInfo& info) {
     58     return SkImageInfo2GrPixelConfig(info.colorType(), info.alphaType());
     59 }
     60 
     61 bool GrPixelConfig2ColorType(GrPixelConfig, SkColorType*);
     62 
     63 static inline GrColor SkColor2GrColor(SkColor c) {
     64     SkPMColor pm = SkPreMultiplyColor(c);
     65     unsigned r = SkGetPackedR32(pm);
     66     unsigned g = SkGetPackedG32(pm);
     67     unsigned b = SkGetPackedB32(pm);
     68     unsigned a = SkGetPackedA32(pm);
     69     return GrColorPackRGBA(r, g, b, a);
     70 }
     71 
     72 static inline GrColor SkColor2GrColorJustAlpha(SkColor c) {
     73     U8CPU a = SkColorGetA(c);
     74     return GrColorPackRGBA(a, a, a, a);
     75 }
     76 
     77 ////////////////////////////////////////////////////////////////////////////////
     78 
     79 bool GrIsBitmapInCache(const GrContext*, const SkBitmap&, const GrTextureParams*);
     80 
     81 GrTexture* GrLockAndRefCachedBitmapTexture(GrContext*, const SkBitmap&, const GrTextureParams*);
     82 
     83 void GrUnlockAndUnrefCachedBitmapTexture(GrTexture*);
     84 
     85 ////////////////////////////////////////////////////////////////////////////////
     86 
     87 // Converts a SkPaint to a GrPaint, ignoring the SkPaint's shader.
     88 // Sets the color of GrPaint to the value of the parameter grColor
     89 // Callers may subsequently modify the GrPaint. Setting constantColor indicates
     90 // that the final paint will draw the same color at every pixel. This allows
     91 // an optimization where the the color filter can be applied to the SkPaint's
     92 // color once while converting to GrPaint and then ignored.
     93 void SkPaint2GrPaintNoShader(GrContext* context, const SkPaint& skPaint, GrColor grColor,
     94                              bool constantColor, GrPaint* grPaint);
     95 
     96 // This function is similar to skPaint2GrPaintNoShader but also converts
     97 // skPaint's shader to a GrTexture/GrEffectStage if possible.
     98 // constantColor has the same meaning as in skPaint2GrPaintNoShader.
     99 void SkPaint2GrPaintShader(GrContext* context, const SkPaint& skPaint,
    100                            bool constantColor, GrPaint* grPaint);
    101 
    102 ////////////////////////////////////////////////////////////////////////////////
    103 // Classes
    104 
    105 class SkGlyphCache;
    106 
    107 class SkGrFontScaler : public GrFontScaler {
    108 public:
    109     explicit SkGrFontScaler(SkGlyphCache* strike);
    110     virtual ~SkGrFontScaler();
    111 
    112     // overrides
    113     virtual const GrKey* getKey();
    114     virtual GrMaskFormat getMaskFormat();
    115     virtual bool getPackedGlyphBounds(GrGlyph::PackedID, SkIRect* bounds) SK_OVERRIDE;
    116     virtual bool getPackedGlyphImage(GrGlyph::PackedID, int width, int height,
    117                                      int rowBytes, void* image) SK_OVERRIDE;
    118     virtual bool getPackedGlyphDFBounds(GrGlyph::PackedID, SkIRect* bounds) SK_OVERRIDE;
    119     virtual bool getPackedGlyphDFImage(GrGlyph::PackedID, int width, int height,
    120                                        void* image) SK_OVERRIDE;
    121     virtual bool getGlyphPath(uint16_t glyphID, SkPath*);
    122 
    123 private:
    124     SkGlyphCache* fStrike;
    125     GrKey*  fKey;
    126 //    DECLARE_INSTANCE_COUNTER(SkGrFontScaler);
    127 };
    128 
    129 ////////////////////////////////////////////////////////////////////////////////
    130 
    131 #endif
    132