blob: aacc5d25db20f40815d5ed6278058306e12c318b [file] [log] [blame]
reed@google.comac10a2d2010-12-22 21:39:39 +00001/*
epoger@google.comec3ed6a2011-07-28 14:26:00 +00002 * 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.
reed@google.comac10a2d2010-12-22 21:39:39 +00006 */
7
reed@google.comac10a2d2010-12-22 21:39:39 +00008#ifndef SkGr_DEFINED
9#define SkGr_DEFINED
10
bsalomonf276ac52015-10-09 13:36:42 -070011#include "GrColor.h"
joshualitt9bc39542015-08-12 12:57:54 -070012#include "GrTextureAccess.h"
bsalomonf276ac52015-10-09 13:36:42 -070013#include "SkColor.h"
14#include "SkColorPriv.h"
15#include "SkFilterQuality.h"
16#include "SkImageInfo.h"
reed@google.comac10a2d2010-12-22 21:39:39 +000017
bsalomonf276ac52015-10-09 13:36:42 -070018class GrContext;
19class GrTexture;
20class GrTextureParams;
21class SkBitmap;
reed@google.comac10a2d2010-12-22 21:39:39 +000022
reed@google.comac10a2d2010-12-22 21:39:39 +000023////////////////////////////////////////////////////////////////////////////////
24// Sk to Gr Type conversions
25
bsalomonf1b7a1d2015-09-28 06:26:28 -070026static inline GrColor SkColorToPremulGrColor(SkColor c) {
rileya@google.com24f3ad12012-07-18 21:47:40 +000027 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
bsalomonf1b7a1d2015-09-28 06:26:28 -070035static 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
43static 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. */
51static inline GrColor SkColorAlphaToGrColor(SkColor c) {
dandov9de5b512014-06-10 14:38:28 -070052 U8CPU a = SkColorGetA(c);
53 return GrColorPackRGBA(a, a, a, a);
54}
55
bsalomonae4738f2015-09-15 15:33:27 -070056static inline SkPMColor GrColorToSkPMColor(GrColor c) {
57 GrColorIsPMAssert(c);
58 return SkPackARGB32(GrColorUnpackA(c), GrColorUnpackR(c), GrColorUnpackG(c), GrColorUnpackB(c));
59}
60
61static inline GrColor SkPMColorToGrColor(SkPMColor c) {
62 return GrColorPackRGBA(SkGetPackedR32(c), SkGetPackedG32(c), SkGetPackedB32(c),
63 SkGetPackedA32(c));
64}
65
rileya@google.com24f3ad12012-07-18 21:47:40 +000066////////////////////////////////////////////////////////////////////////////////
bsalomon045802d2015-10-20 07:58:01 -070067/** 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. */
Brian Salomonbc0bcc02015-10-19 15:12:32 -040070GrTexture* GrRefCachedBitmapTexture(GrContext*, const SkBitmap&, const GrTextureParams&);
bsalomon045802d2015-10-20 07:58:01 -070071
bsalomonf276ac52015-10-09 13:36:42 -070072// TODO: Move SkImageInfo2GrPixelConfig to SkGrPriv.h (requires cleanup to SkWindow its subclasses).
73GrPixelConfig SkImageInfo2GrPixelConfig(SkColorType, SkAlphaType, SkColorProfileType);
74
75static inline GrPixelConfig SkImageInfo2GrPixelConfig(const SkImageInfo& info) {
76 return SkImageInfo2GrPixelConfig(info.colorType(), info.alphaType(), info.profileType());
77}
78
79GrTextureParams::FilterMode GrSkFilterQualityToGrFilterMode(SkFilterQuality paintFilterQuality,
80 const SkMatrix& viewM,
81 const SkMatrix& localM,
82 bool* doBicubic);
reed43fe6182015-09-08 08:37:36 -070083
reed@google.comac10a2d2010-12-22 21:39:39 +000084////////////////////////////////////////////////////////////////////////////////
commit-bot@chromium.org8dcff642014-05-15 20:32:48 +000085
reed8b26b992015-05-07 15:36:17 -070086SkImageInfo GrMakeInfoFromTexture(GrTexture* tex, int w, int h, bool isOpaque);
87
88// Using the dreaded SkGrPixelRef ...
bsalomoncb1ccfd2015-09-09 14:51:52 -070089SK_API void GrWrapTextureInBitmap(GrTexture* src, int w, int h, bool isOpaque,
90 SkBitmap* dst);
reed8b26b992015-05-07 15:36:17 -070091
reed@google.comac10a2d2010-12-22 21:39:39 +000092#endif