OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2016 Google Inc. | 2 * Copyright 2016 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 #include "SkSpecialImage.h" | 7 #include "SkSpecialImage.h" |
8 | 8 |
9 #if SK_SUPPORT_GPU | 9 #if SK_SUPPORT_GPU |
10 #include "GrTexture.h" | 10 #include "GrTexture.h" |
(...skipping 17 matching lines...) Expand all Loading... |
28 | 28 |
29 virtual bool onPeekPixels(SkPixmap*) const { return false; } | 29 virtual bool onPeekPixels(SkPixmap*) const { return false; } |
30 | 30 |
31 virtual GrTexture* onPeekTexture() const { return nullptr; } | 31 virtual GrTexture* onPeekTexture() const { return nullptr; } |
32 | 32 |
33 virtual bool testingOnlyOnGetROPixels(SkBitmap*) const = 0; | 33 virtual bool testingOnlyOnGetROPixels(SkBitmap*) const = 0; |
34 | 34 |
35 // Delete this entry point ASAP (see skbug.com/4965) | 35 // Delete this entry point ASAP (see skbug.com/4965) |
36 virtual bool getBitmapDeprecated(SkBitmap* result) const = 0; | 36 virtual bool getBitmapDeprecated(SkBitmap* result) const = 0; |
37 | 37 |
| 38 virtual sk_sp<SkSpecialImage> onMakeSubset(const SkIRect& subset) const = 0; |
| 39 |
38 virtual sk_sp<SkSpecialSurface> onMakeSurface(const SkImageInfo& info) const
= 0; | 40 virtual sk_sp<SkSpecialSurface> onMakeSurface(const SkImageInfo& info) const
= 0; |
39 | 41 |
40 virtual sk_sp<SkSpecialImage> onMakeSubset(const SkIRect& subset) const = 0; | 42 virtual sk_sp<SkImage> onMakeTightSubset(const SkIRect& subset) const = 0; |
| 43 |
| 44 virtual SkSurface* onMakeTightSurface(const SkImageInfo& info) const = 0; |
41 | 45 |
42 private: | 46 private: |
43 typedef SkSpecialImage INHERITED; | 47 typedef SkSpecialImage INHERITED; |
44 }; | 48 }; |
45 | 49 |
46 /////////////////////////////////////////////////////////////////////////////// | 50 /////////////////////////////////////////////////////////////////////////////// |
47 static inline const SkSpecialImage_Base* as_SIB(const SkSpecialImage* image) { | 51 static inline const SkSpecialImage_Base* as_SIB(const SkSpecialImage* image) { |
48 return static_cast<const SkSpecialImage_Base*>(image); | 52 return static_cast<const SkSpecialImage_Base*>(image); |
49 } | 53 } |
50 | 54 |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
93 } | 97 } |
94 | 98 |
95 bool SkSpecialImage::testingOnlyGetROPixels(SkBitmap* result) const { | 99 bool SkSpecialImage::testingOnlyGetROPixels(SkBitmap* result) const { |
96 return as_SIB(this)->testingOnlyOnGetROPixels(result); | 100 return as_SIB(this)->testingOnlyOnGetROPixels(result); |
97 } | 101 } |
98 | 102 |
99 sk_sp<SkSpecialSurface> SkSpecialImage::makeSurface(const SkImageInfo& info) con
st { | 103 sk_sp<SkSpecialSurface> SkSpecialImage::makeSurface(const SkImageInfo& info) con
st { |
100 return as_SIB(this)->onMakeSurface(info); | 104 return as_SIB(this)->onMakeSurface(info); |
101 } | 105 } |
102 | 106 |
| 107 sk_sp<SkSurface> SkSpecialImage::makeTightSurface(const SkImageInfo& info) const
{ |
| 108 sk_sp<SkSurface> tmp(SkRef(as_SIB(this)->onMakeTightSurface(info))); |
| 109 return tmp; |
| 110 } |
| 111 |
103 sk_sp<SkSpecialImage> SkSpecialImage::makeSubset(const SkIRect& subset) const { | 112 sk_sp<SkSpecialImage> SkSpecialImage::makeSubset(const SkIRect& subset) const { |
104 return as_SIB(this)->onMakeSubset(subset); | 113 return as_SIB(this)->onMakeSubset(subset); |
105 } | 114 } |
106 | 115 |
| 116 sk_sp<SkImage> SkSpecialImage::makeTightSubset(const SkIRect& subset) const { |
| 117 return as_SIB(this)->onMakeTightSubset(subset); |
| 118 } |
| 119 |
107 #if SK_SUPPORT_GPU | 120 #if SK_SUPPORT_GPU |
108 #include "SkGr.h" | 121 #include "SkGr.h" |
109 #include "SkGrPixelRef.h" | 122 #include "SkGrPixelRef.h" |
110 #endif | 123 #endif |
111 | 124 |
112 sk_sp<SkSpecialImage> SkSpecialImage::internal_fromBM(SkImageFilter::Proxy* prox
y, | 125 sk_sp<SkSpecialImage> SkSpecialImage::internal_fromBM(SkImageFilter::Proxy* prox
y, |
113 const SkBitmap& src) { | 126 const SkBitmap& src) { |
114 // Need to test offset case! (see skbug.com/4967) | 127 // Need to test offset case! (see skbug.com/4967) |
115 if (src.getTexture()) { | 128 if (src.getTexture()) { |
116 return SkSpecialImage::MakeFromGpu(proxy, | 129 return SkSpecialImage::MakeFromGpu(proxy, |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
220 sk_sp<SkImage> subsetImg(fImage->makeSubset(subset)); | 233 sk_sp<SkImage> subsetImg(fImage->makeSubset(subset)); |
221 if (!subsetImg) { | 234 if (!subsetImg) { |
222 return nullptr; | 235 return nullptr; |
223 } | 236 } |
224 | 237 |
225 return SkSpecialImage::MakeFromImage(this->internal_getProxy(), | 238 return SkSpecialImage::MakeFromImage(this->internal_getProxy(), |
226 SkIRect::MakeWH(subset.width(), sub
set.height()), | 239 SkIRect::MakeWH(subset.width(), sub
set.height()), |
227 subsetImg); | 240 subsetImg); |
228 } | 241 } |
229 | 242 |
| 243 sk_sp<SkImage> onMakeTightSubset(const SkIRect& subset) const override { |
| 244 return fImage->makeSubset(subset); |
| 245 } |
| 246 |
| 247 SkSurface* onMakeTightSurface(const SkImageInfo& info) const override { |
| 248 #if SK_SUPPORT_GPU |
| 249 GrTexture* texture = as_IB(fImage.get())->peekTexture(); |
| 250 if (texture) { |
| 251 return SkSurface::NewRenderTarget(texture->getContext(), SkBudgeted:
:kYes, info, 0); |
| 252 } |
| 253 #endif |
| 254 return SkSurface::NewRaster(info, nullptr); |
| 255 } |
| 256 |
230 private: | 257 private: |
231 sk_sp<SkImage> fImage; | 258 sk_sp<SkImage> fImage; |
232 | 259 |
233 typedef SkSpecialImage_Base INHERITED; | 260 typedef SkSpecialImage_Base INHERITED; |
234 }; | 261 }; |
235 | 262 |
236 #ifdef SK_DEBUG | 263 #ifdef SK_DEBUG |
237 static bool rect_fits(const SkIRect& rect, int width, int height) { | 264 static bool rect_fits(const SkIRect& rect, int width, int height) { |
238 if (0 == width && 0 == height) { | 265 if (0 == width && 0 == height) { |
239 SkASSERT(0 == rect.fLeft && 0 == rect.fRight && 0 == rect.fTop && 0 == r
ect.fBottom); | 266 SkASSERT(0 == rect.fLeft && 0 == rect.fRight && 0 == rect.fTop && 0 == r
ect.fBottom); |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
325 | 352 |
326 if (!fBitmap.extractSubset(&subsetBM, subset)) { | 353 if (!fBitmap.extractSubset(&subsetBM, subset)) { |
327 return nullptr; | 354 return nullptr; |
328 } | 355 } |
329 | 356 |
330 return SkSpecialImage::MakeFromRaster(this->internal_getProxy(), | 357 return SkSpecialImage::MakeFromRaster(this->internal_getProxy(), |
331 SkIRect::MakeWH(subset.width(), su
bset.height()), | 358 SkIRect::MakeWH(subset.width(), su
bset.height()), |
332 subsetBM); | 359 subsetBM); |
333 } | 360 } |
334 | 361 |
| 362 sk_sp<SkImage> onMakeTightSubset(const SkIRect& subset) const override { |
| 363 SkBitmap subsetBM; |
| 364 |
| 365 if (!fBitmap.extractSubset(&subsetBM, subset)) { |
| 366 return nullptr; |
| 367 } |
| 368 |
| 369 return SkImage::MakeFromBitmap(subsetBM); |
| 370 } |
| 371 |
| 372 SkSurface* onMakeTightSurface(const SkImageInfo& info) const override { |
| 373 return SkSurface::NewRaster(info); |
| 374 } |
| 375 |
335 private: | 376 private: |
336 SkBitmap fBitmap; | 377 SkBitmap fBitmap; |
337 | 378 |
338 typedef SkSpecialImage_Base INHERITED; | 379 typedef SkSpecialImage_Base INHERITED; |
339 }; | 380 }; |
340 | 381 |
341 sk_sp<SkSpecialImage> SkSpecialImage::MakeFromRaster(SkImageFilter::Proxy* proxy
, | 382 sk_sp<SkSpecialImage> SkSpecialImage::MakeFromRaster(SkImageFilter::Proxy* proxy
, |
342 const SkIRect& subset, | 383 const SkIRect& subset, |
343 const SkBitmap& bm) { | 384 const SkBitmap& bm) { |
344 SkASSERT(nullptr == bm.getTexture()); | 385 SkASSERT(nullptr == bm.getTexture()); |
(...skipping 11 matching lines...) Expand all Loading... |
356 return nullptr; | 397 return nullptr; |
357 } | 398 } |
358 | 399 |
359 return sk_make_sp<SkSpecialImage_Raster>(proxy, subset, src, releaseProc, co
ntext); | 400 return sk_make_sp<SkSpecialImage_Raster>(proxy, subset, src, releaseProc, co
ntext); |
360 } | 401 } |
361 | 402 |
362 | 403 |
363 #if SK_SUPPORT_GPU | 404 #if SK_SUPPORT_GPU |
364 /////////////////////////////////////////////////////////////////////////////// | 405 /////////////////////////////////////////////////////////////////////////////// |
365 #include "GrTexture.h" | 406 #include "GrTexture.h" |
| 407 #include "SkImage_Gpu.h" |
366 | 408 |
367 class SkSpecialImage_Gpu : public SkSpecialImage_Base { | 409 class SkSpecialImage_Gpu : public SkSpecialImage_Base { |
368 public: | 410 public: |
369 SkSpecialImage_Gpu(SkImageFilter::Proxy* proxy, const SkIRect& subset, | 411 SkSpecialImage_Gpu(SkImageFilter::Proxy* proxy, const SkIRect& subset, |
370 uint32_t uniqueID, GrTexture* tex, SkAlphaType at) | 412 uint32_t uniqueID, GrTexture* tex, SkAlphaType at) |
371 : INHERITED(proxy, subset, uniqueID) | 413 : INHERITED(proxy, subset, uniqueID) |
372 , fTexture(SkRef(tex)) | 414 , fTexture(SkRef(tex)) |
373 , fAlphaType(at) { | 415 , fAlphaType(at) { |
374 } | 416 } |
375 | 417 |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
438 } | 480 } |
439 | 481 |
440 sk_sp<SkSpecialImage> onMakeSubset(const SkIRect& subset) const override { | 482 sk_sp<SkSpecialImage> onMakeSubset(const SkIRect& subset) const override { |
441 return SkSpecialImage::MakeFromGpu(this->internal_getProxy(), | 483 return SkSpecialImage::MakeFromGpu(this->internal_getProxy(), |
442 subset, | 484 subset, |
443 this->uniqueID(), | 485 this->uniqueID(), |
444 fTexture, | 486 fTexture, |
445 fAlphaType); | 487 fAlphaType); |
446 } | 488 } |
447 | 489 |
| 490 sk_sp<SkImage> onMakeTightSubset(const SkIRect& subset) const override { |
| 491 if (0 == subset.fLeft && 0 == subset.fTop && |
| 492 fTexture->width() == subset.width() && |
| 493 fTexture->height() == subset.height()) { |
| 494 // The existing GrTexture is already tight so reuse it in the SkImag
e |
| 495 return sk_make_sp<SkImage_Gpu>(fTexture->width(), fTexture->height()
, |
| 496 kNeedNewImageUniqueID, |
| 497 fAlphaType, fTexture, SkBudgeted::kYe
s); |
| 498 } |
| 499 |
| 500 GrContext* ctx = fTexture->getContext(); |
| 501 GrSurfaceDesc desc = fTexture->desc(); |
| 502 desc.fWidth = subset.width(); |
| 503 desc.fHeight = subset.height(); |
| 504 |
| 505 GrTexture* subTx = ctx->textureProvider()->createTexture(desc, SkBudgete
d::kYes); |
| 506 if (!subTx) { |
| 507 return nullptr; |
| 508 } |
| 509 ctx->copySurface(subTx, fTexture, subset, SkIPoint::Make(0, 0)); |
| 510 return sk_make_sp<SkImage_Gpu>(desc.fWidth, desc.fHeight, kNeedNewImageU
niqueID, |
| 511 fAlphaType, subTx, SkBudgeted::kYes); |
| 512 } |
| 513 |
| 514 SkSurface* onMakeTightSurface(const SkImageInfo& info) const override { |
| 515 return SkSurface::NewRenderTarget(fTexture->getContext(), SkBudgeted::kY
es, info); |
| 516 } |
| 517 |
448 private: | 518 private: |
449 SkAutoTUnref<GrTexture> fTexture; | 519 SkAutoTUnref<GrTexture> fTexture; |
450 const SkAlphaType fAlphaType; | 520 const SkAlphaType fAlphaType; |
451 | 521 |
452 typedef SkSpecialImage_Base INHERITED; | 522 typedef SkSpecialImage_Base INHERITED; |
453 }; | 523 }; |
454 | 524 |
455 sk_sp<SkSpecialImage> SkSpecialImage::MakeFromGpu(SkImageFilter::Proxy* proxy, | 525 sk_sp<SkSpecialImage> SkSpecialImage::MakeFromGpu(SkImageFilter::Proxy* proxy, |
456 const SkIRect& subset, | 526 const SkIRect& subset, |
457 uint32_t uniqueID, | 527 uint32_t uniqueID, |
458 GrTexture* tex, | 528 GrTexture* tex, |
459 SkAlphaType at) { | 529 SkAlphaType at) { |
460 SkASSERT(rect_fits(subset, tex->width(), tex->height())); | 530 SkASSERT(rect_fits(subset, tex->width(), tex->height())); |
461 return sk_make_sp<SkSpecialImage_Gpu>(proxy, subset, uniqueID, tex, at); | 531 return sk_make_sp<SkSpecialImage_Gpu>(proxy, subset, uniqueID, tex, at); |
462 } | 532 } |
463 | 533 |
464 #else | 534 #else |
465 | 535 |
466 sk_sp<SkSpecialImage> SkSpecialImage::MakeFromGpu(SkImageFilter::Proxy* proxy, | 536 sk_sp<SkSpecialImage> SkSpecialImage::MakeFromGpu(SkImageFilter::Proxy* proxy, |
467 const SkIRect& subset, | 537 const SkIRect& subset, |
468 uint32_t uniqueID, | 538 uint32_t uniqueID, |
469 GrTexture* tex, | 539 GrTexture* tex, |
470 SkAlphaType at) { | 540 SkAlphaType at) { |
471 return nullptr; | 541 return nullptr; |
472 } | 542 } |
473 | 543 |
474 #endif | 544 #endif |
OLD | NEW |