blob: 7aacea4059f29a1c99c040c2228c385a59e88cb3 [file] [log] [blame]
epoger@google.comec3ed6a2011-07-28 14:26:00 +00001
reed@google.comac10a2d2010-12-22 21:39:39 +00002/*
epoger@google.comec3ed6a2011-07-28 14:26:00 +00003 * 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.
reed@google.comac10a2d2010-12-22 21:39:39 +00007 */
8
9
epoger@google.comec3ed6a2011-07-28 14:26:00 +000010
reed@google.comac10a2d2010-12-22 21:39:39 +000011#ifndef SkGr_DEFINED
12#define SkGr_DEFINED
13
14#include <stddef.h>
15
bsalomon@google.comd302f142011-03-03 13:54:13 +000016// Gr headers
bsalomon@google.com6a2134e2011-11-23 21:33:11 +000017#include "GrTypes.h"
reed@google.comac10a2d2010-12-22 21:39:39 +000018#include "GrContext.h"
reed@google.comac10a2d2010-12-22 21:39:39 +000019
20// skia headers
21#include "SkBitmap.h"
22#include "SkPath.h"
23#include "SkPoint.h"
24#include "SkRegion.h"
bsalomon@google.comd302f142011-03-03 13:54:13 +000025#include "SkClipStack.h"
reed@google.comac10a2d2010-12-22 21:39:39 +000026
reed@google.comac10a2d2010-12-22 21:39:39 +000027////////////////////////////////////////////////////////////////////////////////
28// Sk to Gr Type conversions
29
bsalomon@google.com47059542012-06-06 20:51:20 +000030GR_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);
reed@google.comac10a2d2010-12-22 21:39:39 +000040
bsalomon@google.comffca4002011-02-22 20:34:01 +000041#define sk_blend_to_grblend(X) ((GrBlendCoeff)(X))
reed@google.comac10a2d2010-12-22 21:39:39 +000042
reed@google.comac10a2d2010-12-22 21:39:39 +000043///////////////////////////////////////////////////////////////////////////////
44
45#include "SkColorPriv.h"
46
commit-bot@chromium.org15a14052014-02-16 00:59:25 +000047GrPixelConfig SkImageInfo2GrPixelConfig(SkColorType, SkAlphaType);
commit-bot@chromium.org3adcc342014-04-23 19:18:09 +000048
49static inline GrPixelConfig SkImageInfo2GrPixelConfig(const SkImageInfo& info) {
50 return SkImageInfo2GrPixelConfig(info.colorType(), info.alphaType());
51}
52
reed@google.combf790232013-12-13 19:45:58 +000053bool GrPixelConfig2ColorType(GrPixelConfig, SkColorType*);
reed@google.comac10a2d2010-12-22 21:39:39 +000054
rileya@google.com24f3ad12012-07-18 21:47:40 +000055static 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
dandov9de5b512014-06-10 14:38:28 -070064static inline GrColor SkColor2GrColorJustAlpha(SkColor c) {
65 U8CPU a = SkColorGetA(c);
66 return GrColorPackRGBA(a, a, a, a);
67}
68
rileya@google.com24f3ad12012-07-18 21:47:40 +000069////////////////////////////////////////////////////////////////////////////////
70
bsalomon71cb0c22014-11-14 12:10:14 -080071// The cache listens for these messages to purge junk resources proactively.
72struct GrResourceInvalidatedMessage {
73 GrResourceKey key;
74};
75
bsalomon@google.com0797c2c2012-12-20 15:13:01 +000076bool GrIsBitmapInCache(const GrContext*, const SkBitmap&, const GrTextureParams*);
77
bsalomonbcf0a522014-10-08 08:40:09 -070078GrTexture* GrRefCachedBitmapTexture(GrContext*, const SkBitmap&, const GrTextureParams*);
reed@google.comac10a2d2010-12-22 21:39:39 +000079
80////////////////////////////////////////////////////////////////////////////////
commit-bot@chromium.org8dcff642014-05-15 20:32:48 +000081
commit-bot@chromium.org8dcff642014-05-15 20:32:48 +000082// Converts a SkPaint to a GrPaint, ignoring the SkPaint's shader.
bsalomon83d081a2014-07-08 09:56:10 -070083// Sets the color of GrPaint to the value of the parameter paintColor
commit-bot@chromium.org8dcff642014-05-15 20:32:48 +000084// Callers may subsequently modify the GrPaint. Setting constantColor indicates
85// that the final paint will draw the same color at every pixel. This allows
86// an optimization where the the color filter can be applied to the SkPaint's
87// color once while converting to GrPaint and then ignored.
bsalomon83d081a2014-07-08 09:56:10 -070088void SkPaint2GrPaintNoShader(GrContext* context, const SkPaint& skPaint, GrColor paintColor,
commit-bot@chromium.org8dcff642014-05-15 20:32:48 +000089 bool constantColor, GrPaint* grPaint);
90
91// This function is similar to skPaint2GrPaintNoShader but also converts
bsalomonae59b772014-11-19 08:23:49 -080092// skPaint's shader to a GrFragmentProcessor if possible.
commit-bot@chromium.org8dcff642014-05-15 20:32:48 +000093// constantColor has the same meaning as in skPaint2GrPaintNoShader.
commit-bot@chromium.org3595f882014-05-19 19:35:57 +000094void SkPaint2GrPaintShader(GrContext* context, const SkPaint& skPaint,
joshualitt5531d512014-12-17 15:50:11 -080095 const SkMatrix& viewM, bool constantColor, GrPaint* grPaint);
commit-bot@chromium.org8dcff642014-05-15 20:32:48 +000096
97////////////////////////////////////////////////////////////////////////////////
reed@google.comac10a2d2010-12-22 21:39:39 +000098// Classes
99
reed@google.comac10a2d2010-12-22 21:39:39 +0000100class SkGlyphCache;
101
reed@google.comac10a2d2010-12-22 21:39:39 +0000102////////////////////////////////////////////////////////////////////////////////
reed@google.comac10a2d2010-12-22 21:39:39 +0000103
104#endif