blob: edfcd6d813b9049bf69a7d16df015a7616c05e7d [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
brianosmana6359362016-03-21 06:55:37 -070018class GrCaps;
bsalomonf276ac52015-10-09 13:36:42 -070019class GrContext;
20class GrTexture;
21class GrTextureParams;
22class SkBitmap;
reed@google.comac10a2d2010-12-22 21:39:39 +000023
reed@google.comac10a2d2010-12-22 21:39:39 +000024////////////////////////////////////////////////////////////////////////////////
25// Sk to Gr Type conversions
26
bsalomonf1b7a1d2015-09-28 06:26:28 -070027static inline GrColor SkColorToPremulGrColor(SkColor c) {
rileya@google.com24f3ad12012-07-18 21:47:40 +000028 SkPMColor pm = SkPreMultiplyColor(c);
29 unsigned r = SkGetPackedR32(pm);
30 unsigned g = SkGetPackedG32(pm);
31 unsigned b = SkGetPackedB32(pm);
32 unsigned a = SkGetPackedA32(pm);
33 return GrColorPackRGBA(r, g, b, a);
34}
35
bsalomonf1b7a1d2015-09-28 06:26:28 -070036static inline GrColor SkColorToUnpremulGrColor(SkColor c) {
37 unsigned r = SkColorGetR(c);
38 unsigned g = SkColorGetG(c);
39 unsigned b = SkColorGetB(c);
40 unsigned a = SkColorGetA(c);
41 return GrColorPackRGBA(r, g, b, a);
42}
43
44static inline GrColor SkColorToOpaqueGrColor(SkColor c) {
45 unsigned r = SkColorGetR(c);
46 unsigned g = SkColorGetG(c);
47 unsigned b = SkColorGetB(c);
48 return GrColorPackRGBA(r, g, b, 0xFF);
49}
50
51/** Replicates the SkColor's alpha to all four channels of the GrColor. */
52static inline GrColor SkColorAlphaToGrColor(SkColor c) {
dandov9de5b512014-06-10 14:38:28 -070053 U8CPU a = SkColorGetA(c);
54 return GrColorPackRGBA(a, a, a, a);
55}
56
bsalomonae4738f2015-09-15 15:33:27 -070057static inline SkPMColor GrColorToSkPMColor(GrColor c) {
58 GrColorIsPMAssert(c);
59 return SkPackARGB32(GrColorUnpackA(c), GrColorUnpackR(c), GrColorUnpackG(c), GrColorUnpackB(c));
60}
61
62static inline GrColor SkPMColorToGrColor(SkPMColor c) {
63 return GrColorPackRGBA(SkGetPackedR32(c), SkGetPackedG32(c), SkGetPackedB32(c),
64 SkGetPackedA32(c));
65}
66
rileya@google.com24f3ad12012-07-18 21:47:40 +000067////////////////////////////////////////////////////////////////////////////////
bsalomon045802d2015-10-20 07:58:01 -070068/** Returns a texture representing the bitmap that is compatible with the GrTextureParams. The
69 texture is inserted into the cache (unless the bitmap is marked volatile) and can be
70 retrieved again via this function. */
brianosman982eb7f2016-06-06 13:10:58 -070071GrTexture* GrRefCachedBitmapTexture(GrContext*, const SkBitmap&, const GrTextureParams&,
72 SkSourceGammaTreatment);
bsalomon045802d2015-10-20 07:58:01 -070073
bsalomonf276ac52015-10-09 13:36:42 -070074// TODO: Move SkImageInfo2GrPixelConfig to SkGrPriv.h (requires cleanup to SkWindow its subclasses).
brianosmanab824182016-06-16 11:41:44 -070075GrPixelConfig SkImageInfo2GrPixelConfig(SkColorType, SkAlphaType, SkColorProfileType, const GrCaps&);
bsalomonf276ac52015-10-09 13:36:42 -070076
brianosmana6359362016-03-21 06:55:37 -070077static inline GrPixelConfig SkImageInfo2GrPixelConfig(const SkImageInfo& info, const GrCaps& caps) {
brianosmanab824182016-06-16 11:41:44 -070078 return SkImageInfo2GrPixelConfig(info.colorType(), info.alphaType(), info.profileType(), caps);
bsalomonf276ac52015-10-09 13:36:42 -070079}
80
81GrTextureParams::FilterMode GrSkFilterQualityToGrFilterMode(SkFilterQuality paintFilterQuality,
82 const SkMatrix& viewM,
83 const SkMatrix& localM,
84 bool* doBicubic);
reed43fe6182015-09-08 08:37:36 -070085
reed@google.comac10a2d2010-12-22 21:39:39 +000086////////////////////////////////////////////////////////////////////////////////
commit-bot@chromium.org8dcff642014-05-15 20:32:48 +000087
reed8b26b992015-05-07 15:36:17 -070088SkImageInfo GrMakeInfoFromTexture(GrTexture* tex, int w, int h, bool isOpaque);
89
90// Using the dreaded SkGrPixelRef ...
bsalomoncb1ccfd2015-09-09 14:51:52 -070091SK_API void GrWrapTextureInBitmap(GrTexture* src, int w, int h, bool isOpaque,
92 SkBitmap* dst);
reed8b26b992015-05-07 15:36:17 -070093
reed@google.comac10a2d2010-12-22 21:39:39 +000094#endif