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 30GR_STATIC_ASSERT((int)kZero_GrBlendCoeff == (int)SkXfermode::kZero_Coeff); 31GR_STATIC_ASSERT((int)kOne_GrBlendCoeff == (int)SkXfermode::kOne_Coeff); 32GR_STATIC_ASSERT((int)kSC_GrBlendCoeff == (int)SkXfermode::kSC_Coeff); 33GR_STATIC_ASSERT((int)kISC_GrBlendCoeff == (int)SkXfermode::kISC_Coeff); 34GR_STATIC_ASSERT((int)kDC_GrBlendCoeff == (int)SkXfermode::kDC_Coeff); 35GR_STATIC_ASSERT((int)kIDC_GrBlendCoeff == (int)SkXfermode::kIDC_Coeff); 36GR_STATIC_ASSERT((int)kSA_GrBlendCoeff == (int)SkXfermode::kSA_Coeff); 37GR_STATIC_ASSERT((int)kISA_GrBlendCoeff == (int)SkXfermode::kISA_Coeff); 38GR_STATIC_ASSERT((int)kDA_GrBlendCoeff == (int)SkXfermode::kDA_Coeff); 39GR_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 47GrPixelConfig SkImageInfo2GrPixelConfig(SkColorType, SkAlphaType, SkColorProfileType); 48 49static inline GrPixelConfig SkImageInfo2GrPixelConfig(const SkImageInfo& info) { 50 return SkImageInfo2GrPixelConfig(info.colorType(), info.alphaType(), info.profileType()); 51} 52 53bool GrPixelConfig2ColorAndProfileType(GrPixelConfig, SkColorType*, SkColorProfileType*); 54 55static 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 64static inline GrColor SkColor2GrColorJustAlpha(SkColor c) { 65 U8CPU a = SkColorGetA(c); 66 return GrColorPackRGBA(a, a, a, a); 67} 68 69//////////////////////////////////////////////////////////////////////////////// 70 71bool GrIsBitmapInCache(const GrContext*, const SkBitmap&, const GrTextureParams*); 72 73GrTexture* GrRefCachedBitmapTexture(GrContext*, const SkBitmap&, const GrTextureParams*); 74 75//////////////////////////////////////////////////////////////////////////////// 76 77// Converts a SkPaint to a GrPaint, ignoring the SkPaint's shader. 78// Sets the color of GrPaint to the value of the parameter paintColor 79// Callers may subsequently modify the GrPaint. Setting constantColor indicates 80// that the final paint will draw the same color at every pixel. This allows 81// an optimization where the color filter can be applied to the SkPaint's 82// color once while converting to GrPaint and then ignored. TODO: Remove this 83// bool and use the invariant info to automatically apply the color filter. 84bool SkPaint2GrPaintNoShader(GrContext* context, GrRenderTarget*, const SkPaint& skPaint, 85 GrColor paintColor, bool constantColor, GrPaint* grPaint); 86 87// This function is similar to skPaint2GrPaintNoShader but also converts 88// skPaint's shader to a GrFragmentProcessor if possible. 89// constantColor has the same meaning as in skPaint2GrPaintNoShader. 90bool SkPaint2GrPaint(GrContext* context, GrRenderTarget*, const SkPaint& skPaint, 91 const SkMatrix& viewM, bool constantColor, GrPaint* grPaint); 92 93 94SkImageInfo GrMakeInfoFromTexture(GrTexture* tex, int w, int h, bool isOpaque); 95 96// Using the dreaded SkGrPixelRef ... 97void GrWrapTextureInBitmap(GrTexture* src, int w, int h, bool isOpaque, SkBitmap* dst); 98 99//////////////////////////////////////////////////////////////////////////////// 100// Classes 101 102class SkGlyphCache; 103 104//////////////////////////////////////////////////////////////////////////////// 105 106#endif 107