blob: 7dd1aff456e8b06004fbf54c51ec557a98887455 [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
reed@google.comac10a2d2010-12-22 21:39:39 +000017#include "GrContext.h"
joshualitt9bc39542015-08-12 12:57:54 -070018#include "GrTextureAccess.h"
19#include "GrTypes.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
jvanverthfa1e8a72014-12-22 08:31:49 -080048GrPixelConfig SkImageInfo2GrPixelConfig(SkColorType, SkAlphaType, SkColorProfileType);
commit-bot@chromium.org3adcc342014-04-23 19:18:09 +000049
50static inline GrPixelConfig SkImageInfo2GrPixelConfig(const SkImageInfo& info) {
jvanverthfa1e8a72014-12-22 08:31:49 -080051 return SkImageInfo2GrPixelConfig(info.colorType(), info.alphaType(), info.profileType());
commit-bot@chromium.org3adcc342014-04-23 19:18:09 +000052}
53
jvanverthfa1e8a72014-12-22 08:31:49 -080054bool GrPixelConfig2ColorAndProfileType(GrPixelConfig, SkColorType*, SkColorProfileType*);
reed@google.comac10a2d2010-12-22 21:39:39 +000055
rileya@google.com24f3ad12012-07-18 21:47:40 +000056static inline GrColor SkColor2GrColor(SkColor c) {
57 SkPMColor pm = SkPreMultiplyColor(c);
58 unsigned r = SkGetPackedR32(pm);
59 unsigned g = SkGetPackedG32(pm);
60 unsigned b = SkGetPackedB32(pm);
61 unsigned a = SkGetPackedA32(pm);
62 return GrColorPackRGBA(r, g, b, a);
63}
64
dandov9de5b512014-06-10 14:38:28 -070065static inline GrColor SkColor2GrColorJustAlpha(SkColor c) {
66 U8CPU a = SkColorGetA(c);
67 return GrColorPackRGBA(a, a, a, a);
68}
69
rileya@google.com24f3ad12012-07-18 21:47:40 +000070////////////////////////////////////////////////////////////////////////////////
71
reed43fe6182015-09-08 08:37:36 -070072/**
73 * If the compressed data in the SkData is supported (as a texture format, this returns
74 * the pixel-config that should be used, and sets outStartOfDataToUpload to the ptr into
75 * the data where the actual raw data starts (skipping any header bytes).
76 *
77 * If the compressed data is not supported, this returns kUnknown_GrPixelConfig, and
78 * ignores outStartOfDataToUpload.
79 */
80GrPixelConfig GrIsCompressedTextureDataSupported(GrContext* ctx, SkData* data,
81 int expectedW, int expectedH,
82 const void** outStartOfDataToUpload);
83
bsalomon@google.com0797c2c2012-12-20 15:13:01 +000084bool GrIsBitmapInCache(const GrContext*, const SkBitmap&, const GrTextureParams*);
85
bsalomonbcf0a522014-10-08 08:40:09 -070086GrTexture* GrRefCachedBitmapTexture(GrContext*, const SkBitmap&, const GrTextureParams*);
reed8f343722015-08-13 13:32:39 -070087GrTexture* GrRefCachedBitmapTexture(GrContext*, const SkBitmap&, SkImageUsageType);
reed@google.comac10a2d2010-12-22 21:39:39 +000088
reed43fe6182015-09-08 08:37:36 -070089GrTexture* GrCreateTextureForPixels(GrContext*, const GrUniqueKey& optionalKey, GrSurfaceDesc,
90 SkPixelRef* pixelRefForInvalidationNotificationOrNull,
91 const void* pixels, size_t rowBytesOrZero);
92
reed@google.comac10a2d2010-12-22 21:39:39 +000093////////////////////////////////////////////////////////////////////////////////
commit-bot@chromium.org8dcff642014-05-15 20:32:48 +000094
commit-bot@chromium.org8dcff642014-05-15 20:32:48 +000095// Converts a SkPaint to a GrPaint, ignoring the SkPaint's shader.
bsalomon83d081a2014-07-08 09:56:10 -070096// Sets the color of GrPaint to the value of the parameter paintColor
commit-bot@chromium.org8dcff642014-05-15 20:32:48 +000097// Callers may subsequently modify the GrPaint. Setting constantColor indicates
98// that the final paint will draw the same color at every pixel. This allows
bsalomonc9c3e622015-04-02 11:12:09 -070099// an optimization where the color filter can be applied to the SkPaint's
100// color once while converting to GrPaint and then ignored. TODO: Remove this
101// bool and use the invariant info to automatically apply the color filter.
bsalomonbed83a62015-04-15 14:18:34 -0700102bool SkPaint2GrPaintNoShader(GrContext* context, GrRenderTarget*, const SkPaint& skPaint,
joshualitt25d9c152015-02-18 12:29:52 -0800103 GrColor paintColor, bool constantColor, GrPaint* grPaint);
commit-bot@chromium.org8dcff642014-05-15 20:32:48 +0000104
105// This function is similar to skPaint2GrPaintNoShader but also converts
bsalomonae59b772014-11-19 08:23:49 -0800106// skPaint's shader to a GrFragmentProcessor if possible.
commit-bot@chromium.org8dcff642014-05-15 20:32:48 +0000107// constantColor has the same meaning as in skPaint2GrPaintNoShader.
bsalomonbed83a62015-04-15 14:18:34 -0700108bool SkPaint2GrPaint(GrContext* context, GrRenderTarget*, const SkPaint& skPaint,
109 const SkMatrix& viewM, bool constantColor, GrPaint* grPaint);
commit-bot@chromium.org8dcff642014-05-15 20:32:48 +0000110
reed8b26b992015-05-07 15:36:17 -0700111
112SkImageInfo GrMakeInfoFromTexture(GrTexture* tex, int w, int h, bool isOpaque);
113
114// Using the dreaded SkGrPixelRef ...
115void GrWrapTextureInBitmap(GrTexture* src, int w, int h, bool isOpaque, SkBitmap* dst);
116
joshualitt9bc39542015-08-12 12:57:54 -0700117GrTextureParams::FilterMode GrSkFilterQualityToGrFilterMode(SkFilterQuality paintFilterQuality,
118 const SkMatrix& viewM,
119 const SkMatrix& localM,
120 bool* doBicubic);
121
commit-bot@chromium.org8dcff642014-05-15 20:32:48 +0000122////////////////////////////////////////////////////////////////////////////////
reed@google.comac10a2d2010-12-22 21:39:39 +0000123// Classes
124
reed@google.comac10a2d2010-12-22 21:39:39 +0000125class SkGlyphCache;
126
reed@google.comac10a2d2010-12-22 21:39:39 +0000127////////////////////////////////////////////////////////////////////////////////
reed@google.comac10a2d2010-12-22 21:39:39 +0000128
129#endif