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