blob: e306293e318091e443eb4dac07d7372e87987033 [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"
19#include "GrFontScaler.h"
reed@google.comac10a2d2010-12-22 21:39:39 +000020
21// skia headers
22#include "SkBitmap.h"
23#include "SkPath.h"
24#include "SkPoint.h"
25#include "SkRegion.h"
bsalomon@google.comd302f142011-03-03 13:54:13 +000026#include "SkClipStack.h"
reed@google.comac10a2d2010-12-22 21:39:39 +000027
reed@google.comac10a2d2010-12-22 21:39:39 +000028////////////////////////////////////////////////////////////////////////////////
29// Sk to Gr Type conversions
30
bsalomon@google.com47059542012-06-06 20:51:20 +000031GR_STATIC_ASSERT((int)kZero_GrBlendCoeff == (int)SkXfermode::kZero_Coeff);
32GR_STATIC_ASSERT((int)kOne_GrBlendCoeff == (int)SkXfermode::kOne_Coeff);
33GR_STATIC_ASSERT((int)kSC_GrBlendCoeff == (int)SkXfermode::kSC_Coeff);
34GR_STATIC_ASSERT((int)kISC_GrBlendCoeff == (int)SkXfermode::kISC_Coeff);
35GR_STATIC_ASSERT((int)kDC_GrBlendCoeff == (int)SkXfermode::kDC_Coeff);
36GR_STATIC_ASSERT((int)kIDC_GrBlendCoeff == (int)SkXfermode::kIDC_Coeff);
37GR_STATIC_ASSERT((int)kSA_GrBlendCoeff == (int)SkXfermode::kSA_Coeff);
38GR_STATIC_ASSERT((int)kISA_GrBlendCoeff == (int)SkXfermode::kISA_Coeff);
39GR_STATIC_ASSERT((int)kDA_GrBlendCoeff == (int)SkXfermode::kDA_Coeff);
40GR_STATIC_ASSERT((int)kIDA_GrBlendCoeff == (int)SkXfermode::kIDA_Coeff);
reed@google.comac10a2d2010-12-22 21:39:39 +000041
bsalomon@google.comffca4002011-02-22 20:34:01 +000042#define sk_blend_to_grblend(X) ((GrBlendCoeff)(X))
reed@google.comac10a2d2010-12-22 21:39:39 +000043
reed@google.comac10a2d2010-12-22 21:39:39 +000044///////////////////////////////////////////////////////////////////////////////
45
46#include "SkColorPriv.h"
47
reedc3b32662014-06-17 08:38:31 -070048#ifdef SK_SUPPORT_LEGACY_BITMAP_CONFIG
rileya@google.com24f3ad12012-07-18 21:47:40 +000049/**
50 * Convert the SkBitmap::Config to the corresponding PixelConfig, or
51 * kUnknown_PixelConfig if the conversion cannot be done.
52 */
53GrPixelConfig SkBitmapConfig2GrPixelConfig(SkBitmap::Config);
reedc3b32662014-06-17 08:38:31 -070054#endif
commit-bot@chromium.org15a14052014-02-16 00:59:25 +000055GrPixelConfig SkImageInfo2GrPixelConfig(SkColorType, SkAlphaType);
commit-bot@chromium.org3adcc342014-04-23 19:18:09 +000056
57static inline GrPixelConfig SkImageInfo2GrPixelConfig(const SkImageInfo& info) {
58 return SkImageInfo2GrPixelConfig(info.colorType(), info.alphaType());
59}
60
reed@google.combf790232013-12-13 19:45:58 +000061bool GrPixelConfig2ColorType(GrPixelConfig, SkColorType*);
reed@google.comac10a2d2010-12-22 21:39:39 +000062
rileya@google.com24f3ad12012-07-18 21:47:40 +000063static inline GrColor SkColor2GrColor(SkColor c) {
64 SkPMColor pm = SkPreMultiplyColor(c);
65 unsigned r = SkGetPackedR32(pm);
66 unsigned g = SkGetPackedG32(pm);
67 unsigned b = SkGetPackedB32(pm);
68 unsigned a = SkGetPackedA32(pm);
69 return GrColorPackRGBA(r, g, b, a);
70}
71
dandov9de5b512014-06-10 14:38:28 -070072static inline GrColor SkColor2GrColorJustAlpha(SkColor c) {
73 U8CPU a = SkColorGetA(c);
74 return GrColorPackRGBA(a, a, a, a);
75}
76
rileya@google.com24f3ad12012-07-18 21:47:40 +000077////////////////////////////////////////////////////////////////////////////////
78
bsalomon@google.com0797c2c2012-12-20 15:13:01 +000079bool GrIsBitmapInCache(const GrContext*, const SkBitmap&, const GrTextureParams*);
80
bsalomon@google.com95ed55a2013-01-24 14:46:47 +000081GrTexture* GrLockAndRefCachedBitmapTexture(GrContext*, const SkBitmap&, const GrTextureParams*);
rileya@google.com24f3ad12012-07-18 21:47:40 +000082
bsalomon@google.com95ed55a2013-01-24 14:46:47 +000083void GrUnlockAndUnrefCachedBitmapTexture(GrTexture*);
reed@google.comac10a2d2010-12-22 21:39:39 +000084
85////////////////////////////////////////////////////////////////////////////////
commit-bot@chromium.org8dcff642014-05-15 20:32:48 +000086
commit-bot@chromium.org8dcff642014-05-15 20:32:48 +000087// Converts a SkPaint to a GrPaint, ignoring the SkPaint's shader.
bsalomon83d081a2014-07-08 09:56:10 -070088// Sets the color of GrPaint to the value of the parameter paintColor
commit-bot@chromium.org8dcff642014-05-15 20:32:48 +000089// Callers may subsequently modify the GrPaint. Setting constantColor indicates
90// that the final paint will draw the same color at every pixel. This allows
91// an optimization where the the color filter can be applied to the SkPaint's
92// color once while converting to GrPaint and then ignored.
bsalomon83d081a2014-07-08 09:56:10 -070093void SkPaint2GrPaintNoShader(GrContext* context, const SkPaint& skPaint, GrColor paintColor,
commit-bot@chromium.org8dcff642014-05-15 20:32:48 +000094 bool constantColor, GrPaint* grPaint);
95
96// This function is similar to skPaint2GrPaintNoShader but also converts
97// skPaint's shader to a GrTexture/GrEffectStage if possible.
98// constantColor has the same meaning as in skPaint2GrPaintNoShader.
commit-bot@chromium.org3595f882014-05-19 19:35:57 +000099void SkPaint2GrPaintShader(GrContext* context, const SkPaint& skPaint,
commit-bot@chromium.org8dcff642014-05-15 20:32:48 +0000100 bool constantColor, GrPaint* grPaint);
101
102////////////////////////////////////////////////////////////////////////////////
reed@google.comac10a2d2010-12-22 21:39:39 +0000103// Classes
104
reed@google.comac10a2d2010-12-22 21:39:39 +0000105class SkGlyphCache;
106
107class SkGrFontScaler : public GrFontScaler {
108public:
109 explicit SkGrFontScaler(SkGlyphCache* strike);
110 virtual ~SkGrFontScaler();
111
112 // overrides
113 virtual const GrKey* getKey();
reed@google.com98539c62011-03-15 15:40:16 +0000114 virtual GrMaskFormat getMaskFormat();
commit-bot@chromium.org762cd802014-04-14 22:05:07 +0000115 virtual bool getPackedGlyphBounds(GrGlyph::PackedID, SkIRect* bounds) SK_OVERRIDE;
reed@google.comac10a2d2010-12-22 21:39:39 +0000116 virtual bool getPackedGlyphImage(GrGlyph::PackedID, int width, int height,
commit-bot@chromium.org762cd802014-04-14 22:05:07 +0000117 int rowBytes, void* image) SK_OVERRIDE;
118 virtual bool getPackedGlyphDFBounds(GrGlyph::PackedID, SkIRect* bounds) SK_OVERRIDE;
119 virtual bool getPackedGlyphDFImage(GrGlyph::PackedID, int width, int height,
120 void* image) SK_OVERRIDE;
bsalomon@google.com8d033a12012-04-27 15:52:53 +0000121 virtual bool getGlyphPath(uint16_t glyphID, SkPath*);
reed@google.comac10a2d2010-12-22 21:39:39 +0000122
123private:
124 SkGlyphCache* fStrike;
125 GrKey* fKey;
126// DECLARE_INSTANCE_COUNTER(SkGrFontScaler);
127};
128
129////////////////////////////////////////////////////////////////////////////////
reed@google.comac10a2d2010-12-22 21:39:39 +0000130
131#endif