• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2010 Google Inc.
3  *
4  * Use of this source code is governed by a BSD-style license that can be
5  * found in the LICENSE file.
6  */
7 
8 #ifndef SkGr_DEFINED
9 #define SkGr_DEFINED
10 
11 #include "GrColor.h"
12 #include "GrTextureAccess.h"
13 #include "SkColor.h"
14 #include "SkColorPriv.h"
15 #include "SkFilterQuality.h"
16 #include "SkImageInfo.h"
17 
18 class GrContext;
19 class GrTexture;
20 class GrTextureParams;
21 class SkBitmap;
22 
23 ////////////////////////////////////////////////////////////////////////////////
24 // Sk to Gr Type conversions
25 
SkColorToPremulGrColor(SkColor c)26 static inline GrColor SkColorToPremulGrColor(SkColor c) {
27     SkPMColor pm = SkPreMultiplyColor(c);
28     unsigned r = SkGetPackedR32(pm);
29     unsigned g = SkGetPackedG32(pm);
30     unsigned b = SkGetPackedB32(pm);
31     unsigned a = SkGetPackedA32(pm);
32     return GrColorPackRGBA(r, g, b, a);
33 }
34 
SkColorToUnpremulGrColor(SkColor c)35 static inline GrColor SkColorToUnpremulGrColor(SkColor c) {
36     unsigned r = SkColorGetR(c);
37     unsigned g = SkColorGetG(c);
38     unsigned b = SkColorGetB(c);
39     unsigned a = SkColorGetA(c);
40     return GrColorPackRGBA(r, g, b, a);
41 }
42 
SkColorToOpaqueGrColor(SkColor c)43 static inline GrColor SkColorToOpaqueGrColor(SkColor c) {
44     unsigned r = SkColorGetR(c);
45     unsigned g = SkColorGetG(c);
46     unsigned b = SkColorGetB(c);
47     return GrColorPackRGBA(r, g, b, 0xFF);
48 }
49 
50 /** Replicates the SkColor's alpha to all four channels of the GrColor. */
SkColorAlphaToGrColor(SkColor c)51 static inline GrColor SkColorAlphaToGrColor(SkColor c) {
52     U8CPU a = SkColorGetA(c);
53     return GrColorPackRGBA(a, a, a, a);
54 }
55 
GrColorToSkPMColor(GrColor c)56 static inline SkPMColor GrColorToSkPMColor(GrColor c) {
57     GrColorIsPMAssert(c);
58     return SkPackARGB32(GrColorUnpackA(c), GrColorUnpackR(c), GrColorUnpackG(c), GrColorUnpackB(c));
59 }
60 
SkPMColorToGrColor(SkPMColor c)61 static inline GrColor SkPMColorToGrColor(SkPMColor c) {
62     return GrColorPackRGBA(SkGetPackedR32(c), SkGetPackedG32(c), SkGetPackedB32(c),
63                            SkGetPackedA32(c));
64 }
65 
66 ////////////////////////////////////////////////////////////////////////////////
67 /** Returns a texture representing the bitmap that is compatible with the GrTextureParams. The
68     texture is inserted into the cache (unless the bitmap is marked volatile) and can be
69     retrieved again via this function. */
70 GrTexture* GrRefCachedBitmapTexture(GrContext*, const SkBitmap&, const GrTextureParams&);
71 
72 // TODO: Move SkImageInfo2GrPixelConfig to SkGrPriv.h (requires cleanup to SkWindow its subclasses).
73 GrPixelConfig SkImageInfo2GrPixelConfig(SkColorType, SkAlphaType, SkColorProfileType);
74 
SkImageInfo2GrPixelConfig(const SkImageInfo & info)75 static inline GrPixelConfig SkImageInfo2GrPixelConfig(const SkImageInfo& info) {
76     return SkImageInfo2GrPixelConfig(info.colorType(), info.alphaType(), info.profileType());
77 }
78 
79 GrTextureParams::FilterMode GrSkFilterQualityToGrFilterMode(SkFilterQuality paintFilterQuality,
80                                                             const SkMatrix& viewM,
81                                                             const SkMatrix& localM,
82                                                             bool* doBicubic);
83 
84 ////////////////////////////////////////////////////////////////////////////////
85 
86 SkImageInfo GrMakeInfoFromTexture(GrTexture* tex, int w, int h, bool isOpaque);
87 
88 // Using the dreaded SkGrPixelRef ...
89 SK_API void GrWrapTextureInBitmap(GrTexture* src, int w, int h, bool isOpaque,
90                                   SkBitmap* dst);
91 
92 #endif
93