commit-bot@chromium.org | c5d9bb0 | 2014-04-08 15:19:34 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2014 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 | #include "SkPictureShader.h" |
| 9 | |
| 10 | #include "SkBitmap.h" |
| 11 | #include "SkBitmapProcShader.h" |
| 12 | #include "SkCanvas.h" |
| 13 | #include "SkMatrixUtils.h" |
| 14 | #include "SkPicture.h" |
| 15 | #include "SkReadBuffer.h" |
fmalita | 23df2d6 | 2014-10-22 07:39:08 -0700 | [diff] [blame] | 16 | #include "SkResourceCache.h" |
commit-bot@chromium.org | c5d9bb0 | 2014-04-08 15:19:34 +0000 | [diff] [blame] | 17 | |
| 18 | #if SK_SUPPORT_GPU |
| 19 | #include "GrContext.h" |
| 20 | #endif |
| 21 | |
fmalita | 171e5b7 | 2014-10-22 11:20:40 -0700 | [diff] [blame^] | 22 | namespace { |
| 23 | static unsigned gBitmapSkaderKeyNamespaceLabel; |
| 24 | |
fmalita | 23df2d6 | 2014-10-22 07:39:08 -0700 | [diff] [blame] | 25 | struct BitmapShaderKey : public SkResourceCache::Key { |
| 26 | public: |
| 27 | BitmapShaderKey(uint32_t pictureID, |
| 28 | const SkRect& tile, |
| 29 | SkShader::TileMode tmx, |
| 30 | SkShader::TileMode tmy, |
| 31 | const SkSize& scale, |
| 32 | const SkMatrix& localMatrix) |
| 33 | : fPictureID(pictureID) |
| 34 | , fTile(tile) |
| 35 | , fTmx(tmx) |
| 36 | , fTmy(tmy) |
| 37 | , fScale(scale) |
| 38 | , fLocalMatrix(localMatrix) { |
| 39 | |
| 40 | static const size_t keySize = sizeof(fPictureID) + |
| 41 | sizeof(fTile) + |
| 42 | sizeof(fTmx) + sizeof(fTmy) + |
| 43 | sizeof(fScale) + |
| 44 | sizeof(fLocalMatrix); |
| 45 | // This better be packed. |
| 46 | SkASSERT(sizeof(uint32_t) * (&fEndOfStruct - &fPictureID) == keySize); |
fmalita | 171e5b7 | 2014-10-22 11:20:40 -0700 | [diff] [blame^] | 47 | this->init(&gBitmapSkaderKeyNamespaceLabel, keySize); |
fmalita | 23df2d6 | 2014-10-22 07:39:08 -0700 | [diff] [blame] | 48 | } |
| 49 | |
| 50 | private: |
| 51 | uint32_t fPictureID; |
| 52 | SkRect fTile; |
| 53 | SkShader::TileMode fTmx, fTmy; |
| 54 | SkSize fScale; |
| 55 | SkMatrix fLocalMatrix; |
| 56 | |
| 57 | SkDEBUGCODE(uint32_t fEndOfStruct;) |
| 58 | }; |
| 59 | |
| 60 | struct BitmapShaderRec : public SkResourceCache::Rec { |
| 61 | BitmapShaderRec(const BitmapShaderKey& key, SkShader* tileShader, size_t bitmapBytes) |
| 62 | : fKey(key) |
| 63 | , fShader(SkRef(tileShader)) |
| 64 | , fBitmapBytes(bitmapBytes) {} |
| 65 | |
| 66 | BitmapShaderKey fKey; |
| 67 | SkAutoTUnref<SkShader> fShader; |
| 68 | size_t fBitmapBytes; |
| 69 | |
| 70 | virtual const Key& getKey() const SK_OVERRIDE { return fKey; } |
| 71 | virtual size_t bytesUsed() const SK_OVERRIDE { |
| 72 | return sizeof(fKey) + sizeof(SkShader) + fBitmapBytes; |
| 73 | } |
| 74 | |
| 75 | static bool Visitor(const SkResourceCache::Rec& baseRec, void* contextShader) { |
| 76 | const BitmapShaderRec& rec = static_cast<const BitmapShaderRec&>(baseRec); |
| 77 | SkAutoTUnref<SkShader>* result = reinterpret_cast<SkAutoTUnref<SkShader>*>(contextShader); |
| 78 | |
| 79 | result->reset(SkRef(rec.fShader.get())); |
| 80 | return true; |
| 81 | } |
| 82 | }; |
| 83 | |
fmalita | 23df2d6 | 2014-10-22 07:39:08 -0700 | [diff] [blame] | 84 | static bool cache_try_alloc_pixels(SkBitmap* bitmap) { |
fmalita | 171e5b7 | 2014-10-22 11:20:40 -0700 | [diff] [blame^] | 85 | SkBitmap::Allocator* allocator = SkResourceCache::GetAllocator(); |
fmalita | 23df2d6 | 2014-10-22 07:39:08 -0700 | [diff] [blame] | 86 | |
fmalita | 171e5b7 | 2014-10-22 11:20:40 -0700 | [diff] [blame^] | 87 | return NULL != allocator |
| 88 | ? allocator->allocPixelRef(bitmap, NULL) |
| 89 | : bitmap->tryAllocPixels(); |
fmalita | 23df2d6 | 2014-10-22 07:39:08 -0700 | [diff] [blame] | 90 | } |
| 91 | |
fmalita | 171e5b7 | 2014-10-22 11:20:40 -0700 | [diff] [blame^] | 92 | } // namespace |
| 93 | |
robertphillips | e846499 | 2014-07-14 07:53:26 -0700 | [diff] [blame] | 94 | SkPictureShader::SkPictureShader(const SkPicture* picture, TileMode tmx, TileMode tmy, |
fmalita | b5f7826 | 2014-08-06 13:07:15 -0700 | [diff] [blame] | 95 | const SkMatrix* localMatrix, const SkRect* tile) |
commit-bot@chromium.org | 5aacfe9 | 2014-05-02 21:23:52 +0000 | [diff] [blame] | 96 | : INHERITED(localMatrix) |
| 97 | , fPicture(SkRef(picture)) |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 98 | , fTile(tile ? *tile : picture->cullRect()) |
commit-bot@chromium.org | c5d9bb0 | 2014-04-08 15:19:34 +0000 | [diff] [blame] | 99 | , fTmx(tmx) |
fmalita | b5f7826 | 2014-08-06 13:07:15 -0700 | [diff] [blame] | 100 | , fTmy(tmy) { |
fmalita | b5f7826 | 2014-08-06 13:07:15 -0700 | [diff] [blame] | 101 | } |
commit-bot@chromium.org | c5d9bb0 | 2014-04-08 15:19:34 +0000 | [diff] [blame] | 102 | |
reed | 9fa60da | 2014-08-21 07:59:51 -0700 | [diff] [blame] | 103 | #ifdef SK_SUPPORT_LEGACY_DEEPFLATTENING |
| 104 | SkPictureShader::SkPictureShader(SkReadBuffer& buffer) : INHERITED(buffer) { |
commit-bot@chromium.org | c5d9bb0 | 2014-04-08 15:19:34 +0000 | [diff] [blame] | 105 | fTmx = static_cast<SkShader::TileMode>(buffer.read32()); |
| 106 | fTmy = static_cast<SkShader::TileMode>(buffer.read32()); |
fmalita | b5f7826 | 2014-08-06 13:07:15 -0700 | [diff] [blame] | 107 | buffer.readRect(&fTile); |
commit-bot@chromium.org | 855e88e | 2014-04-21 19:33:12 +0000 | [diff] [blame] | 108 | fPicture = SkPicture::CreateFromBuffer(buffer); |
commit-bot@chromium.org | c5d9bb0 | 2014-04-08 15:19:34 +0000 | [diff] [blame] | 109 | } |
reed | 9fa60da | 2014-08-21 07:59:51 -0700 | [diff] [blame] | 110 | #endif |
commit-bot@chromium.org | c5d9bb0 | 2014-04-08 15:19:34 +0000 | [diff] [blame] | 111 | |
| 112 | SkPictureShader::~SkPictureShader() { |
commit-bot@chromium.org | 855e88e | 2014-04-21 19:33:12 +0000 | [diff] [blame] | 113 | fPicture->unref(); |
commit-bot@chromium.org | c5d9bb0 | 2014-04-08 15:19:34 +0000 | [diff] [blame] | 114 | } |
| 115 | |
robertphillips | e846499 | 2014-07-14 07:53:26 -0700 | [diff] [blame] | 116 | SkPictureShader* SkPictureShader::Create(const SkPicture* picture, TileMode tmx, TileMode tmy, |
fmalita | b5f7826 | 2014-08-06 13:07:15 -0700 | [diff] [blame] | 117 | const SkMatrix* localMatrix, const SkRect* tile) { |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 118 | if (!picture || picture->cullRect().isEmpty() || (tile && tile->isEmpty())) { |
commit-bot@chromium.org | 855e88e | 2014-04-21 19:33:12 +0000 | [diff] [blame] | 119 | return NULL; |
| 120 | } |
fmalita | b5f7826 | 2014-08-06 13:07:15 -0700 | [diff] [blame] | 121 | return SkNEW_ARGS(SkPictureShader, (picture, tmx, tmy, localMatrix, tile)); |
commit-bot@chromium.org | c5d9bb0 | 2014-04-08 15:19:34 +0000 | [diff] [blame] | 122 | } |
| 123 | |
reed | 9fa60da | 2014-08-21 07:59:51 -0700 | [diff] [blame] | 124 | SkFlattenable* SkPictureShader::CreateProc(SkReadBuffer& buffer) { |
| 125 | SkMatrix lm; |
| 126 | buffer.readMatrix(&lm); |
| 127 | TileMode mx = (TileMode)buffer.read32(); |
| 128 | TileMode my = (TileMode)buffer.read32(); |
| 129 | SkRect tile; |
| 130 | buffer.readRect(&tile); |
| 131 | SkAutoTUnref<SkPicture> picture(SkPicture::CreateFromBuffer(buffer)); |
| 132 | return SkPictureShader::Create(picture, mx, my, &lm, &tile); |
| 133 | } |
commit-bot@chromium.org | c5d9bb0 | 2014-04-08 15:19:34 +0000 | [diff] [blame] | 134 | |
reed | 9fa60da | 2014-08-21 07:59:51 -0700 | [diff] [blame] | 135 | void SkPictureShader::flatten(SkWriteBuffer& buffer) const { |
| 136 | buffer.writeMatrix(this->getLocalMatrix()); |
commit-bot@chromium.org | c5d9bb0 | 2014-04-08 15:19:34 +0000 | [diff] [blame] | 137 | buffer.write32(fTmx); |
| 138 | buffer.write32(fTmy); |
fmalita | b5f7826 | 2014-08-06 13:07:15 -0700 | [diff] [blame] | 139 | buffer.writeRect(fTile); |
commit-bot@chromium.org | 855e88e | 2014-04-21 19:33:12 +0000 | [diff] [blame] | 140 | fPicture->flatten(buffer); |
commit-bot@chromium.org | c5d9bb0 | 2014-04-08 15:19:34 +0000 | [diff] [blame] | 141 | } |
| 142 | |
commit-bot@chromium.org | 80116dc | 2014-05-06 17:16:03 +0000 | [diff] [blame] | 143 | SkShader* SkPictureShader::refBitmapShader(const SkMatrix& matrix, const SkMatrix* localM) const { |
robertphillips | a8d7f0b | 2014-08-29 08:03:56 -0700 | [diff] [blame] | 144 | SkASSERT(fPicture && !fPicture->cullRect().isEmpty()); |
commit-bot@chromium.org | c5d9bb0 | 2014-04-08 15:19:34 +0000 | [diff] [blame] | 145 | |
| 146 | SkMatrix m; |
commit-bot@chromium.org | 5970f62 | 2014-05-12 20:42:21 +0000 | [diff] [blame] | 147 | m.setConcat(matrix, this->getLocalMatrix()); |
commit-bot@chromium.org | 80116dc | 2014-05-06 17:16:03 +0000 | [diff] [blame] | 148 | if (localM) { |
| 149 | m.preConcat(*localM); |
| 150 | } |
commit-bot@chromium.org | c5d9bb0 | 2014-04-08 15:19:34 +0000 | [diff] [blame] | 151 | |
| 152 | // Use a rotation-invariant scale |
| 153 | SkPoint scale; |
| 154 | if (!SkDecomposeUpper2x2(m, NULL, &scale, NULL)) { |
| 155 | // Decomposition failed, use an approximation. |
| 156 | scale.set(SkScalarSqrt(m.getScaleX() * m.getScaleX() + m.getSkewX() * m.getSkewX()), |
| 157 | SkScalarSqrt(m.getScaleY() * m.getScaleY() + m.getSkewY() * m.getSkewY())); |
| 158 | } |
fmalita | b5f7826 | 2014-08-06 13:07:15 -0700 | [diff] [blame] | 159 | SkSize scaledSize = SkSize::Make(scale.x() * fTile.width(), scale.y() * fTile.height()); |
commit-bot@chromium.org | c5d9bb0 | 2014-04-08 15:19:34 +0000 | [diff] [blame] | 160 | |
fmalita | bb204f4 | 2014-08-07 08:39:24 -0700 | [diff] [blame] | 161 | // Clamp the tile size to about 16M pixels |
| 162 | static const SkScalar kMaxTileArea = 4096 * 4096; |
| 163 | SkScalar tileArea = SkScalarMul(scaledSize.width(), scaledSize.height()); |
| 164 | if (tileArea > kMaxTileArea) { |
| 165 | SkScalar clampScale = SkScalarSqrt(SkScalarDiv(kMaxTileArea, tileArea)); |
| 166 | scaledSize.set(SkScalarMul(scaledSize.width(), clampScale), |
| 167 | SkScalarMul(scaledSize.height(), clampScale)); |
| 168 | } |
| 169 | |
commit-bot@chromium.org | c5d9bb0 | 2014-04-08 15:19:34 +0000 | [diff] [blame] | 170 | SkISize tileSize = scaledSize.toRound(); |
| 171 | if (tileSize.isEmpty()) { |
commit-bot@chromium.org | 87fcd95 | 2014-04-23 19:10:51 +0000 | [diff] [blame] | 172 | return NULL; |
commit-bot@chromium.org | c5d9bb0 | 2014-04-08 15:19:34 +0000 | [diff] [blame] | 173 | } |
| 174 | |
fmalita | bb204f4 | 2014-08-07 08:39:24 -0700 | [diff] [blame] | 175 | // The actual scale, compensating for rounding & clamping. |
fmalita | b5f7826 | 2014-08-06 13:07:15 -0700 | [diff] [blame] | 176 | SkSize tileScale = SkSize::Make(SkIntToScalar(tileSize.width()) / fTile.width(), |
| 177 | SkIntToScalar(tileSize.height()) / fTile.height()); |
commit-bot@chromium.org | c5d9bb0 | 2014-04-08 15:19:34 +0000 | [diff] [blame] | 178 | |
fmalita | 23df2d6 | 2014-10-22 07:39:08 -0700 | [diff] [blame] | 179 | SkAutoTUnref<SkShader> tileShader; |
| 180 | BitmapShaderKey key(fPicture->uniqueID(), |
| 181 | fTile, |
| 182 | fTmx, |
| 183 | fTmy, |
| 184 | tileScale, |
| 185 | this->getLocalMatrix()); |
commit-bot@chromium.org | 87fcd95 | 2014-04-23 19:10:51 +0000 | [diff] [blame] | 186 | |
fmalita | 171e5b7 | 2014-10-22 11:20:40 -0700 | [diff] [blame^] | 187 | if (!SkResourceCache::Find(key, BitmapShaderRec::Visitor, &tileShader)) { |
commit-bot@chromium.org | c5d9bb0 | 2014-04-08 15:19:34 +0000 | [diff] [blame] | 188 | SkBitmap bm; |
fmalita | 23df2d6 | 2014-10-22 07:39:08 -0700 | [diff] [blame] | 189 | bm.setInfo(SkImageInfo::MakeN32Premul(tileSize)); |
| 190 | if (!cache_try_alloc_pixels(&bm)) { |
commit-bot@chromium.org | 87fcd95 | 2014-04-23 19:10:51 +0000 | [diff] [blame] | 191 | return NULL; |
commit-bot@chromium.org | c5d9bb0 | 2014-04-08 15:19:34 +0000 | [diff] [blame] | 192 | } |
| 193 | bm.eraseColor(SK_ColorTRANSPARENT); |
| 194 | |
| 195 | SkCanvas canvas(bm); |
| 196 | canvas.scale(tileScale.width(), tileScale.height()); |
fmalita | b5f7826 | 2014-08-06 13:07:15 -0700 | [diff] [blame] | 197 | canvas.translate(fTile.x(), fTile.y()); |
robertphillips | 9b14f26 | 2014-06-04 05:40:44 -0700 | [diff] [blame] | 198 | canvas.drawPicture(fPicture); |
commit-bot@chromium.org | c5d9bb0 | 2014-04-08 15:19:34 +0000 | [diff] [blame] | 199 | |
commit-bot@chromium.org | 87fcd95 | 2014-04-23 19:10:51 +0000 | [diff] [blame] | 200 | SkMatrix shaderMatrix = this->getLocalMatrix(); |
| 201 | shaderMatrix.preScale(1 / tileScale.width(), 1 / tileScale.height()); |
fmalita | 23df2d6 | 2014-10-22 07:39:08 -0700 | [diff] [blame] | 202 | tileShader.reset(CreateBitmapShader(bm, fTmx, fTmy, &shaderMatrix)); |
| 203 | |
fmalita | 171e5b7 | 2014-10-22 11:20:40 -0700 | [diff] [blame^] | 204 | SkResourceCache::Add(SkNEW_ARGS(BitmapShaderRec, (key, tileShader.get(), bm.getSize()))); |
commit-bot@chromium.org | c5d9bb0 | 2014-04-08 15:19:34 +0000 | [diff] [blame] | 205 | } |
| 206 | |
fmalita | 23df2d6 | 2014-10-22 07:39:08 -0700 | [diff] [blame] | 207 | return tileShader.detach(); |
commit-bot@chromium.org | c5d9bb0 | 2014-04-08 15:19:34 +0000 | [diff] [blame] | 208 | } |
| 209 | |
commit-bot@chromium.org | 87fcd95 | 2014-04-23 19:10:51 +0000 | [diff] [blame] | 210 | size_t SkPictureShader::contextSize() const { |
| 211 | return sizeof(PictureShaderContext); |
commit-bot@chromium.org | c5d9bb0 | 2014-04-08 15:19:34 +0000 | [diff] [blame] | 212 | } |
| 213 | |
commit-bot@chromium.org | ce56d96 | 2014-05-05 18:39:18 +0000 | [diff] [blame] | 214 | SkShader::Context* SkPictureShader::onCreateContext(const ContextRec& rec, void* storage) const { |
commit-bot@chromium.org | 80116dc | 2014-05-06 17:16:03 +0000 | [diff] [blame] | 215 | SkAutoTUnref<SkShader> bitmapShader(this->refBitmapShader(*rec.fMatrix, rec.fLocalMatrix)); |
commit-bot@chromium.org | ce56d96 | 2014-05-05 18:39:18 +0000 | [diff] [blame] | 216 | if (NULL == bitmapShader.get()) { |
| 217 | return NULL; |
| 218 | } |
commit-bot@chromium.org | f03f9ff | 2014-05-06 13:43:17 +0000 | [diff] [blame] | 219 | return PictureShaderContext::Create(storage, *this, rec, bitmapShader); |
commit-bot@chromium.org | ce56d96 | 2014-05-05 18:39:18 +0000 | [diff] [blame] | 220 | } |
| 221 | |
| 222 | ///////////////////////////////////////////////////////////////////////////////////////// |
| 223 | |
| 224 | SkShader::Context* SkPictureShader::PictureShaderContext::Create(void* storage, |
| 225 | const SkPictureShader& shader, const ContextRec& rec, SkShader* bitmapShader) { |
| 226 | PictureShaderContext* ctx = SkNEW_PLACEMENT_ARGS(storage, PictureShaderContext, |
| 227 | (shader, rec, bitmapShader)); |
| 228 | if (NULL == ctx->fBitmapShaderContext) { |
| 229 | ctx->~PictureShaderContext(); |
| 230 | ctx = NULL; |
| 231 | } |
| 232 | return ctx; |
| 233 | } |
| 234 | |
commit-bot@chromium.org | 87fcd95 | 2014-04-23 19:10:51 +0000 | [diff] [blame] | 235 | SkPictureShader::PictureShaderContext::PictureShaderContext( |
commit-bot@chromium.org | e901b6d | 2014-05-01 19:31:31 +0000 | [diff] [blame] | 236 | const SkPictureShader& shader, const ContextRec& rec, SkShader* bitmapShader) |
| 237 | : INHERITED(shader, rec) |
commit-bot@chromium.org | ce56d96 | 2014-05-05 18:39:18 +0000 | [diff] [blame] | 238 | , fBitmapShader(SkRef(bitmapShader)) |
commit-bot@chromium.org | 87fcd95 | 2014-04-23 19:10:51 +0000 | [diff] [blame] | 239 | { |
commit-bot@chromium.org | ce56d96 | 2014-05-05 18:39:18 +0000 | [diff] [blame] | 240 | fBitmapShaderContextStorage = sk_malloc_throw(bitmapShader->contextSize()); |
| 241 | fBitmapShaderContext = bitmapShader->createContext(rec, fBitmapShaderContextStorage); |
| 242 | //if fBitmapShaderContext is null, we are invalid |
commit-bot@chromium.org | c5d9bb0 | 2014-04-08 15:19:34 +0000 | [diff] [blame] | 243 | } |
| 244 | |
commit-bot@chromium.org | 87fcd95 | 2014-04-23 19:10:51 +0000 | [diff] [blame] | 245 | SkPictureShader::PictureShaderContext::~PictureShaderContext() { |
commit-bot@chromium.org | ce56d96 | 2014-05-05 18:39:18 +0000 | [diff] [blame] | 246 | if (fBitmapShaderContext) { |
| 247 | fBitmapShaderContext->~Context(); |
| 248 | } |
commit-bot@chromium.org | 87fcd95 | 2014-04-23 19:10:51 +0000 | [diff] [blame] | 249 | sk_free(fBitmapShaderContextStorage); |
commit-bot@chromium.org | c5d9bb0 | 2014-04-08 15:19:34 +0000 | [diff] [blame] | 250 | } |
| 251 | |
commit-bot@chromium.org | 87fcd95 | 2014-04-23 19:10:51 +0000 | [diff] [blame] | 252 | uint32_t SkPictureShader::PictureShaderContext::getFlags() const { |
commit-bot@chromium.org | ce56d96 | 2014-05-05 18:39:18 +0000 | [diff] [blame] | 253 | SkASSERT(fBitmapShaderContext); |
commit-bot@chromium.org | 87fcd95 | 2014-04-23 19:10:51 +0000 | [diff] [blame] | 254 | return fBitmapShaderContext->getFlags(); |
commit-bot@chromium.org | c5d9bb0 | 2014-04-08 15:19:34 +0000 | [diff] [blame] | 255 | } |
| 256 | |
commit-bot@chromium.org | 87fcd95 | 2014-04-23 19:10:51 +0000 | [diff] [blame] | 257 | SkShader::Context::ShadeProc SkPictureShader::PictureShaderContext::asAShadeProc(void** ctx) { |
commit-bot@chromium.org | ce56d96 | 2014-05-05 18:39:18 +0000 | [diff] [blame] | 258 | SkASSERT(fBitmapShaderContext); |
commit-bot@chromium.org | 87fcd95 | 2014-04-23 19:10:51 +0000 | [diff] [blame] | 259 | return fBitmapShaderContext->asAShadeProc(ctx); |
| 260 | } |
| 261 | |
| 262 | void SkPictureShader::PictureShaderContext::shadeSpan(int x, int y, SkPMColor dstC[], int count) { |
| 263 | SkASSERT(fBitmapShaderContext); |
| 264 | fBitmapShaderContext->shadeSpan(x, y, dstC, count); |
| 265 | } |
| 266 | |
| 267 | void SkPictureShader::PictureShaderContext::shadeSpan16(int x, int y, uint16_t dstC[], int count) { |
| 268 | SkASSERT(fBitmapShaderContext); |
| 269 | fBitmapShaderContext->shadeSpan16(x, y, dstC, count); |
commit-bot@chromium.org | c5d9bb0 | 2014-04-08 15:19:34 +0000 | [diff] [blame] | 270 | } |
| 271 | |
| 272 | #ifndef SK_IGNORE_TO_STRING |
| 273 | void SkPictureShader::toString(SkString* str) const { |
| 274 | static const char* gTileModeName[SkShader::kTileModeCount] = { |
| 275 | "clamp", "repeat", "mirror" |
| 276 | }; |
| 277 | |
robertphillips | a8d7f0b | 2014-08-29 08:03:56 -0700 | [diff] [blame] | 278 | str->appendf("PictureShader: [%f:%f:%f:%f] ", |
| 279 | fPicture ? fPicture->cullRect().fLeft : 0, |
| 280 | fPicture ? fPicture->cullRect().fTop : 0, |
| 281 | fPicture ? fPicture->cullRect().fRight : 0, |
| 282 | fPicture ? fPicture->cullRect().fBottom : 0); |
commit-bot@chromium.org | c5d9bb0 | 2014-04-08 15:19:34 +0000 | [diff] [blame] | 283 | |
| 284 | str->appendf("(%s, %s)", gTileModeName[fTmx], gTileModeName[fTmy]); |
| 285 | |
| 286 | this->INHERITED::toString(str); |
| 287 | } |
| 288 | #endif |
| 289 | |
| 290 | #if SK_SUPPORT_GPU |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 291 | bool SkPictureShader::asFragmentProcessor(GrContext* context, const SkPaint& paint, |
| 292 | const SkMatrix* localMatrix, GrColor* paintColor, |
| 293 | GrFragmentProcessor** fp) const { |
commit-bot@chromium.org | 96fb748 | 2014-05-09 20:28:11 +0000 | [diff] [blame] | 294 | SkAutoTUnref<SkShader> bitmapShader(this->refBitmapShader(context->getMatrix(), localMatrix)); |
commit-bot@chromium.org | 87fcd95 | 2014-04-23 19:10:51 +0000 | [diff] [blame] | 295 | if (!bitmapShader) { |
dandov | 9de5b51 | 2014-06-10 14:38:28 -0700 | [diff] [blame] | 296 | return false; |
commit-bot@chromium.org | c5d9bb0 | 2014-04-08 15:19:34 +0000 | [diff] [blame] | 297 | } |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 298 | return bitmapShader->asFragmentProcessor(context, paint, NULL, paintColor, fp); |
dandov | 9de5b51 | 2014-06-10 14:38:28 -0700 | [diff] [blame] | 299 | } |
| 300 | #else |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 301 | bool SkPictureShader::asFragmentProcessor(GrContext*, const SkPaint&, const SkMatrix*, GrColor*, |
| 302 | GrFragmentProcessor**) const { |
dandov | 9de5b51 | 2014-06-10 14:38:28 -0700 | [diff] [blame] | 303 | SkDEBUGFAIL("Should not call in GPU-less build"); |
| 304 | return false; |
commit-bot@chromium.org | c5d9bb0 | 2014-04-08 15:19:34 +0000 | [diff] [blame] | 305 | } |
| 306 | #endif |