reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1 | /* |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 2 | * Copyright 2010 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. |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 6 | */ |
| 7 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 8 | #include "SkGr.h" |
commit-bot@chromium.org | 8dcff64 | 2014-05-15 20:32:48 +0000 | [diff] [blame] | 9 | #include "SkColorFilter.h" |
commit-bot@chromium.org | ea476e1 | 2013-10-14 18:29:23 +0000 | [diff] [blame] | 10 | #include "SkConfig8888.h" |
krajcevski | 9c0e629 | 2014-06-02 07:38:14 -0700 | [diff] [blame] | 11 | #include "SkData.h" |
commit-bot@chromium.org | 50a3043 | 2013-10-24 17:44:27 +0000 | [diff] [blame] | 12 | #include "SkMessageBus.h" |
| 13 | #include "SkPixelRef.h" |
krajcevski | 40a1e11 | 2014-08-05 14:13:36 -0700 | [diff] [blame] | 14 | #include "SkTextureCompressor.h" |
krajcevski | 9c0e629 | 2014-06-02 07:38:14 -0700 | [diff] [blame] | 15 | #include "GrGpu.h" |
krajcevski | f461a8f | 2014-06-19 14:14:06 -0700 | [diff] [blame] | 16 | #include "effects/GrDitherEffect.h" |
krajcevski | 9c0e629 | 2014-06-02 07:38:14 -0700 | [diff] [blame] | 17 | #include "GrDrawTargetCaps.h" |
sugoi | 518d83d | 2014-07-21 11:37:39 -0700 | [diff] [blame] | 18 | #include "effects/GrYUVtoRGBEffect.h" |
krajcevski | 9c0e629 | 2014-06-02 07:38:14 -0700 | [diff] [blame] | 19 | |
krajcevski | 8c111f7 | 2014-06-02 13:51:34 -0700 | [diff] [blame] | 20 | #ifndef SK_IGNORE_ETC1_SUPPORT |
krajcevski | 99ffe24 | 2014-06-03 13:04:35 -0700 | [diff] [blame] | 21 | # include "ktx.h" |
krajcevski | 9c0e629 | 2014-06-02 07:38:14 -0700 | [diff] [blame] | 22 | # include "etc1.h" |
| 23 | #endif |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 24 | |
| 25 | /* Fill out buffer with the compressed format Ganesh expects from a colortable |
| 26 | based bitmap. [palette (colortable) + indices]. |
bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 27 | |
| 28 | At the moment Ganesh only supports 8bit version. If Ganesh allowed we others |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 29 | we could detect that the colortable.count is <= 16, and then repack the |
| 30 | indices as nibbles to save RAM, but it would take more time (i.e. a lot |
| 31 | slower than memcpy), so skipping that for now. |
bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 32 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 33 | Ganesh wants a full 256 palette entry, even though Skia's ctable is only as big |
| 34 | as the colortable.count says it is. |
| 35 | */ |
bsalomon | e79a2da | 2014-10-24 12:42:51 -0700 | [diff] [blame] | 36 | static void build_index8_data(void* buffer, const SkBitmap& bitmap) { |
reed | 0689d7b | 2014-06-14 05:30:20 -0700 | [diff] [blame] | 37 | SkASSERT(kIndex_8_SkColorType == bitmap.colorType()); |
bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 38 | |
bsalomon@google.com | 7f4ad5a | 2013-05-07 19:36:43 +0000 | [diff] [blame] | 39 | SkAutoLockPixels alp(bitmap); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 40 | if (!bitmap.readyToDraw()) { |
tomhudson@google.com | 0c00f21 | 2011-12-28 14:59:50 +0000 | [diff] [blame] | 41 | SkDEBUGFAIL("bitmap not ready to draw!"); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 42 | return; |
| 43 | } |
| 44 | |
| 45 | SkColorTable* ctable = bitmap.getColorTable(); |
| 46 | char* dst = (char*)buffer; |
bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 47 | |
reed@google.com | 7111d46 | 2014-03-25 16:20:24 +0000 | [diff] [blame] | 48 | const int count = ctable->count(); |
| 49 | |
| 50 | SkDstPixelInfo dstPI; |
| 51 | dstPI.fColorType = kRGBA_8888_SkColorType; |
| 52 | dstPI.fAlphaType = kPremul_SkAlphaType; |
| 53 | dstPI.fPixels = buffer; |
| 54 | dstPI.fRowBytes = count * sizeof(SkPMColor); |
| 55 | |
| 56 | SkSrcPixelInfo srcPI; |
commit-bot@chromium.org | 28fcae2 | 2014-04-11 17:15:40 +0000 | [diff] [blame] | 57 | srcPI.fColorType = kN32_SkColorType; |
reed@google.com | 7111d46 | 2014-03-25 16:20:24 +0000 | [diff] [blame] | 58 | srcPI.fAlphaType = kPremul_SkAlphaType; |
mtklein | 775b819 | 2014-12-02 09:11:25 -0800 | [diff] [blame^] | 59 | srcPI.fPixels = ctable->readColors(); |
reed@google.com | 7111d46 | 2014-03-25 16:20:24 +0000 | [diff] [blame] | 60 | srcPI.fRowBytes = count * sizeof(SkPMColor); |
| 61 | |
| 62 | srcPI.convertPixelsTo(&dstPI, count, 1); |
| 63 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 64 | // always skip a full 256 number of entries, even if we memcpy'd fewer |
bsalomon | d4cb922 | 2014-08-11 14:19:09 -0700 | [diff] [blame] | 65 | dst += 256 * sizeof(GrColor); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 66 | |
scroggo@google.com | 0ba4bf4 | 2013-02-25 16:02:36 +0000 | [diff] [blame] | 67 | if ((unsigned)bitmap.width() == bitmap.rowBytes()) { |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 68 | memcpy(dst, bitmap.getPixels(), bitmap.getSize()); |
| 69 | } else { |
| 70 | // need to trim off the extra bytes per row |
| 71 | size_t width = bitmap.width(); |
| 72 | size_t rowBytes = bitmap.rowBytes(); |
| 73 | const char* src = (const char*)bitmap.getPixels(); |
| 74 | for (int y = 0; y < bitmap.height(); y++) { |
| 75 | memcpy(dst, src, width); |
| 76 | src += rowBytes; |
| 77 | dst += width; |
| 78 | } |
| 79 | } |
| 80 | } |
| 81 | |
| 82 | //////////////////////////////////////////////////////////////////////////////// |
| 83 | |
bsalomon@google.com | 0797c2c | 2012-12-20 15:13:01 +0000 | [diff] [blame] | 84 | static void generate_bitmap_cache_id(const SkBitmap& bitmap, GrCacheID* id) { |
| 85 | // Our id includes the offset, width, and height so that bitmaps created by extractSubset() |
| 86 | // are unique. |
| 87 | uint32_t genID = bitmap.getGenerationID(); |
reed@google.com | 672588b | 2014-01-08 15:42:01 +0000 | [diff] [blame] | 88 | SkIPoint origin = bitmap.pixelRefOrigin(); |
| 89 | int16_t width = SkToS16(bitmap.width()); |
| 90 | int16_t height = SkToS16(bitmap.height()); |
bsalomon@google.com | 0797c2c | 2012-12-20 15:13:01 +0000 | [diff] [blame] | 91 | |
skia.committer@gmail.com | 2859eb7 | 2012-12-21 02:01:28 +0000 | [diff] [blame] | 92 | GrCacheID::Key key; |
reed@google.com | 672588b | 2014-01-08 15:42:01 +0000 | [diff] [blame] | 93 | memcpy(key.fData8 + 0, &genID, 4); |
| 94 | memcpy(key.fData8 + 4, &origin.fX, 4); |
| 95 | memcpy(key.fData8 + 8, &origin.fY, 4); |
| 96 | memcpy(key.fData8 + 12, &width, 2); |
| 97 | memcpy(key.fData8 + 14, &height, 2); |
| 98 | static const size_t kKeyDataSize = 16; |
bsalomon@google.com | 10a9fb8 | 2013-01-02 19:29:57 +0000 | [diff] [blame] | 99 | memset(key.fData8 + kKeyDataSize, 0, sizeof(key) - kKeyDataSize); |
reed@google.com | 672588b | 2014-01-08 15:42:01 +0000 | [diff] [blame] | 100 | GR_STATIC_ASSERT(sizeof(key) >= kKeyDataSize); |
bsalomon@google.com | 0797c2c | 2012-12-20 15:13:01 +0000 | [diff] [blame] | 101 | static const GrCacheID::Domain gBitmapTextureDomain = GrCacheID::GenerateDomain(); |
| 102 | id->reset(gBitmapTextureDomain, key); |
| 103 | } |
| 104 | |
bsalomon | f2703d8 | 2014-10-28 14:33:06 -0700 | [diff] [blame] | 105 | static void generate_bitmap_texture_desc(const SkBitmap& bitmap, GrSurfaceDesc* desc) { |
| 106 | desc->fFlags = kNone_GrSurfaceFlags; |
bsalomon@google.com | 0797c2c | 2012-12-20 15:13:01 +0000 | [diff] [blame] | 107 | desc->fWidth = bitmap.width(); |
| 108 | desc->fHeight = bitmap.height(); |
commit-bot@chromium.org | 3adcc34 | 2014-04-23 19:18:09 +0000 | [diff] [blame] | 109 | desc->fConfig = SkImageInfo2GrPixelConfig(bitmap.info()); |
bsalomon@google.com | 0797c2c | 2012-12-20 15:13:01 +0000 | [diff] [blame] | 110 | desc->fSampleCnt = 0; |
| 111 | } |
| 112 | |
commit-bot@chromium.org | 50a3043 | 2013-10-24 17:44:27 +0000 | [diff] [blame] | 113 | namespace { |
| 114 | |
| 115 | // When the SkPixelRef genID changes, invalidate a corresponding GrResource described by key. |
| 116 | class GrResourceInvalidator : public SkPixelRef::GenIDChangeListener { |
| 117 | public: |
| 118 | explicit GrResourceInvalidator(GrResourceKey key) : fKey(key) {} |
| 119 | private: |
| 120 | GrResourceKey fKey; |
| 121 | |
| 122 | virtual void onChange() SK_OVERRIDE { |
| 123 | const GrResourceInvalidatedMessage message = { fKey }; |
| 124 | SkMessageBus<GrResourceInvalidatedMessage>::Post(message); |
| 125 | } |
| 126 | }; |
| 127 | |
| 128 | } // namespace |
| 129 | |
| 130 | static void add_genID_listener(GrResourceKey key, SkPixelRef* pixelRef) { |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 131 | SkASSERT(pixelRef); |
commit-bot@chromium.org | 50a3043 | 2013-10-24 17:44:27 +0000 | [diff] [blame] | 132 | pixelRef->addGenIDChangeListener(SkNEW_ARGS(GrResourceInvalidator, (key))); |
| 133 | } |
| 134 | |
sugoi | 0249ec2 | 2014-09-09 08:12:34 -0700 | [diff] [blame] | 135 | static GrTexture* sk_gr_allocate_texture(GrContext* ctx, |
| 136 | bool cache, |
| 137 | const GrTextureParams* params, |
| 138 | const SkBitmap& bm, |
bsalomon | f2703d8 | 2014-10-28 14:33:06 -0700 | [diff] [blame] | 139 | GrSurfaceDesc desc, |
sugoi | 0249ec2 | 2014-09-09 08:12:34 -0700 | [diff] [blame] | 140 | const void* pixels, |
| 141 | size_t rowBytes) { |
| 142 | GrTexture* result; |
| 143 | if (cache) { |
| 144 | // This texture is likely to be used again so leave it in the cache |
| 145 | GrCacheID cacheID; |
| 146 | generate_bitmap_cache_id(bm, &cacheID); |
| 147 | |
| 148 | GrResourceKey key; |
| 149 | result = ctx->createTexture(params, desc, cacheID, pixels, rowBytes, &key); |
| 150 | if (result) { |
| 151 | add_genID_listener(key, bm.pixelRef()); |
| 152 | } |
| 153 | } else { |
| 154 | // This texture is unlikely to be used again (in its present form) so |
| 155 | // just use a scratch texture. This will remove the texture from the |
| 156 | // cache so no one else can find it. Additionally, once unlocked, the |
| 157 | // scratch texture will go to the end of the list for purging so will |
| 158 | // likely be available for this volatile bitmap the next time around. |
bsalomon | e305973 | 2014-10-14 11:47:22 -0700 | [diff] [blame] | 159 | result = ctx->refScratchTexture(desc, GrContext::kExact_ScratchTexMatch); |
sugoi | 0249ec2 | 2014-09-09 08:12:34 -0700 | [diff] [blame] | 160 | if (pixels) { |
| 161 | result->writePixels(0, 0, bm.width(), bm.height(), desc.fConfig, pixels, rowBytes); |
| 162 | } |
| 163 | } |
| 164 | return result; |
| 165 | } |
| 166 | |
krajcevski | 8c111f7 | 2014-06-02 13:51:34 -0700 | [diff] [blame] | 167 | #ifndef SK_IGNORE_ETC1_SUPPORT |
sugoi | 0249ec2 | 2014-09-09 08:12:34 -0700 | [diff] [blame] | 168 | static GrTexture *load_etc1_texture(GrContext* ctx, bool cache, |
krajcevski | 9c0e629 | 2014-06-02 07:38:14 -0700 | [diff] [blame] | 169 | const GrTextureParams* params, |
bsalomon | f2703d8 | 2014-10-28 14:33:06 -0700 | [diff] [blame] | 170 | const SkBitmap &bm, GrSurfaceDesc desc) { |
krajcevski | 99ffe24 | 2014-06-03 13:04:35 -0700 | [diff] [blame] | 171 | SkAutoTUnref<SkData> data(bm.pixelRef()->refEncodedData()); |
krajcevski | 9c0e629 | 2014-06-02 07:38:14 -0700 | [diff] [blame] | 172 | |
| 173 | // Is this even encoded data? |
| 174 | if (NULL == data) { |
| 175 | return NULL; |
| 176 | } |
| 177 | |
| 178 | // Is this a valid PKM encoded data? |
| 179 | const uint8_t *bytes = data->bytes(); |
krajcevski | 99ffe24 | 2014-06-03 13:04:35 -0700 | [diff] [blame] | 180 | if (etc1_pkm_is_valid(bytes)) { |
| 181 | uint32_t encodedWidth = etc1_pkm_get_width(bytes); |
| 182 | uint32_t encodedHeight = etc1_pkm_get_height(bytes); |
| 183 | |
| 184 | // Does the data match the dimensions of the bitmap? If not, |
| 185 | // then we don't know how to scale the image to match it... |
| 186 | if (encodedWidth != static_cast<uint32_t>(bm.width()) || |
| 187 | encodedHeight != static_cast<uint32_t>(bm.height())) { |
| 188 | return NULL; |
| 189 | } |
| 190 | |
| 191 | // Everything seems good... skip ahead to the data. |
| 192 | bytes += ETC_PKM_HEADER_SIZE; |
| 193 | desc.fConfig = kETC1_GrPixelConfig; |
| 194 | } else if (SkKTXFile::is_ktx(bytes)) { |
| 195 | SkKTXFile ktx(data); |
| 196 | |
| 197 | // Is it actually an ETC1 texture? |
krajcevski | 40a1e11 | 2014-08-05 14:13:36 -0700 | [diff] [blame] | 198 | if (!ktx.isCompressedFormat(SkTextureCompressor::kETC1_Format)) { |
krajcevski | 99ffe24 | 2014-06-03 13:04:35 -0700 | [diff] [blame] | 199 | return NULL; |
| 200 | } |
| 201 | |
| 202 | // Does the data match the dimensions of the bitmap? If not, |
| 203 | // then we don't know how to scale the image to match it... |
| 204 | if (ktx.width() != bm.width() || ktx.height() != bm.height()) { |
| 205 | return NULL; |
mtklein | 775b819 | 2014-12-02 09:11:25 -0800 | [diff] [blame^] | 206 | } |
krajcevski | 99ffe24 | 2014-06-03 13:04:35 -0700 | [diff] [blame] | 207 | |
| 208 | bytes = ktx.pixelData(); |
| 209 | desc.fConfig = kETC1_GrPixelConfig; |
| 210 | } else { |
krajcevski | 9c0e629 | 2014-06-02 07:38:14 -0700 | [diff] [blame] | 211 | return NULL; |
| 212 | } |
| 213 | |
sugoi | 0249ec2 | 2014-09-09 08:12:34 -0700 | [diff] [blame] | 214 | return sk_gr_allocate_texture(ctx, cache, params, bm, desc, bytes, 0); |
krajcevski | 9c0e629 | 2014-06-02 07:38:14 -0700 | [diff] [blame] | 215 | } |
krajcevski | 8c111f7 | 2014-06-02 13:51:34 -0700 | [diff] [blame] | 216 | #endif // SK_IGNORE_ETC1_SUPPORT |
krajcevski | 9c0e629 | 2014-06-02 07:38:14 -0700 | [diff] [blame] | 217 | |
sugoi | 0249ec2 | 2014-09-09 08:12:34 -0700 | [diff] [blame] | 218 | static GrTexture *load_yuv_texture(GrContext* ctx, bool cache, const GrTextureParams* params, |
bsalomon | f2703d8 | 2014-10-28 14:33:06 -0700 | [diff] [blame] | 219 | const SkBitmap& bm, const GrSurfaceDesc& desc) { |
sugoi | ff58e46 | 2014-10-16 05:19:31 -0700 | [diff] [blame] | 220 | // Subsets are not supported, the whole pixelRef is loaded when using YUV decoding |
| 221 | if ((bm.pixelRef()->info().width() != bm.info().width()) || |
| 222 | (bm.pixelRef()->info().height() != bm.info().height())) { |
| 223 | return NULL; |
| 224 | } |
| 225 | |
sugoi | 518d83d | 2014-07-21 11:37:39 -0700 | [diff] [blame] | 226 | SkPixelRef* pixelRef = bm.pixelRef(); |
| 227 | SkISize yuvSizes[3]; |
rileya | abaef86 | 2014-09-12 17:45:58 -0700 | [diff] [blame] | 228 | if ((NULL == pixelRef) || !pixelRef->getYUV8Planes(yuvSizes, NULL, NULL, NULL)) { |
sugoi | 518d83d | 2014-07-21 11:37:39 -0700 | [diff] [blame] | 229 | return NULL; |
| 230 | } |
| 231 | |
| 232 | // Allocate the memory for YUV |
| 233 | size_t totalSize(0); |
| 234 | size_t sizes[3], rowBytes[3]; |
| 235 | for (int i = 0; i < 3; ++i) { |
| 236 | rowBytes[i] = yuvSizes[i].fWidth; |
| 237 | totalSize += sizes[i] = rowBytes[i] * yuvSizes[i].fHeight; |
| 238 | } |
| 239 | SkAutoMalloc storage(totalSize); |
| 240 | void* planes[3]; |
| 241 | planes[0] = storage.get(); |
| 242 | planes[1] = (uint8_t*)planes[0] + sizes[0]; |
| 243 | planes[2] = (uint8_t*)planes[1] + sizes[1]; |
| 244 | |
rileya | abaef86 | 2014-09-12 17:45:58 -0700 | [diff] [blame] | 245 | SkYUVColorSpace colorSpace; |
| 246 | |
sugoi | 518d83d | 2014-07-21 11:37:39 -0700 | [diff] [blame] | 247 | // Get the YUV planes |
rileya | abaef86 | 2014-09-12 17:45:58 -0700 | [diff] [blame] | 248 | if (!pixelRef->getYUV8Planes(yuvSizes, planes, rowBytes, &colorSpace)) { |
sugoi | 518d83d | 2014-07-21 11:37:39 -0700 | [diff] [blame] | 249 | return NULL; |
| 250 | } |
| 251 | |
bsalomon | f2703d8 | 2014-10-28 14:33:06 -0700 | [diff] [blame] | 252 | GrSurfaceDesc yuvDesc; |
sugoi | 518d83d | 2014-07-21 11:37:39 -0700 | [diff] [blame] | 253 | yuvDesc.fConfig = kAlpha_8_GrPixelConfig; |
bsalomon | e305973 | 2014-10-14 11:47:22 -0700 | [diff] [blame] | 254 | SkAutoTUnref<GrTexture> yuvTextures[3]; |
sugoi | 518d83d | 2014-07-21 11:37:39 -0700 | [diff] [blame] | 255 | for (int i = 0; i < 3; ++i) { |
| 256 | yuvDesc.fWidth = yuvSizes[i].fWidth; |
| 257 | yuvDesc.fHeight = yuvSizes[i].fHeight; |
bsalomon | e305973 | 2014-10-14 11:47:22 -0700 | [diff] [blame] | 258 | yuvTextures[i].reset( |
| 259 | ctx->refScratchTexture(yuvDesc, GrContext::kApprox_ScratchTexMatch)); |
| 260 | if (!yuvTextures[i] || |
| 261 | !yuvTextures[i]->writePixels(0, 0, yuvDesc.fWidth, yuvDesc.fHeight, |
| 262 | yuvDesc.fConfig, planes[i], rowBytes[i])) { |
sugoi | 518d83d | 2014-07-21 11:37:39 -0700 | [diff] [blame] | 263 | return NULL; |
| 264 | } |
| 265 | } |
| 266 | |
bsalomon | f2703d8 | 2014-10-28 14:33:06 -0700 | [diff] [blame] | 267 | GrSurfaceDesc rtDesc = desc; |
sugoi | 518d83d | 2014-07-21 11:37:39 -0700 | [diff] [blame] | 268 | rtDesc.fFlags = rtDesc.fFlags | |
bsalomon | f2703d8 | 2014-10-28 14:33:06 -0700 | [diff] [blame] | 269 | kRenderTarget_GrSurfaceFlag | |
| 270 | kNoStencil_GrSurfaceFlag; |
sugoi | 518d83d | 2014-07-21 11:37:39 -0700 | [diff] [blame] | 271 | |
sugoi | 0249ec2 | 2014-09-09 08:12:34 -0700 | [diff] [blame] | 272 | GrTexture* result = sk_gr_allocate_texture(ctx, cache, params, bm, rtDesc, NULL, 0); |
sugoi | 518d83d | 2014-07-21 11:37:39 -0700 | [diff] [blame] | 273 | |
sugoi | 518d83d | 2014-07-21 11:37:39 -0700 | [diff] [blame] | 274 | GrRenderTarget* renderTarget = result ? result->asRenderTarget() : NULL; |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 275 | if (renderTarget) { |
bsalomon | e305973 | 2014-10-14 11:47:22 -0700 | [diff] [blame] | 276 | SkAutoTUnref<GrFragmentProcessor> yuvToRgbProcessor( |
| 277 | GrYUVtoRGBEffect::Create(yuvTextures[0], yuvTextures[1], yuvTextures[2], colorSpace)); |
sugoi | 518d83d | 2014-07-21 11:37:39 -0700 | [diff] [blame] | 278 | GrPaint paint; |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 279 | paint.addColorProcessor(yuvToRgbProcessor); |
sugoi | 518d83d | 2014-07-21 11:37:39 -0700 | [diff] [blame] | 280 | SkRect r = SkRect::MakeWH(SkIntToScalar(yuvSizes[0].fWidth), |
| 281 | SkIntToScalar(yuvSizes[0].fHeight)); |
| 282 | GrContext::AutoRenderTarget autoRT(ctx, renderTarget); |
| 283 | GrContext::AutoMatrix am; |
| 284 | am.setIdentity(ctx); |
| 285 | GrContext::AutoClip ac(ctx, GrContext::AutoClip::kWideOpen_InitialClip); |
| 286 | ctx->drawRect(paint, r); |
| 287 | } else { |
| 288 | SkSafeSetNull(result); |
| 289 | } |
| 290 | |
| 291 | return result; |
| 292 | } |
| 293 | |
robertphillips@google.com | 1f47f4f | 2012-08-16 14:49:16 +0000 | [diff] [blame] | 294 | static GrTexture* sk_gr_create_bitmap_texture(GrContext* ctx, |
bsalomon@google.com | 0797c2c | 2012-12-20 15:13:01 +0000 | [diff] [blame] | 295 | bool cache, |
robertphillips@google.com | 1f47f4f | 2012-08-16 14:49:16 +0000 | [diff] [blame] | 296 | const GrTextureParams* params, |
| 297 | const SkBitmap& origBitmap) { |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 298 | SkBitmap tmpBitmap; |
| 299 | |
| 300 | const SkBitmap* bitmap = &origBitmap; |
bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 301 | |
bsalomon | f2703d8 | 2014-10-28 14:33:06 -0700 | [diff] [blame] | 302 | GrSurfaceDesc desc; |
bsalomon@google.com | 0797c2c | 2012-12-20 15:13:01 +0000 | [diff] [blame] | 303 | generate_bitmap_texture_desc(*bitmap, &desc); |
bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 304 | |
reed | 0689d7b | 2014-06-14 05:30:20 -0700 | [diff] [blame] | 305 | if (kIndex_8_SkColorType == bitmap->colorType()) { |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 306 | // build_compressed_data doesn't do npot->pot expansion |
| 307 | // and paletted textures can't be sub-updated |
bsalomon | e79a2da | 2014-10-24 12:42:51 -0700 | [diff] [blame] | 308 | if (cache && ctx->supportsIndex8PixelConfig(params, bitmap->width(), bitmap->height())) { |
bsalomon | d4cb922 | 2014-08-11 14:19:09 -0700 | [diff] [blame] | 309 | size_t imageSize = GrCompressedFormatDataSize(kIndex_8_GrPixelConfig, |
| 310 | bitmap->width(), bitmap->height()); |
| 311 | SkAutoMalloc storage(imageSize); |
bsalomon | e79a2da | 2014-10-24 12:42:51 -0700 | [diff] [blame] | 312 | build_index8_data(storage.get(), origBitmap); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 313 | |
| 314 | // our compressed data will be trimmed, so pass width() for its |
| 315 | // "rowBytes", since they are the same now. |
sugoi | 0249ec2 | 2014-09-09 08:12:34 -0700 | [diff] [blame] | 316 | return sk_gr_allocate_texture(ctx, cache, params, origBitmap, |
| 317 | desc, storage.get(), bitmap->width()); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 318 | } else { |
commit-bot@chromium.org | 28fcae2 | 2014-04-11 17:15:40 +0000 | [diff] [blame] | 319 | origBitmap.copyTo(&tmpBitmap, kN32_SkColorType); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 320 | // now bitmap points to our temp, which has been promoted to 32bits |
| 321 | bitmap = &tmpBitmap; |
commit-bot@chromium.org | 3adcc34 | 2014-04-23 19:18:09 +0000 | [diff] [blame] | 322 | desc.fConfig = SkImageInfo2GrPixelConfig(bitmap->info()); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 323 | } |
krajcevski | 309e869 | 2014-06-02 08:02:45 -0700 | [diff] [blame] | 324 | } |
krajcevski | 9c0e629 | 2014-06-02 07:38:14 -0700 | [diff] [blame] | 325 | |
| 326 | // Is this an ETC1 encoded texture? |
krajcevski | 8c111f7 | 2014-06-02 13:51:34 -0700 | [diff] [blame] | 327 | #ifndef SK_IGNORE_ETC1_SUPPORT |
krajcevski | 9a3cdbb | 2014-06-05 07:03:39 -0700 | [diff] [blame] | 328 | else if ( |
bungeman | 77cd8b0 | 2014-09-10 14:59:59 -0700 | [diff] [blame] | 329 | // We do not support scratch ETC1 textures, hence they should all be at least |
| 330 | // trying to go to the cache. |
| 331 | cache |
krajcevski | 9a3cdbb | 2014-06-05 07:03:39 -0700 | [diff] [blame] | 332 | // Make sure that the underlying device supports ETC1 textures before we go ahead |
| 333 | // and check the data. |
bungeman | 77cd8b0 | 2014-09-10 14:59:59 -0700 | [diff] [blame] | 334 | && ctx->getGpu()->caps()->isConfigTexturable(kETC1_GrPixelConfig) |
krajcevski | 9a3cdbb | 2014-06-05 07:03:39 -0700 | [diff] [blame] | 335 | // If the bitmap had compressed data and was then uncompressed, it'll still return |
| 336 | // compressed data on 'refEncodedData' and upload it. Probably not good, since if |
| 337 | // the bitmap has available pixels, then they might not be what the decompressed |
| 338 | // data is. |
| 339 | && !(bitmap->readyToDraw())) { |
sugoi | 0249ec2 | 2014-09-09 08:12:34 -0700 | [diff] [blame] | 340 | GrTexture *texture = load_etc1_texture(ctx, cache, params, *bitmap, desc); |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 341 | if (texture) { |
krajcevski | 9c0e629 | 2014-06-02 07:38:14 -0700 | [diff] [blame] | 342 | return texture; |
| 343 | } |
bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 344 | } |
krajcevski | 8c111f7 | 2014-06-02 13:51:34 -0700 | [diff] [blame] | 345 | #endif // SK_IGNORE_ETC1_SUPPORT |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 346 | |
sugoi | 518d83d | 2014-07-21 11:37:39 -0700 | [diff] [blame] | 347 | else { |
sugoi | 0249ec2 | 2014-09-09 08:12:34 -0700 | [diff] [blame] | 348 | GrTexture *texture = load_yuv_texture(ctx, cache, params, *bitmap, desc); |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 349 | if (texture) { |
sugoi | 518d83d | 2014-07-21 11:37:39 -0700 | [diff] [blame] | 350 | return texture; |
| 351 | } |
| 352 | } |
bsalomon@google.com | 7f4ad5a | 2013-05-07 19:36:43 +0000 | [diff] [blame] | 353 | SkAutoLockPixels alp(*bitmap); |
| 354 | if (!bitmap->readyToDraw()) { |
| 355 | return NULL; |
| 356 | } |
commit-bot@chromium.org | 50a3043 | 2013-10-24 17:44:27 +0000 | [diff] [blame] | 357 | |
sugoi | 0249ec2 | 2014-09-09 08:12:34 -0700 | [diff] [blame] | 358 | return sk_gr_allocate_texture(ctx, cache, params, origBitmap, desc, |
| 359 | bitmap->getPixels(), bitmap->rowBytes()); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 360 | } |
| 361 | |
bsalomon@google.com | 0797c2c | 2012-12-20 15:13:01 +0000 | [diff] [blame] | 362 | bool GrIsBitmapInCache(const GrContext* ctx, |
| 363 | const SkBitmap& bitmap, |
| 364 | const GrTextureParams* params) { |
| 365 | GrCacheID cacheID; |
| 366 | generate_bitmap_cache_id(bitmap, &cacheID); |
| 367 | |
bsalomon | f2703d8 | 2014-10-28 14:33:06 -0700 | [diff] [blame] | 368 | GrSurfaceDesc desc; |
bsalomon@google.com | 0797c2c | 2012-12-20 15:13:01 +0000 | [diff] [blame] | 369 | generate_bitmap_texture_desc(bitmap, &desc); |
| 370 | return ctx->isTextureInCache(desc, cacheID, params); |
| 371 | } |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 372 | |
bsalomon | bcf0a52 | 2014-10-08 08:40:09 -0700 | [diff] [blame] | 373 | GrTexture* GrRefCachedBitmapTexture(GrContext* ctx, |
| 374 | const SkBitmap& bitmap, |
| 375 | const GrTextureParams* params) { |
bsalomon | ebfce41 | 2014-10-07 06:20:25 -0700 | [diff] [blame] | 376 | GrTexture* result = NULL; |
rileya@google.com | 24f3ad1 | 2012-07-18 21:47:40 +0000 | [diff] [blame] | 377 | |
bsalomon@google.com | 0797c2c | 2012-12-20 15:13:01 +0000 | [diff] [blame] | 378 | bool cache = !bitmap.isVolatile(); |
| 379 | |
| 380 | if (cache) { |
| 381 | // If the bitmap isn't changing try to find a cached copy first. |
| 382 | |
| 383 | GrCacheID cacheID; |
| 384 | generate_bitmap_cache_id(bitmap, &cacheID); |
rileya@google.com | 24f3ad1 | 2012-07-18 21:47:40 +0000 | [diff] [blame] | 385 | |
bsalomon | f2703d8 | 2014-10-28 14:33:06 -0700 | [diff] [blame] | 386 | GrSurfaceDesc desc; |
bsalomon@google.com | 0797c2c | 2012-12-20 15:13:01 +0000 | [diff] [blame] | 387 | generate_bitmap_texture_desc(bitmap, &desc); |
rileya@google.com | 24f3ad1 | 2012-07-18 21:47:40 +0000 | [diff] [blame] | 388 | |
bsalomon@google.com | 95ed55a | 2013-01-24 14:46:47 +0000 | [diff] [blame] | 389 | result = ctx->findAndRefTexture(desc, cacheID, params); |
bsalomon@google.com | 0797c2c | 2012-12-20 15:13:01 +0000 | [diff] [blame] | 390 | } |
| 391 | if (NULL == result) { |
| 392 | result = sk_gr_create_bitmap_texture(ctx, cache, params, bitmap); |
rileya@google.com | 24f3ad1 | 2012-07-18 21:47:40 +0000 | [diff] [blame] | 393 | } |
robertphillips@google.com | 1f47f4f | 2012-08-16 14:49:16 +0000 | [diff] [blame] | 394 | if (NULL == result) { |
tfarina | 38406c8 | 2014-10-31 07:11:12 -0700 | [diff] [blame] | 395 | SkDebugf("---- failed to create texture for cache [%d %d]\n", |
| 396 | bitmap.width(), bitmap.height()); |
rileya@google.com | 24f3ad1 | 2012-07-18 21:47:40 +0000 | [diff] [blame] | 397 | } |
robertphillips@google.com | 1f47f4f | 2012-08-16 14:49:16 +0000 | [diff] [blame] | 398 | return result; |
rileya@google.com | 24f3ad1 | 2012-07-18 21:47:40 +0000 | [diff] [blame] | 399 | } |
| 400 | |
rileya@google.com | 24f3ad1 | 2012-07-18 21:47:40 +0000 | [diff] [blame] | 401 | /////////////////////////////////////////////////////////////////////////////// |
| 402 | |
commit-bot@chromium.org | 15a1405 | 2014-02-16 00:59:25 +0000 | [diff] [blame] | 403 | // alphatype is ignore for now, but if GrPixelConfig is expanded to encompass |
| 404 | // alpha info, that will be considered. |
| 405 | GrPixelConfig SkImageInfo2GrPixelConfig(SkColorType ct, SkAlphaType) { |
| 406 | switch (ct) { |
| 407 | case kUnknown_SkColorType: |
| 408 | return kUnknown_GrPixelConfig; |
| 409 | case kAlpha_8_SkColorType: |
| 410 | return kAlpha_8_GrPixelConfig; |
| 411 | case kRGB_565_SkColorType: |
| 412 | return kRGB_565_GrPixelConfig; |
| 413 | case kARGB_4444_SkColorType: |
| 414 | return kRGBA_4444_GrPixelConfig; |
| 415 | case kRGBA_8888_SkColorType: |
| 416 | return kRGBA_8888_GrPixelConfig; |
| 417 | case kBGRA_8888_SkColorType: |
| 418 | return kBGRA_8888_GrPixelConfig; |
| 419 | case kIndex_8_SkColorType: |
| 420 | return kIndex_8_GrPixelConfig; |
| 421 | } |
| 422 | SkASSERT(0); // shouldn't get here |
| 423 | return kUnknown_GrPixelConfig; |
| 424 | } |
| 425 | |
reed@google.com | bf79023 | 2013-12-13 19:45:58 +0000 | [diff] [blame] | 426 | bool GrPixelConfig2ColorType(GrPixelConfig config, SkColorType* ctOut) { |
| 427 | SkColorType ct; |
| 428 | switch (config) { |
| 429 | case kAlpha_8_GrPixelConfig: |
| 430 | ct = kAlpha_8_SkColorType; |
| 431 | break; |
| 432 | case kIndex_8_GrPixelConfig: |
| 433 | ct = kIndex_8_SkColorType; |
| 434 | break; |
| 435 | case kRGB_565_GrPixelConfig: |
| 436 | ct = kRGB_565_SkColorType; |
| 437 | break; |
| 438 | case kRGBA_4444_GrPixelConfig: |
| 439 | ct = kARGB_4444_SkColorType; |
| 440 | break; |
| 441 | case kRGBA_8888_GrPixelConfig: |
| 442 | ct = kRGBA_8888_SkColorType; |
| 443 | break; |
| 444 | case kBGRA_8888_GrPixelConfig: |
| 445 | ct = kBGRA_8888_SkColorType; |
| 446 | break; |
| 447 | default: |
| 448 | return false; |
| 449 | } |
| 450 | if (ctOut) { |
| 451 | *ctOut = ct; |
| 452 | } |
| 453 | return true; |
| 454 | } |
commit-bot@chromium.org | 8dcff64 | 2014-05-15 20:32:48 +0000 | [diff] [blame] | 455 | |
| 456 | /////////////////////////////////////////////////////////////////////////////// |
| 457 | |
bsalomon | 83d081a | 2014-07-08 09:56:10 -0700 | [diff] [blame] | 458 | void SkPaint2GrPaintNoShader(GrContext* context, const SkPaint& skPaint, GrColor paintColor, |
commit-bot@chromium.org | 8dcff64 | 2014-05-15 20:32:48 +0000 | [diff] [blame] | 459 | bool constantColor, GrPaint* grPaint) { |
| 460 | |
| 461 | grPaint->setDither(skPaint.isDither()); |
| 462 | grPaint->setAntiAlias(skPaint.isAntiAlias()); |
| 463 | |
| 464 | SkXfermode::Coeff sm; |
| 465 | SkXfermode::Coeff dm; |
| 466 | |
| 467 | SkXfermode* mode = skPaint.getXfermode(); |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 468 | GrFragmentProcessor* xferProcessor = NULL; |
| 469 | if (SkXfermode::asFragmentProcessorOrCoeff(mode, &xferProcessor, &sm, &dm)) { |
| 470 | if (xferProcessor) { |
| 471 | grPaint->addColorProcessor(xferProcessor)->unref(); |
commit-bot@chromium.org | 8dcff64 | 2014-05-15 20:32:48 +0000 | [diff] [blame] | 472 | sm = SkXfermode::kOne_Coeff; |
| 473 | dm = SkXfermode::kZero_Coeff; |
| 474 | } |
| 475 | } else { |
| 476 | //SkDEBUGCODE(SkDebugf("Unsupported xfer mode.\n");) |
| 477 | // Fall back to src-over |
| 478 | sm = SkXfermode::kOne_Coeff; |
| 479 | dm = SkXfermode::kISA_Coeff; |
| 480 | } |
| 481 | grPaint->setBlendFunc(sk_blend_to_grblend(sm), sk_blend_to_grblend(dm)); |
mtklein | 775b819 | 2014-12-02 09:11:25 -0800 | [diff] [blame^] | 482 | |
dandov | 9de5b51 | 2014-06-10 14:38:28 -0700 | [diff] [blame] | 483 | //set the color of the paint to the one of the parameter |
bsalomon | 83d081a | 2014-07-08 09:56:10 -0700 | [diff] [blame] | 484 | grPaint->setColor(paintColor); |
commit-bot@chromium.org | 8dcff64 | 2014-05-15 20:32:48 +0000 | [diff] [blame] | 485 | |
| 486 | SkColorFilter* colorFilter = skPaint.getColorFilter(); |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 487 | if (colorFilter) { |
commit-bot@chromium.org | 8dcff64 | 2014-05-15 20:32:48 +0000 | [diff] [blame] | 488 | // if the source color is a constant then apply the filter here once rather than per pixel |
| 489 | // in a shader. |
| 490 | if (constantColor) { |
| 491 | SkColor filtered = colorFilter->filterColor(skPaint.getColor()); |
| 492 | grPaint->setColor(SkColor2GrColor(filtered)); |
| 493 | } else { |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 494 | SkAutoTUnref<GrFragmentProcessor> fp(colorFilter->asFragmentProcessor(context)); |
| 495 | if (fp.get()) { |
| 496 | grPaint->addColorProcessor(fp); |
commit-bot@chromium.org | 8dcff64 | 2014-05-15 20:32:48 +0000 | [diff] [blame] | 497 | } |
| 498 | } |
| 499 | } |
krajcevski | f461a8f | 2014-06-19 14:14:06 -0700 | [diff] [blame] | 500 | |
| 501 | #ifndef SK_IGNORE_GPU_DITHER |
| 502 | // If the dither flag is set, then we need to see if the underlying context |
| 503 | // supports it. If not, then install a dither effect. |
| 504 | if (skPaint.isDither() && grPaint->numColorStages() > 0) { |
| 505 | // What are we rendering into? |
| 506 | const GrRenderTarget *target = context->getRenderTarget(); |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 507 | SkASSERT(target); |
krajcevski | f461a8f | 2014-06-19 14:14:06 -0700 | [diff] [blame] | 508 | |
| 509 | // Suspect the dithering flag has no effect on these configs, otherwise |
| 510 | // fall back on setting the appropriate state. |
| 511 | if (target->config() == kRGBA_8888_GrPixelConfig || |
| 512 | target->config() == kBGRA_8888_GrPixelConfig) { |
| 513 | // The dither flag is set and the target is likely |
| 514 | // not going to be dithered by the GPU. |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 515 | SkAutoTUnref<GrFragmentProcessor> fp(GrDitherEffect::Create()); |
| 516 | if (fp.get()) { |
| 517 | grPaint->addColorProcessor(fp); |
krajcevski | f461a8f | 2014-06-19 14:14:06 -0700 | [diff] [blame] | 518 | grPaint->setDither(false); |
| 519 | } |
| 520 | } |
| 521 | } |
| 522 | #endif |
commit-bot@chromium.org | 8dcff64 | 2014-05-15 20:32:48 +0000 | [diff] [blame] | 523 | } |
| 524 | |
commit-bot@chromium.org | 9e967ad | 2014-05-20 15:06:29 +0000 | [diff] [blame] | 525 | /** |
| 526 | * Unlike GrContext::AutoMatrix, this doesn't require setting a new matrix. GrContext::AutoMatrix |
| 527 | * likes to set the new matrix in its constructor because it is usually necessary to simulataneously |
| 528 | * update a GrPaint. This AutoMatrix is used while initially setting up GrPaint, however. |
| 529 | */ |
| 530 | class AutoMatrix { |
| 531 | public: |
| 532 | AutoMatrix(GrContext* context) { |
| 533 | fMatrix = context->getMatrix(); |
| 534 | fContext = context; |
| 535 | } |
| 536 | ~AutoMatrix() { |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 537 | SkASSERT(fContext); |
commit-bot@chromium.org | 9e967ad | 2014-05-20 15:06:29 +0000 | [diff] [blame] | 538 | fContext->setMatrix(fMatrix); |
| 539 | } |
| 540 | private: |
| 541 | GrContext* fContext; |
| 542 | SkMatrix fMatrix; |
| 543 | }; |
| 544 | |
commit-bot@chromium.org | 3595f88 | 2014-05-19 19:35:57 +0000 | [diff] [blame] | 545 | void SkPaint2GrPaintShader(GrContext* context, const SkPaint& skPaint, |
commit-bot@chromium.org | 8dcff64 | 2014-05-15 20:32:48 +0000 | [diff] [blame] | 546 | bool constantColor, GrPaint* grPaint) { |
| 547 | SkShader* shader = skPaint.getShader(); |
| 548 | if (NULL == shader) { |
dandov | 9de5b51 | 2014-06-10 14:38:28 -0700 | [diff] [blame] | 549 | SkPaint2GrPaintNoShader(context, skPaint, SkColor2GrColor(skPaint.getColor()), |
| 550 | constantColor, grPaint); |
commit-bot@chromium.org | 8dcff64 | 2014-05-15 20:32:48 +0000 | [diff] [blame] | 551 | return; |
| 552 | } |
| 553 | |
bsalomon | 83d081a | 2014-07-08 09:56:10 -0700 | [diff] [blame] | 554 | GrColor paintColor = SkColor2GrColor(skPaint.getColor()); |
krajcevski | f461a8f | 2014-06-19 14:14:06 -0700 | [diff] [blame] | 555 | |
| 556 | // Start a new block here in order to preserve our context state after calling |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 557 | // asFragmentProcessor(). Since these calls get passed back to the client, we don't really |
krajcevski | f461a8f | 2014-06-19 14:14:06 -0700 | [diff] [blame] | 558 | // want them messing around with the context. |
| 559 | { |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 560 | // SkShader::asFragmentProcessor() may do offscreen rendering. Save off the current RT, |
| 561 | // clip, and matrix. We don't reset the matrix on the context because |
| 562 | // SkShader::asFragmentProcessor may use GrContext::getMatrix() to know the transformation |
| 563 | // from local coords to device space. |
krajcevski | f461a8f | 2014-06-19 14:14:06 -0700 | [diff] [blame] | 564 | GrContext::AutoRenderTarget art(context, NULL); |
| 565 | GrContext::AutoClip ac(context, GrContext::AutoClip::kWideOpen_InitialClip); |
| 566 | AutoMatrix am(context); |
| 567 | |
bsalomon | 83d081a | 2014-07-08 09:56:10 -0700 | [diff] [blame] | 568 | // Allow the shader to modify paintColor and also create an effect to be installed as |
| 569 | // the first color effect on the GrPaint. |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 570 | GrFragmentProcessor* fp = NULL; |
| 571 | if (shader->asFragmentProcessor(context, skPaint, NULL, &paintColor, &fp) && fp) { |
| 572 | grPaint->addColorProcessor(fp)->unref(); |
krajcevski | f461a8f | 2014-06-19 14:14:06 -0700 | [diff] [blame] | 573 | constantColor = false; |
| 574 | } |
commit-bot@chromium.org | 8dcff64 | 2014-05-15 20:32:48 +0000 | [diff] [blame] | 575 | } |
krajcevski | f461a8f | 2014-06-19 14:14:06 -0700 | [diff] [blame] | 576 | |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 577 | // The grcolor is automatically set when calling asFragmentProcessor. |
dandov | 9de5b51 | 2014-06-10 14:38:28 -0700 | [diff] [blame] | 578 | // If the shader can be seen as an effect it returns true and adds its effect to the grpaint. |
bsalomon | 83d081a | 2014-07-08 09:56:10 -0700 | [diff] [blame] | 579 | SkPaint2GrPaintNoShader(context, skPaint, paintColor, constantColor, grPaint); |
commit-bot@chromium.org | 8dcff64 | 2014-05-15 20:32:48 +0000 | [diff] [blame] | 580 | } |