OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2010 Google Inc. | 2 * Copyright 2010 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 | 8 |
9 #include "SkGr.h" | 9 #include "SkGr.h" |
10 | 10 |
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
210 if (kUnknown_GrPixelConfig == desc.fConfig) { | 210 if (kUnknown_GrPixelConfig == desc.fConfig) { |
211 return nullptr; | 211 return nullptr; |
212 } | 212 } |
213 | 213 |
214 return ctx->textureProvider()->createTexture(desc, true, startOfTexData, 0); | 214 return ctx->textureProvider()->createTexture(desc, true, startOfTexData, 0); |
215 } | 215 } |
216 | 216 |
217 GrTexture* GrUploadBitmapToTexture(GrContext* ctx, const SkBitmap& bmp) { | 217 GrTexture* GrUploadBitmapToTexture(GrContext* ctx, const SkBitmap& bmp) { |
218 SkASSERT(!bmp.getTexture()); | 218 SkASSERT(!bmp.getTexture()); |
219 | 219 |
220 if (bmp.width() < ctx->caps()->minTextureSize() || | |
221 bmp.height() < ctx->caps()->minTextureSize()) { | |
222 return nullptr; | |
223 } | |
224 | |
225 SkBitmap tmpBitmap; | 220 SkBitmap tmpBitmap; |
226 const SkBitmap* bitmap = &bmp; | 221 const SkBitmap* bitmap = &bmp; |
227 | 222 |
228 GrSurfaceDesc desc = GrImageInfoToSurfaceDesc(bitmap->info()); | 223 GrSurfaceDesc desc = GrImageInfoToSurfaceDesc(bitmap->info()); |
229 const GrCaps* caps = ctx->caps(); | 224 const GrCaps* caps = ctx->caps(); |
230 | 225 |
231 if (kIndex_8_SkColorType == bitmap->colorType()) { | 226 if (kIndex_8_SkColorType == bitmap->colorType()) { |
232 if (caps->isConfigTexturable(kIndex_8_GrPixelConfig)) { | 227 if (caps->isConfigTexturable(kIndex_8_GrPixelConfig)) { |
233 size_t imageSize = GrCompressedFormatDataSize(kIndex_8_GrPixelConfig
, | 228 size_t imageSize = GrCompressedFormatDataSize(kIndex_8_GrPixelConfig
, |
234 bitmap->width(), bitma
p->height()); | 229 bitmap->width(), bitma
p->height()); |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
284 { | 279 { |
285 if (!bitmap.isVolatile()) { | 280 if (!bitmap.isVolatile()) { |
286 SkIPoint origin = bitmap.pixelRefOrigin(); | 281 SkIPoint origin = bitmap.pixelRefOrigin(); |
287 SkIRect subset = SkIRect::MakeXYWH(origin.fX, origin.fY, bitmap.widt
h(), | 282 SkIRect subset = SkIRect::MakeXYWH(origin.fX, origin.fY, bitmap.widt
h(), |
288 bitmap.height()); | 283 bitmap.height()); |
289 GrMakeKeyFromImageID(&fOriginalKey, bitmap.pixelRef()->getGeneration
ID(), subset); | 284 GrMakeKeyFromImageID(&fOriginalKey, bitmap.pixelRef()->getGeneration
ID(), subset); |
290 } | 285 } |
291 } | 286 } |
292 | 287 |
293 protected: | 288 protected: |
294 GrTexture* peekOriginalTexture() override { return fBitmap.getTexture(); } | |
295 | |
296 GrTexture* refOriginalTexture(GrContext* ctx) override { | 289 GrTexture* refOriginalTexture(GrContext* ctx) override { |
297 GrTexture* tex = fBitmap.getTexture(); | 290 GrTexture* tex = fBitmap.getTexture(); |
298 if (tex) { | 291 if (tex) { |
299 return SkRef(tex); | 292 return SkRef(tex); |
300 } | 293 } |
301 | 294 |
302 if (fOriginalKey.isValid()) { | 295 if (fOriginalKey.isValid()) { |
303 tex = ctx->textureProvider()->findAndRefTextureByUniqueKey(fOriginal
Key); | 296 tex = ctx->textureProvider()->findAndRefTextureByUniqueKey(fOriginal
Key); |
304 if (tex) { | 297 if (tex) { |
305 return tex; | 298 return tex; |
(...skipping 11 matching lines...) Expand all Loading... |
317 void makeCopyKey(const CopyParams& copyParams, GrUniqueKey* copyKey) overrid
e { | 310 void makeCopyKey(const CopyParams& copyParams, GrUniqueKey* copyKey) overrid
e { |
318 if (fOriginalKey.isValid()) { | 311 if (fOriginalKey.isValid()) { |
319 MakeCopyKeyFromOrigKey(fOriginalKey, copyParams, copyKey); | 312 MakeCopyKeyFromOrigKey(fOriginalKey, copyParams, copyKey); |
320 } | 313 } |
321 } | 314 } |
322 | 315 |
323 void didCacheCopy(const GrUniqueKey& copyKey) override { | 316 void didCacheCopy(const GrUniqueKey& copyKey) override { |
324 InstallInvalidator(copyKey, fBitmap.pixelRef()); | 317 InstallInvalidator(copyKey, fBitmap.pixelRef()); |
325 } | 318 } |
326 | 319 |
327 bool getROBitmap(SkBitmap* bitmap) override { | |
328 SkASSERT(!fBitmap.getTexture()); | |
329 *bitmap = fBitmap; | |
330 return true; | |
331 } | |
332 | |
333 private: | 320 private: |
334 static void InstallInvalidator(const GrUniqueKey& key, SkPixelRef* pixelRef)
{ | 321 static void InstallInvalidator(const GrUniqueKey& key, SkPixelRef* pixelRef)
{ |
335 class Invalidator : public SkPixelRef::GenIDChangeListener { | 322 class Invalidator : public SkPixelRef::GenIDChangeListener { |
336 public: | 323 public: |
337 explicit Invalidator(const GrUniqueKey& key) : fMsg(key) {} | 324 explicit Invalidator(const GrUniqueKey& key) : fMsg(key) {} |
338 private: | 325 private: |
339 GrUniqueKeyInvalidatedMessage fMsg; | 326 GrUniqueKeyInvalidatedMessage fMsg; |
340 | 327 |
341 void onChange() override { | 328 void onChange() override { |
342 SkMessageBus<GrUniqueKeyInvalidatedMessage>::Post(fMsg); | 329 SkMessageBus<GrUniqueKeyInvalidatedMessage>::Post(fMsg); |
(...skipping 325 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
668 SkErrorInternals::SetError( kInvalidPaint_SkError, | 655 SkErrorInternals::SetError( kInvalidPaint_SkError, |
669 "Sorry, I don't understand the filtering
" | 656 "Sorry, I don't understand the filtering
" |
670 "mode you asked for. Falling back to " | 657 "mode you asked for. Falling back to " |
671 "MIPMaps."); | 658 "MIPMaps."); |
672 textureFilterMode = GrTextureParams::kMipMap_FilterMode; | 659 textureFilterMode = GrTextureParams::kMipMap_FilterMode; |
673 break; | 660 break; |
674 | 661 |
675 } | 662 } |
676 return textureFilterMode; | 663 return textureFilterMode; |
677 } | 664 } |
OLD | NEW |