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 #if (GR_DEBUG && defined(SK_RELEASE)) || (GR_RELEASE && defined(SK_DEBUG))
     29 //    #error "inconsistent GR_DEBUG and SK_DEBUG"
     30 #endif
     31 
     32 ////////////////////////////////////////////////////////////////////////////////
     33 // Sk to Gr Type conversions
     34 
     35 GR_STATIC_ASSERT((int)kZero_GrBlendCoeff == (int)SkXfermode::kZero_Coeff);
     36 GR_STATIC_ASSERT((int)kOne_GrBlendCoeff  == (int)SkXfermode::kOne_Coeff);
     37 GR_STATIC_ASSERT((int)kSC_GrBlendCoeff   == (int)SkXfermode::kSC_Coeff);
     38 GR_STATIC_ASSERT((int)kISC_GrBlendCoeff  == (int)SkXfermode::kISC_Coeff);
     39 GR_STATIC_ASSERT((int)kDC_GrBlendCoeff   == (int)SkXfermode::kDC_Coeff);
     40 GR_STATIC_ASSERT((int)kIDC_GrBlendCoeff  == (int)SkXfermode::kIDC_Coeff);
     41 GR_STATIC_ASSERT((int)kSA_GrBlendCoeff   == (int)SkXfermode::kSA_Coeff);
     42 GR_STATIC_ASSERT((int)kISA_GrBlendCoeff  == (int)SkXfermode::kISA_Coeff);
     43 GR_STATIC_ASSERT((int)kDA_GrBlendCoeff   == (int)SkXfermode::kDA_Coeff);
     44 GR_STATIC_ASSERT((int)kIDA_GrBlendCoeff  == (int)SkXfermode::kIDA_Coeff);
     45 
     46 #define sk_blend_to_grblend(X) ((GrBlendCoeff)(X))
     47 
     48 GR_STATIC_ASSERT((int)SkPath::kMove_Verb  == (int)kMove_PathCmd);
     49 GR_STATIC_ASSERT((int)SkPath::kLine_Verb  == (int)kLine_PathCmd);
     50 GR_STATIC_ASSERT((int)SkPath::kQuad_Verb  == (int)kQuadratic_PathCmd);
     51 GR_STATIC_ASSERT((int)SkPath::kCubic_Verb == (int)kCubic_PathCmd);
     52 GR_STATIC_ASSERT((int)SkPath::kClose_Verb == (int)kClose_PathCmd);
     53 GR_STATIC_ASSERT((int)SkPath::kDone_Verb  == (int)kEnd_PathCmd);
     54 
     55 #define sk_path_verb_to_gr_path_command(X) ((GrPathCmd)(X))
     56 
     57 ///////////////////////////////////////////////////////////////////////////////
     58 
     59 #include "SkColorPriv.h"
     60 
     61 /**
     62  *  Convert the SkBitmap::Config to the corresponding PixelConfig, or
     63  *  kUnknown_PixelConfig if the conversion cannot be done.
     64  */
     65 GrPixelConfig SkBitmapConfig2GrPixelConfig(SkBitmap::Config);
     66 
     67 static inline GrColor SkColor2GrColor(SkColor c) {
     68     SkPMColor pm = SkPreMultiplyColor(c);
     69     unsigned r = SkGetPackedR32(pm);
     70     unsigned g = SkGetPackedG32(pm);
     71     unsigned b = SkGetPackedB32(pm);
     72     unsigned a = SkGetPackedA32(pm);
     73     return GrColorPackRGBA(r, g, b, a);
     74 }
     75 
     76 ////////////////////////////////////////////////////////////////////////////////
     77 
     78 bool GrIsBitmapInCache(const GrContext*, const SkBitmap&, const GrTextureParams*);
     79 
     80 GrTexture* GrLockAndRefCachedBitmapTexture(GrContext*, const SkBitmap&, const GrTextureParams*);
     81 
     82 void GrUnlockAndUnrefCachedBitmapTexture(GrTexture*);
     83 
     84 ////////////////////////////////////////////////////////////////////////////////
     85 // Classes
     86 
     87 class SkGlyphCache;
     88 
     89 class SkGrFontScaler : public GrFontScaler {
     90 public:
     91     explicit SkGrFontScaler(SkGlyphCache* strike);
     92     virtual ~SkGrFontScaler();
     93 
     94     // overrides
     95     virtual const GrKey* getKey();
     96     virtual GrMaskFormat getMaskFormat();
     97     virtual bool getPackedGlyphBounds(GrGlyph::PackedID, GrIRect* bounds);
     98     virtual bool getPackedGlyphImage(GrGlyph::PackedID, int width, int height,
     99                                      int rowBytes, void* image);
    100     virtual bool getGlyphPath(uint16_t glyphID, SkPath*);
    101 
    102 private:
    103     SkGlyphCache* fStrike;
    104     GrKey*  fKey;
    105 //    DECLARE_INSTANCE_COUNTER(SkGrFontScaler);
    106 };
    107 
    108 ////////////////////////////////////////////////////////////////////////////////
    109 
    110 #endif
    111