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; |
| 19 | class GrFragmentProcessor; |
| 20 | class GrPaint; |
bsalomon | f276ac5 | 2015-10-09 13:36:42 -0700 | [diff] [blame] | 21 | class GrTexture; |
bsalomon | afa95e2 | 2015-10-12 10:39:46 -0700 | [diff] [blame] | 22 | class GrTextureParams; |
reed | 8f34372 | 2015-08-13 13:32:39 -0700 | [diff] [blame] | 23 | class GrUniqueKey; |
bsalomon | afa95e2 | 2015-10-12 10:39:46 -0700 | [diff] [blame] | 24 | class SkData; |
bsalomon | f1b7a1d | 2015-09-28 06:26:28 -0700 | [diff] [blame] | 25 | class SkPaint; |
bsalomon | afa95e2 | 2015-10-12 10:39:46 -0700 | [diff] [blame] | 26 | class SkPixelRef; |
bsalomon | f1b7a1d | 2015-09-28 06:26:28 -0700 | [diff] [blame] | 27 | struct SkIRect; |
reed | 8f34372 | 2015-08-13 13:32:39 -0700 | [diff] [blame] | 28 | |
| 29 | /** |
| 30 | * Our key includes the offset, width, and height so that bitmaps created by extractSubset() |
| 31 | * are unique. |
| 32 | * |
bsalomon | 045802d | 2015-10-20 07:58:01 -0700 | [diff] [blame] | 33 | * The imageID is in the shared namespace (see SkNextID::ImageID()) |
reed | 8f34372 | 2015-08-13 13:32:39 -0700 | [diff] [blame] | 34 | * - SkBitmap/SkPixelRef |
| 35 | * - SkImage |
| 36 | * - SkImageGenerator |
| 37 | * |
| 38 | * Note: width/height must fit in 16bits for this impl. |
| 39 | */ |
bsalomon | 045802d | 2015-10-20 07:58:01 -0700 | [diff] [blame] | 40 | void GrMakeKeyFromImageID(GrUniqueKey* key, uint32_t imageID, const SkIRect& imageBounds); |
reed | 856e9d9 | 2015-09-30 12:21:45 -0700 | [diff] [blame] | 41 | |
bsalomon | f1b7a1d | 2015-09-28 06:26:28 -0700 | [diff] [blame] | 42 | /** 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] | 43 | 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] | 44 | bool SkPaintToGrPaint(GrContext*, |
| 45 | const SkPaint& skPaint, |
| 46 | const SkMatrix& viewM, |
| 47 | GrPaint* grPaint); |
| 48 | |
bsalomon | aa48d36 | 2015-10-01 08:34:17 -0700 | [diff] [blame] | 49 | /** Same as above but ignores the SkShader (if any) on skPaint. */ |
bsalomon | f1b7a1d | 2015-09-28 06:26:28 -0700 | [diff] [blame] | 50 | bool SkPaintToGrPaintNoShader(GrContext* context, |
| 51 | const SkPaint& skPaint, |
| 52 | GrPaint* grPaint); |
| 53 | |
| 54 | /** 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] | 55 | should expect an unpremul input color and produce a premultiplied output color. There is |
| 56 | no primitive color. */ |
bsalomon | f1b7a1d | 2015-09-28 06:26:28 -0700 | [diff] [blame] | 57 | bool SkPaintToGrPaintReplaceShader(GrContext*, |
| 58 | const SkPaint& skPaint, |
| 59 | const GrFragmentProcessor* shaderFP, |
| 60 | GrPaint* grPaint); |
| 61 | |
| 62 | /** Blends the SkPaint's shader (or color if no shader) with the color which specified via a |
| 63 | GrBatch's GrPrimitiveProcesssor. Currently there is a bool param to indicate whether the |
| 64 | 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] | 65 | drawVertices and drawAtlas. */ |
bsalomon | f1b7a1d | 2015-09-28 06:26:28 -0700 | [diff] [blame] | 66 | bool SkPaintToGrPaintWithXfermode(GrContext* context, |
| 67 | const SkPaint& skPaint, |
| 68 | const SkMatrix& viewM, |
| 69 | SkXfermode::Mode primColorMode, |
| 70 | bool primitiveIsSrc, |
| 71 | GrPaint* grPaint); |
| 72 | |
bsalomon | aa48d36 | 2015-10-01 08:34:17 -0700 | [diff] [blame] | 73 | /** This is used when there is a primitive color, but the shader should be ignored. Currently, |
| 74 | the expectation is that the primitive color will be premultiplied, though it really should be |
| 75 | unpremultiplied so that interpolation is done in unpremul space. The paint's alpha will be |
| 76 | applied to the primitive color after interpolation. */ |
| 77 | inline bool SkPaintToGrPaintWithPrimitiveColor(GrContext* context, const SkPaint& skPaint, |
| 78 | GrPaint* grPaint) { |
| 79 | return SkPaintToGrPaintWithXfermode(context, skPaint, SkMatrix::I(), SkXfermode::kDst_Mode, |
| 80 | false, grPaint); |
| 81 | } |
| 82 | |
bsalomon | f276ac5 | 2015-10-09 13:36:42 -0700 | [diff] [blame] | 83 | ////////////////////////////////////////////////////////////////////////////// |
| 84 | |
bsalomon | f276ac5 | 2015-10-09 13:36:42 -0700 | [diff] [blame] | 85 | GrSurfaceDesc GrImageInfoToSurfaceDesc(const SkImageInfo&); |
| 86 | |
| 87 | bool GrPixelConfig2ColorAndProfileType(GrPixelConfig, SkColorType*, SkColorProfileType*); |
| 88 | |
| 89 | /** |
bsalomon | 045802d | 2015-10-20 07:58:01 -0700 | [diff] [blame] | 90 | * If the compressed data in the SkData is supported (as a texture format, this returns |
| 91 | * the pixel-config that should be used, and sets outStartOfDataToUpload to the ptr into |
| 92 | * the data where the actual raw data starts (skipping any header bytes). |
| 93 | * |
| 94 | * If the compressed data is not supported, this returns kUnknown_GrPixelConfig, and |
| 95 | * ignores outStartOfDataToUpload. |
| 96 | */ |
bsalomon | f276ac5 | 2015-10-09 13:36:42 -0700 | [diff] [blame] | 97 | GrPixelConfig GrIsCompressedTextureDataSupported(GrContext* ctx, SkData* data, |
| 98 | int expectedW, int expectedH, |
| 99 | const void** outStartOfDataToUpload); |
| 100 | |
bsalomon | f276ac5 | 2015-10-09 13:36:42 -0700 | [diff] [blame] | 101 | |
bsalomon | 045802d | 2015-10-20 07:58:01 -0700 | [diff] [blame] | 102 | /** |
| 103 | * Creates a new texture for the bitmap. Does not concern itself with cache keys or texture params. |
| 104 | * The bitmap must have CPU-accessible pixels. Attempts to take advantage of faster paths for |
| 105 | * compressed textures and yuv planes. |
| 106 | */ |
| 107 | GrTexture* GrUploadBitmapToTexture(GrContext*, const SkBitmap&); |
bsalomon | f276ac5 | 2015-10-09 13:36:42 -0700 | [diff] [blame] | 108 | |
| 109 | ////////////////////////////////////////////////////////////////////////////// |
| 110 | |
| 111 | GR_STATIC_ASSERT((int)kZero_GrBlendCoeff == (int)SkXfermode::kZero_Coeff); |
| 112 | GR_STATIC_ASSERT((int)kOne_GrBlendCoeff == (int)SkXfermode::kOne_Coeff); |
| 113 | GR_STATIC_ASSERT((int)kSC_GrBlendCoeff == (int)SkXfermode::kSC_Coeff); |
| 114 | GR_STATIC_ASSERT((int)kISC_GrBlendCoeff == (int)SkXfermode::kISC_Coeff); |
| 115 | GR_STATIC_ASSERT((int)kDC_GrBlendCoeff == (int)SkXfermode::kDC_Coeff); |
| 116 | GR_STATIC_ASSERT((int)kIDC_GrBlendCoeff == (int)SkXfermode::kIDC_Coeff); |
| 117 | GR_STATIC_ASSERT((int)kSA_GrBlendCoeff == (int)SkXfermode::kSA_Coeff); |
| 118 | GR_STATIC_ASSERT((int)kISA_GrBlendCoeff == (int)SkXfermode::kISA_Coeff); |
| 119 | GR_STATIC_ASSERT((int)kDA_GrBlendCoeff == (int)SkXfermode::kDA_Coeff); |
| 120 | GR_STATIC_ASSERT((int)kIDA_GrBlendCoeff == (int)SkXfermode::kIDA_Coeff); |
| 121 | GR_STATIC_ASSERT(SkXfermode::kCoeffCount == 10); |
| 122 | |
| 123 | #define SkXfermodeCoeffToGrBlendCoeff(X) ((GrBlendCoeff)(X)) |
| 124 | |
reed | 8f34372 | 2015-08-13 13:32:39 -0700 | [diff] [blame] | 125 | #endif |