reed | 8f34372 | 2015-08-13 13:32:39 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2015 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. |
| 6 | */ |
| 7 | |
| 8 | #ifndef SkGrPriv_DEFINED |
| 9 | #define SkGrPriv_DEFINED |
| 10 | |
| 11 | #include "GrTypes.h" |
bsalomon | f276ac5 | 2015-10-09 13:36:42 -0700 | [diff] [blame] | 12 | #include "GrBlend.h" |
bsalomon | f1b7a1d | 2015-09-28 06:26:28 -0700 | [diff] [blame] | 13 | #include "SkImageInfo.h" |
bsalomon | afa95e2 | 2015-10-12 10:39:46 -0700 | [diff] [blame] | 14 | #include "SkMatrix.h" |
bsalomon | f1b7a1d | 2015-09-28 06:26:28 -0700 | [diff] [blame] | 15 | #include "SkXfermode.h" |
reed | 8f34372 | 2015-08-13 13:32:39 -0700 | [diff] [blame] | 16 | |
| 17 | class GrCaps; |
bsalomon | f1b7a1d | 2015-09-28 06:26:28 -0700 | [diff] [blame] | 18 | class GrContext; |
brianosman | 8fe485b | 2016-07-25 12:31:51 -0700 | [diff] [blame] | 19 | class GrDrawContext; |
bsalomon | f1b7a1d | 2015-09-28 06:26:28 -0700 | [diff] [blame] | 20 | class GrFragmentProcessor; |
| 21 | class GrPaint; |
bsalomon | f276ac5 | 2015-10-09 13:36:42 -0700 | [diff] [blame] | 22 | class GrTexture; |
bsalomon | afa95e2 | 2015-10-12 10:39:46 -0700 | [diff] [blame] | 23 | class GrTextureParams; |
reed | 8f34372 | 2015-08-13 13:32:39 -0700 | [diff] [blame] | 24 | class GrUniqueKey; |
bsalomon | afa95e2 | 2015-10-12 10:39:46 -0700 | [diff] [blame] | 25 | class SkData; |
bsalomon | f1b7a1d | 2015-09-28 06:26:28 -0700 | [diff] [blame] | 26 | class SkPaint; |
bsalomon | afa95e2 | 2015-10-12 10:39:46 -0700 | [diff] [blame] | 27 | class SkPixelRef; |
bsalomon | f1b7a1d | 2015-09-28 06:26:28 -0700 | [diff] [blame] | 28 | struct SkIRect; |
reed | 8f34372 | 2015-08-13 13:32:39 -0700 | [diff] [blame] | 29 | |
| 30 | /** |
| 31 | * Our key includes the offset, width, and height so that bitmaps created by extractSubset() |
| 32 | * are unique. |
| 33 | * |
bsalomon | 045802d | 2015-10-20 07:58:01 -0700 | [diff] [blame] | 34 | * The imageID is in the shared namespace (see SkNextID::ImageID()) |
reed | 8f34372 | 2015-08-13 13:32:39 -0700 | [diff] [blame] | 35 | * - SkBitmap/SkPixelRef |
| 36 | * - SkImage |
| 37 | * - SkImageGenerator |
| 38 | * |
| 39 | * Note: width/height must fit in 16bits for this impl. |
| 40 | */ |
bsalomon | 045802d | 2015-10-20 07:58:01 -0700 | [diff] [blame] | 41 | void GrMakeKeyFromImageID(GrUniqueKey* key, uint32_t imageID, const SkIRect& imageBounds); |
reed | 856e9d9 | 2015-09-30 12:21:45 -0700 | [diff] [blame] | 42 | |
bsalomon | c55271f | 2015-11-09 11:55:57 -0800 | [diff] [blame] | 43 | /** Call this after installing a GrUniqueKey on texture. It will cause the texture's key to be |
| 44 | removed should the bitmap's contents change or be destroyed. */ |
| 45 | void GrInstallBitmapUniqueKeyInvalidator(const GrUniqueKey& key, SkPixelRef* pixelRef); |
| 46 | |
bsalomon | f1b7a1d | 2015-09-28 06:26:28 -0700 | [diff] [blame] | 47 | /** Converts an SkPaint to a GrPaint for a given GrContext. The matrix is required in order |
bsalomon | aa48d36 | 2015-10-01 08:34:17 -0700 | [diff] [blame] | 48 | to convert the SkShader (if any) on the SkPaint. The primitive itself has no color. */ |
bsalomon | f1b7a1d | 2015-09-28 06:26:28 -0700 | [diff] [blame] | 49 | bool SkPaintToGrPaint(GrContext*, |
brianosman | 8fe485b | 2016-07-25 12:31:51 -0700 | [diff] [blame] | 50 | GrDrawContext*, |
bsalomon | f1b7a1d | 2015-09-28 06:26:28 -0700 | [diff] [blame] | 51 | const SkPaint& skPaint, |
| 52 | const SkMatrix& viewM, |
| 53 | GrPaint* grPaint); |
| 54 | |
bsalomon | aa48d36 | 2015-10-01 08:34:17 -0700 | [diff] [blame] | 55 | /** Same as above but ignores the SkShader (if any) on skPaint. */ |
bsalomon | f1b7a1d | 2015-09-28 06:26:28 -0700 | [diff] [blame] | 56 | bool SkPaintToGrPaintNoShader(GrContext* context, |
brianosman | 8fe485b | 2016-07-25 12:31:51 -0700 | [diff] [blame] | 57 | GrDrawContext* dc, |
bsalomon | f1b7a1d | 2015-09-28 06:26:28 -0700 | [diff] [blame] | 58 | const SkPaint& skPaint, |
| 59 | GrPaint* grPaint); |
| 60 | |
| 61 | /** Replaces the SkShader (if any) on skPaint with the passed in GrFragmentProcessor. The processor |
bsalomon | aa48d36 | 2015-10-01 08:34:17 -0700 | [diff] [blame] | 62 | should expect an unpremul input color and produce a premultiplied output color. There is |
| 63 | no primitive color. */ |
bsalomon | f1b7a1d | 2015-09-28 06:26:28 -0700 | [diff] [blame] | 64 | bool SkPaintToGrPaintReplaceShader(GrContext*, |
brianosman | 8fe485b | 2016-07-25 12:31:51 -0700 | [diff] [blame] | 65 | GrDrawContext*, |
bsalomon | f1b7a1d | 2015-09-28 06:26:28 -0700 | [diff] [blame] | 66 | const SkPaint& skPaint, |
bungeman | 06ca8ec | 2016-06-09 08:01:03 -0700 | [diff] [blame] | 67 | sk_sp<GrFragmentProcessor> shaderFP, |
bsalomon | f1b7a1d | 2015-09-28 06:26:28 -0700 | [diff] [blame] | 68 | GrPaint* grPaint); |
| 69 | |
| 70 | /** Blends the SkPaint's shader (or color if no shader) with the color which specified via a |
| 71 | GrBatch's GrPrimitiveProcesssor. Currently there is a bool param to indicate whether the |
| 72 | primitive color is the dst or src color to the blend in order to work around differences between |
bsalomon | aa48d36 | 2015-10-01 08:34:17 -0700 | [diff] [blame] | 73 | drawVertices and drawAtlas. */ |
bsalomon | f1b7a1d | 2015-09-28 06:26:28 -0700 | [diff] [blame] | 74 | bool SkPaintToGrPaintWithXfermode(GrContext* context, |
brianosman | 8fe485b | 2016-07-25 12:31:51 -0700 | [diff] [blame] | 75 | GrDrawContext* dc, |
bsalomon | f1b7a1d | 2015-09-28 06:26:28 -0700 | [diff] [blame] | 76 | const SkPaint& skPaint, |
| 77 | const SkMatrix& viewM, |
| 78 | SkXfermode::Mode primColorMode, |
| 79 | bool primitiveIsSrc, |
| 80 | GrPaint* grPaint); |
| 81 | |
bsalomon | aa48d36 | 2015-10-01 08:34:17 -0700 | [diff] [blame] | 82 | /** This is used when there is a primitive color, but the shader should be ignored. Currently, |
| 83 | the expectation is that the primitive color will be premultiplied, though it really should be |
| 84 | unpremultiplied so that interpolation is done in unpremul space. The paint's alpha will be |
| 85 | applied to the primitive color after interpolation. */ |
brianosman | 8fe485b | 2016-07-25 12:31:51 -0700 | [diff] [blame] | 86 | inline bool SkPaintToGrPaintWithPrimitiveColor(GrContext* context, GrDrawContext* dc, |
| 87 | const SkPaint& skPaint, GrPaint* grPaint) { |
| 88 | return SkPaintToGrPaintWithXfermode(context, dc, skPaint, SkMatrix::I(), SkXfermode::kDst_Mode, |
| 89 | false, grPaint); |
bsalomon | aa48d36 | 2015-10-01 08:34:17 -0700 | [diff] [blame] | 90 | } |
| 91 | |
joshualitt | 33a5fce | 2015-11-18 13:28:51 -0800 | [diff] [blame] | 92 | /** This is used when there may or may not be a shader, and the caller wants to plugin a texture |
| 93 | lookup. If there is a shader, then its output will only be used if the texture is alpha8. */ |
| 94 | bool SkPaintToGrPaintWithTexture(GrContext* context, |
brianosman | 8fe485b | 2016-07-25 12:31:51 -0700 | [diff] [blame] | 95 | GrDrawContext* dc, |
joshualitt | 33a5fce | 2015-11-18 13:28:51 -0800 | [diff] [blame] | 96 | const SkPaint& paint, |
| 97 | const SkMatrix& viewM, |
bungeman | 06ca8ec | 2016-06-09 08:01:03 -0700 | [diff] [blame] | 98 | sk_sp<GrFragmentProcessor> fp, |
joshualitt | 33a5fce | 2015-11-18 13:28:51 -0800 | [diff] [blame] | 99 | bool textureIsAlphaOnly, |
| 100 | GrPaint* grPaint); |
| 101 | |
bsalomon | f276ac5 | 2015-10-09 13:36:42 -0700 | [diff] [blame] | 102 | ////////////////////////////////////////////////////////////////////////////// |
| 103 | |
brianosman | a635936 | 2016-03-21 06:55:37 -0700 | [diff] [blame] | 104 | GrSurfaceDesc GrImageInfoToSurfaceDesc(const SkImageInfo&, const GrCaps&); |
bsalomon | f276ac5 | 2015-10-09 13:36:42 -0700 | [diff] [blame] | 105 | |
brianosman | 396fcdb | 2016-07-22 06:26:11 -0700 | [diff] [blame] | 106 | bool GrPixelConfigToColorType(GrPixelConfig, SkColorType*); |
bsalomon | f276ac5 | 2015-10-09 13:36:42 -0700 | [diff] [blame] | 107 | |
brianosman | 2695eaa | 2016-09-21 06:45:09 -0700 | [diff] [blame] | 108 | /** When image filter code needs to construct a draw context to do intermediate rendering, we need |
| 109 | a renderable pixel config. The source (SkSpecialImage) may not be in a renderable format, but |
| 110 | we want to preserve the color space of that source. This picks an appropriate format to use. */ |
| 111 | GrPixelConfig GrRenderableConfigForColorSpace(SkColorSpace*); |
| 112 | |
bsalomon | f276ac5 | 2015-10-09 13:36:42 -0700 | [diff] [blame] | 113 | /** |
bsalomon | 045802d | 2015-10-20 07:58:01 -0700 | [diff] [blame] | 114 | * If the compressed data in the SkData is supported (as a texture format, this returns |
| 115 | * the pixel-config that should be used, and sets outStartOfDataToUpload to the ptr into |
| 116 | * the data where the actual raw data starts (skipping any header bytes). |
| 117 | * |
| 118 | * If the compressed data is not supported, this returns kUnknown_GrPixelConfig, and |
| 119 | * ignores outStartOfDataToUpload. |
| 120 | */ |
bsalomon | f276ac5 | 2015-10-09 13:36:42 -0700 | [diff] [blame] | 121 | GrPixelConfig GrIsCompressedTextureDataSupported(GrContext* ctx, SkData* data, |
| 122 | int expectedW, int expectedH, |
| 123 | const void** outStartOfDataToUpload); |
| 124 | |
bsalomon | f276ac5 | 2015-10-09 13:36:42 -0700 | [diff] [blame] | 125 | |
bsalomon | 045802d | 2015-10-20 07:58:01 -0700 | [diff] [blame] | 126 | /** |
| 127 | * Creates a new texture for the bitmap. Does not concern itself with cache keys or texture params. |
| 128 | * The bitmap must have CPU-accessible pixels. Attempts to take advantage of faster paths for |
| 129 | * compressed textures and yuv planes. |
| 130 | */ |
| 131 | GrTexture* GrUploadBitmapToTexture(GrContext*, const SkBitmap&); |
bsalomon | f276ac5 | 2015-10-09 13:36:42 -0700 | [diff] [blame] | 132 | |
brianosman | 982eb7f | 2016-06-06 13:10:58 -0700 | [diff] [blame] | 133 | GrTexture* GrGenerateMipMapsAndUploadToTexture(GrContext*, const SkBitmap&, SkSourceGammaTreatment); |
cblume | 55f2d2d | 2016-02-26 13:20:48 -0800 | [diff] [blame] | 134 | |
bsalomon | 0d99686 | 2016-03-09 18:44:43 -0800 | [diff] [blame] | 135 | /** |
| 136 | * Creates a new texture for the pixmap. |
| 137 | */ |
ericrk | 8bea890 | 2016-03-18 11:52:20 -0700 | [diff] [blame] | 138 | GrTexture* GrUploadPixmapToTexture(GrContext*, const SkPixmap&, SkBudgeted budgeted); |
bsalomon | 0d99686 | 2016-03-09 18:44:43 -0800 | [diff] [blame] | 139 | |
cblume | 186d2d4 | 2016-06-03 11:17:42 -0700 | [diff] [blame] | 140 | /** |
| 141 | * Creates a new texture populated with the mipmap levels. |
| 142 | */ |
| 143 | GrTexture* GrUploadMipMapToTexture(GrContext*, const SkImageInfo&, const GrMipLevel* texels, |
| 144 | int mipLevelCount); |
| 145 | |
bsalomon | f276ac5 | 2015-10-09 13:36:42 -0700 | [diff] [blame] | 146 | ////////////////////////////////////////////////////////////////////////////// |
| 147 | |
| 148 | GR_STATIC_ASSERT((int)kZero_GrBlendCoeff == (int)SkXfermode::kZero_Coeff); |
| 149 | GR_STATIC_ASSERT((int)kOne_GrBlendCoeff == (int)SkXfermode::kOne_Coeff); |
| 150 | GR_STATIC_ASSERT((int)kSC_GrBlendCoeff == (int)SkXfermode::kSC_Coeff); |
| 151 | GR_STATIC_ASSERT((int)kISC_GrBlendCoeff == (int)SkXfermode::kISC_Coeff); |
| 152 | GR_STATIC_ASSERT((int)kDC_GrBlendCoeff == (int)SkXfermode::kDC_Coeff); |
| 153 | GR_STATIC_ASSERT((int)kIDC_GrBlendCoeff == (int)SkXfermode::kIDC_Coeff); |
| 154 | GR_STATIC_ASSERT((int)kSA_GrBlendCoeff == (int)SkXfermode::kSA_Coeff); |
| 155 | GR_STATIC_ASSERT((int)kISA_GrBlendCoeff == (int)SkXfermode::kISA_Coeff); |
| 156 | GR_STATIC_ASSERT((int)kDA_GrBlendCoeff == (int)SkXfermode::kDA_Coeff); |
| 157 | GR_STATIC_ASSERT((int)kIDA_GrBlendCoeff == (int)SkXfermode::kIDA_Coeff); |
| 158 | GR_STATIC_ASSERT(SkXfermode::kCoeffCount == 10); |
| 159 | |
| 160 | #define SkXfermodeCoeffToGrBlendCoeff(X) ((GrBlendCoeff)(X)) |
| 161 | |
reed | 8f34372 | 2015-08-13 13:32:39 -0700 | [diff] [blame] | 162 | #endif |