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