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 
     20 // skia headers
     21 #include "SkBitmap.h"
     22 #include "SkPath.h"
     23 #include "SkPoint.h"
     24 #include "SkRegion.h"
     25 #include "SkClipStack.h"
     26 
     27 ////////////////////////////////////////////////////////////////////////////////
     28 // Sk to Gr Type conversions
     29 
     30 GR_STATIC_ASSERT((int)kZero_GrBlendCoeff == (int)SkXfermode::kZero_Coeff);
     31 GR_STATIC_ASSERT((int)kOne_GrBlendCoeff  == (int)SkXfermode::kOne_Coeff);
     32 GR_STATIC_ASSERT((int)kSC_GrBlendCoeff   == (int)SkXfermode::kSC_Coeff);
     33 GR_STATIC_ASSERT((int)kISC_GrBlendCoeff  == (int)SkXfermode::kISC_Coeff);
     34 GR_STATIC_ASSERT((int)kDC_GrBlendCoeff   == (int)SkXfermode::kDC_Coeff);
     35 GR_STATIC_ASSERT((int)kIDC_GrBlendCoeff  == (int)SkXfermode::kIDC_Coeff);
     36 GR_STATIC_ASSERT((int)kSA_GrBlendCoeff   == (int)SkXfermode::kSA_Coeff);
     37 GR_STATIC_ASSERT((int)kISA_GrBlendCoeff  == (int)SkXfermode::kISA_Coeff);
     38 GR_STATIC_ASSERT((int)kDA_GrBlendCoeff   == (int)SkXfermode::kDA_Coeff);
     39 GR_STATIC_ASSERT((int)kIDA_GrBlendCoeff  == (int)SkXfermode::kIDA_Coeff);
     40 
     41 #define sk_blend_to_grblend(X) ((GrBlendCoeff)(X))
     42 
     43 ///////////////////////////////////////////////////////////////////////////////
     44 
     45 #include "SkColorPriv.h"
     46 
     47 GrPixelConfig SkImageInfo2GrPixelConfig(SkColorType, SkAlphaType);
     48 
     49 static inline GrPixelConfig SkImageInfo2GrPixelConfig(const SkImageInfo& info) {
     50     return SkImageInfo2GrPixelConfig(info.colorType(), info.alphaType());
     51 }
     52 
     53 bool GrPixelConfig2ColorType(GrPixelConfig, SkColorType*);
     54 
     55 static inline GrColor SkColor2GrColor(SkColor c) {
     56     SkPMColor pm = SkPreMultiplyColor(c);
     57     unsigned r = SkGetPackedR32(pm);
     58     unsigned g = SkGetPackedG32(pm);
     59     unsigned b = SkGetPackedB32(pm);
     60     unsigned a = SkGetPackedA32(pm);
     61     return GrColorPackRGBA(r, g, b, a);
     62 }
     63 
     64 static inline GrColor SkColor2GrColorJustAlpha(SkColor c) {
     65     U8CPU a = SkColorGetA(c);
     66     return GrColorPackRGBA(a, a, a, a);
     67 }
     68 
     69 ////////////////////////////////////////////////////////////////////////////////
     70 
     71 bool GrIsBitmapInCache(const GrContext*, const SkBitmap&, const GrTextureParams*);
     72 
     73 GrTexture* GrLockAndRefCachedBitmapTexture(GrContext*, const SkBitmap&, const GrTextureParams*);
     74 
     75 void GrUnlockAndUnrefCachedBitmapTexture(GrTexture*);
     76 
     77 ////////////////////////////////////////////////////////////////////////////////
     78 
     79 // Converts a SkPaint to a GrPaint, ignoring the SkPaint's shader.
     80 // Sets the color of GrPaint to the value of the parameter paintColor
     81 // Callers may subsequently modify the GrPaint. Setting constantColor indicates
     82 // that the final paint will draw the same color at every pixel. This allows
     83 // an optimization where the the color filter can be applied to the SkPaint's
     84 // color once while converting to GrPaint and then ignored.
     85 void SkPaint2GrPaintNoShader(GrContext* context, const SkPaint& skPaint, GrColor paintColor,
     86                              bool constantColor, GrPaint* grPaint);
     87 
     88 // This function is similar to skPaint2GrPaintNoShader but also converts
     89 // skPaint's shader to a GrTexture/GrProcessorStage if possible.
     90 // constantColor has the same meaning as in skPaint2GrPaintNoShader.
     91 void SkPaint2GrPaintShader(GrContext* context, const SkPaint& skPaint,
     92                            bool constantColor, GrPaint* grPaint);
     93 
     94 ////////////////////////////////////////////////////////////////////////////////
     95 // Classes
     96 
     97 class SkGlyphCache;
     98 
     99 ////////////////////////////////////////////////////////////////////////////////
    100 
    101 #endif
    102