| 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 | 7 |
| 8 #include "SkSpecialImage.h" | 8 #include "SkSpecialImage.h" |
| 9 #include "SkBitmap.h" | 9 #include "SkBitmap.h" |
| 10 #include "SkImage.h" | 10 #include "SkImage.h" |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 45 virtual GrTexture* onPeekTexture() const { return nullptr; } | 45 virtual GrTexture* onPeekTexture() const { return nullptr; } |
| 46 | 46 |
| 47 virtual SkColorSpace* onGetColorSpace() const = 0; | 47 virtual SkColorSpace* onGetColorSpace() const = 0; |
| 48 | 48 |
| 49 #if SK_SUPPORT_GPU | 49 #if SK_SUPPORT_GPU |
| 50 virtual sk_sp<GrTexture> onAsTextureRef(GrContext* context) const = 0; | 50 virtual sk_sp<GrTexture> onAsTextureRef(GrContext* context) const = 0; |
| 51 #endif | 51 #endif |
| 52 | 52 |
| 53 virtual sk_sp<SkSpecialImage> onMakeSubset(const SkIRect& subset) const = 0; | 53 virtual sk_sp<SkSpecialImage> onMakeSubset(const SkIRect& subset) const = 0; |
| 54 | 54 |
| 55 virtual sk_sp<SkSpecialSurface> onMakeSurface(const SkImageInfo& info) const
= 0; | 55 virtual sk_sp<SkSpecialSurface> onMakeSurface(const SkImageFilter::OutputPro
perties& outProps, |
| 56 const SkISize& size, SkAlphaTy
pe at) const = 0; |
| 56 | 57 |
| 57 virtual sk_sp<SkImage> onMakeTightSubset(const SkIRect& subset) const = 0; | 58 virtual sk_sp<SkImage> onMakeTightSubset(const SkIRect& subset) const = 0; |
| 58 | 59 |
| 59 virtual sk_sp<SkSurface> onMakeTightSurface(const SkImageInfo& info) const =
0; | 60 virtual sk_sp<SkSurface> onMakeTightSurface(const SkImageFilter::OutputPrope
rties& outProps, |
| 61 const SkISize& size, SkAlphaType
at) const = 0; |
| 60 | 62 |
| 61 private: | 63 private: |
| 62 typedef SkSpecialImage INHERITED; | 64 typedef SkSpecialImage INHERITED; |
| 63 }; | 65 }; |
| 64 | 66 |
| 65 /////////////////////////////////////////////////////////////////////////////// | 67 /////////////////////////////////////////////////////////////////////////////// |
| 66 static inline const SkSpecialImage_Base* as_SIB(const SkSpecialImage* image) { | 68 static inline const SkSpecialImage_Base* as_SIB(const SkSpecialImage* image) { |
| 67 return static_cast<const SkSpecialImage_Base*>(image); | 69 return static_cast<const SkSpecialImage_Base*>(image); |
| 68 } | 70 } |
| 69 | 71 |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 144 SkColorSpace* SkSpecialImage::getColorSpace() const { | 146 SkColorSpace* SkSpecialImage::getColorSpace() const { |
| 145 return as_SIB(this)->onGetColorSpace(); | 147 return as_SIB(this)->onGetColorSpace(); |
| 146 } | 148 } |
| 147 | 149 |
| 148 #if SK_SUPPORT_GPU | 150 #if SK_SUPPORT_GPU |
| 149 sk_sp<GrTexture> SkSpecialImage::asTextureRef(GrContext* context) const { | 151 sk_sp<GrTexture> SkSpecialImage::asTextureRef(GrContext* context) const { |
| 150 return as_SIB(this)->onAsTextureRef(context); | 152 return as_SIB(this)->onAsTextureRef(context); |
| 151 } | 153 } |
| 152 #endif | 154 #endif |
| 153 | 155 |
| 154 sk_sp<SkSpecialSurface> SkSpecialImage::makeSurface(const SkImageInfo& info) con
st { | 156 sk_sp<SkSpecialSurface> SkSpecialImage::makeSurface(const SkImageFilter::OutputP
roperties& outProps, |
| 155 return as_SIB(this)->onMakeSurface(info); | 157 const SkISize& size, SkAlpha
Type at) const { |
| 158 return as_SIB(this)->onMakeSurface(outProps, size, at); |
| 156 } | 159 } |
| 157 | 160 |
| 158 sk_sp<SkSurface> SkSpecialImage::makeTightSurface(const SkImageInfo& info) const
{ | 161 sk_sp<SkSurface> SkSpecialImage::makeTightSurface(const SkImageFilter::OutputPro
perties& outProps, |
| 159 return as_SIB(this)->onMakeTightSurface(info); | 162 const SkISize& size, SkAlphaTy
pe at) const { |
| 163 return as_SIB(this)->onMakeTightSurface(outProps, size, at); |
| 160 } | 164 } |
| 161 | 165 |
| 162 sk_sp<SkSpecialImage> SkSpecialImage::makeSubset(const SkIRect& subset) const { | 166 sk_sp<SkSpecialImage> SkSpecialImage::makeSubset(const SkIRect& subset) const { |
| 163 return as_SIB(this)->onMakeSubset(subset); | 167 return as_SIB(this)->onMakeSubset(subset); |
| 164 } | 168 } |
| 165 | 169 |
| 166 sk_sp<SkImage> SkSpecialImage::makeTightSubset(const SkIRect& subset) const { | 170 sk_sp<SkImage> SkSpecialImage::makeTightSubset(const SkIRect& subset) const { |
| 167 return as_SIB(this)->onMakeTightSubset(subset); | 171 return as_SIB(this)->onMakeTightSubset(subset); |
| 168 } | 172 } |
| 169 | 173 |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 245 return sk_ref_sp(GrRefCachedBitmapTexture(context, | 249 return sk_ref_sp(GrRefCachedBitmapTexture(context, |
| 246 fBitmap, | 250 fBitmap, |
| 247 GrTextureParams::ClampNoFi
lter(), | 251 GrTextureParams::ClampNoFi
lter(), |
| 248 SkSourceGammaTreatment::kR
espect)); | 252 SkSourceGammaTreatment::kR
espect)); |
| 249 } | 253 } |
| 250 | 254 |
| 251 return nullptr; | 255 return nullptr; |
| 252 } | 256 } |
| 253 #endif | 257 #endif |
| 254 | 258 |
| 255 sk_sp<SkSpecialSurface> onMakeSurface(const SkImageInfo& info) const overrid
e { | 259 // TODO: The raster implementations of image filters all currently assume that t
he pixels are |
| 260 // legacy N32. Until they actually check the format and operate on sRGB or F16 d
ata appropriately, |
| 261 // we can't enable this. (They will continue to produce incorrect results, but l
ess-so). |
| 262 #define RASTER_IMAGE_FILTERS_SUPPORT_SRGB_AND_F16 0 |
| 263 |
| 264 sk_sp<SkSpecialSurface> onMakeSurface(const SkImageFilter::OutputProperties&
outProps, |
| 265 const SkISize& size, SkAlphaType at) c
onst override { |
| 266 #if RASTER_IMAGE_FILTERS_SUPPORT_SRGB_AND_F16 |
| 267 SkColorSpace* colorSpace = outProps.colorSpace(); |
| 268 #else |
| 269 SkColorSpace* colorSpace = nullptr; |
| 270 #endif |
| 271 SkColorType colorType = colorSpace && colorSpace->gammaIsLinear() |
| 272 ? kRGBA_F16_SkColorType : kN32_SkColorType; |
| 273 SkImageInfo info = SkImageInfo::Make(size.width(), size.height(), colorT
ype, at, |
| 274 sk_ref_sp(colorSpace)); |
| 256 return SkSpecialSurface::MakeRaster(info, nullptr); | 275 return SkSpecialSurface::MakeRaster(info, nullptr); |
| 257 } | 276 } |
| 258 | 277 |
| 259 sk_sp<SkSpecialImage> onMakeSubset(const SkIRect& subset) const override { | 278 sk_sp<SkSpecialImage> onMakeSubset(const SkIRect& subset) const override { |
| 260 SkBitmap subsetBM; | 279 SkBitmap subsetBM; |
| 261 | 280 |
| 262 if (!fBitmap.extractSubset(&subsetBM, subset)) { | 281 if (!fBitmap.extractSubset(&subsetBM, subset)) { |
| 263 return nullptr; | 282 return nullptr; |
| 264 } | 283 } |
| 265 | 284 |
| 266 return SkSpecialImage::MakeFromRaster(SkIRect::MakeWH(subset.width(), su
bset.height()), | 285 return SkSpecialImage::MakeFromRaster(SkIRect::MakeWH(subset.width(), su
bset.height()), |
| 267 subsetBM, | 286 subsetBM, |
| 268 &this->props()); | 287 &this->props()); |
| 269 } | 288 } |
| 270 | 289 |
| 271 sk_sp<SkImage> onMakeTightSubset(const SkIRect& subset) const override { | 290 sk_sp<SkImage> onMakeTightSubset(const SkIRect& subset) const override { |
| 272 SkBitmap subsetBM; | 291 SkBitmap subsetBM; |
| 273 | 292 |
| 274 if (!fBitmap.extractSubset(&subsetBM, subset)) { | 293 if (!fBitmap.extractSubset(&subsetBM, subset)) { |
| 275 return nullptr; | 294 return nullptr; |
| 276 } | 295 } |
| 277 | 296 |
| 278 return SkImage::MakeFromBitmap(subsetBM); | 297 return SkImage::MakeFromBitmap(subsetBM); |
| 279 } | 298 } |
| 280 | 299 |
| 281 sk_sp<SkSurface> onMakeTightSurface(const SkImageInfo& info) const override
{ | 300 sk_sp<SkSurface> onMakeTightSurface(const SkImageFilter::OutputProperties& o
utProps, |
| 301 const SkISize& size, SkAlphaType at) con
st override { |
| 302 #if RASTER_IMAGE_FILTERS_SUPPORT_SRGB_AND_F16 |
| 303 SkColorSpace* colorSpace = outProps.colorSpace(); |
| 304 #else |
| 305 SkColorSpace* colorSpace = nullptr; |
| 306 #endif |
| 307 SkColorType colorType = colorSpace && colorSpace->gammaIsLinear() |
| 308 ? kRGBA_F16_SkColorType : kN32_SkColorType; |
| 309 SkImageInfo info = SkImageInfo::Make(size.width(), size.height(), colorT
ype, at, |
| 310 sk_ref_sp(colorSpace)); |
| 282 return SkSurface::MakeRaster(info); | 311 return SkSurface::MakeRaster(info); |
| 283 } | 312 } |
| 284 | 313 |
| 285 private: | 314 private: |
| 286 SkBitmap fBitmap; | 315 SkBitmap fBitmap; |
| 287 | 316 |
| 288 typedef SkSpecialImage_Base INHERITED; | 317 typedef SkSpecialImage_Base INHERITED; |
| 289 }; | 318 }; |
| 290 | 319 |
| 291 sk_sp<SkSpecialImage> SkSpecialImage::MakeFromRaster(const SkIRect& subset, | 320 sk_sp<SkSpecialImage> SkSpecialImage::MakeFromRaster(const SkIRect& subset, |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 375 dst->pixelRef()->setImmutableWithID(this->uniqueID()); | 404 dst->pixelRef()->setImmutableWithID(this->uniqueID()); |
| 376 SkBitmapCache::Add(this->uniqueID(), *dst); | 405 SkBitmapCache::Add(this->uniqueID(), *dst); |
| 377 fAddedRasterVersionToCache.store(true); | 406 fAddedRasterVersionToCache.store(true); |
| 378 return true; | 407 return true; |
| 379 } | 408 } |
| 380 | 409 |
| 381 SkColorSpace* onGetColorSpace() const override { | 410 SkColorSpace* onGetColorSpace() const override { |
| 382 return fColorSpace.get(); | 411 return fColorSpace.get(); |
| 383 } | 412 } |
| 384 | 413 |
| 385 sk_sp<SkSpecialSurface> onMakeSurface(const SkImageInfo& info) const overrid
e { | 414 sk_sp<SkSpecialSurface> onMakeSurface(const SkImageFilter::OutputProperties&
outProps, |
| 415 const SkISize& size, SkAlphaType at) c
onst override { |
| 386 if (!fTexture->getContext()) { | 416 if (!fTexture->getContext()) { |
| 387 return nullptr; | 417 return nullptr; |
| 388 } | 418 } |
| 389 | 419 |
| 390 GrPixelConfig config = SkImageInfo2GrPixelConfig(info, *fTexture->getCon
text()->caps()); | 420 SkColorSpace* colorSpace = outProps.colorSpace(); |
| 391 | 421 return SkSpecialSurface::MakeRenderTarget( |
| 392 return SkSpecialSurface::MakeRenderTarget(fTexture->getContext(), | 422 fTexture->getContext(), size.width(), size.height(), |
| 393 info.width(), info.height(), | 423 GrRenderableConfigForColorSpace(colorSpace), sk_ref_sp(colorSpace)); |
| 394 config, sk_ref_sp(info.colorSp
ace())); | |
| 395 } | 424 } |
| 396 | 425 |
| 397 sk_sp<SkSpecialImage> onMakeSubset(const SkIRect& subset) const override { | 426 sk_sp<SkSpecialImage> onMakeSubset(const SkIRect& subset) const override { |
| 398 return SkSpecialImage::MakeFromGpu(subset, | 427 return SkSpecialImage::MakeFromGpu(subset, |
| 399 this->uniqueID(), | 428 this->uniqueID(), |
| 400 fTexture, | 429 fTexture, |
| 401 fColorSpace, | 430 fColorSpace, |
| 402 &this->props(), | 431 &this->props(), |
| 403 fAlphaType); | 432 fAlphaType); |
| 404 } | 433 } |
| (...skipping 16 matching lines...) Expand all Loading... |
| 421 | 450 |
| 422 sk_sp<GrTexture> subTx(ctx->textureProvider()->createTexture(desc, SkBud
geted::kYes)); | 451 sk_sp<GrTexture> subTx(ctx->textureProvider()->createTexture(desc, SkBud
geted::kYes)); |
| 423 if (!subTx) { | 452 if (!subTx) { |
| 424 return nullptr; | 453 return nullptr; |
| 425 } | 454 } |
| 426 ctx->copySurface(subTx.get(), fTexture.get(), subset, SkIPoint::Make(0,
0)); | 455 ctx->copySurface(subTx.get(), fTexture.get(), subset, SkIPoint::Make(0,
0)); |
| 427 return sk_make_sp<SkImage_Gpu>(desc.fWidth, desc.fHeight, kNeedNewImageU
niqueID, | 456 return sk_make_sp<SkImage_Gpu>(desc.fWidth, desc.fHeight, kNeedNewImageU
niqueID, |
| 428 fAlphaType, subTx.get(), fColorSpace, SkB
udgeted::kYes); | 457 fAlphaType, subTx.get(), fColorSpace, SkB
udgeted::kYes); |
| 429 } | 458 } |
| 430 | 459 |
| 431 sk_sp<SkSurface> onMakeTightSurface(const SkImageInfo& info) const override
{ | 460 sk_sp<SkSurface> onMakeTightSurface(const SkImageFilter::OutputProperties& o
utProps, |
| 461 const SkISize& size, SkAlphaType at) con
st override { |
| 462 SkColorSpace* colorSpace = outProps.colorSpace(); |
| 463 SkColorType colorType = colorSpace && colorSpace->gammaIsLinear() |
| 464 ? kRGBA_F16_SkColorType : kRGBA_8888_SkColorType; |
| 465 SkImageInfo info = SkImageInfo::Make(size.width(), size.height(), colorT
ype, at, |
| 466 sk_ref_sp(colorSpace)); |
| 432 return SkSurface::MakeRenderTarget(fTexture->getContext(), SkBudgeted::k
Yes, info); | 467 return SkSurface::MakeRenderTarget(fTexture->getContext(), SkBudgeted::k
Yes, info); |
| 433 } | 468 } |
| 434 | 469 |
| 435 private: | 470 private: |
| 436 sk_sp<GrTexture> fTexture; | 471 sk_sp<GrTexture> fTexture; |
| 437 const SkAlphaType fAlphaType; | 472 const SkAlphaType fAlphaType; |
| 438 sk_sp<SkColorSpace> fColorSpace; | 473 sk_sp<SkColorSpace> fColorSpace; |
| 439 mutable SkAtomic<bool> fAddedRasterVersionToCache; | 474 mutable SkAtomic<bool> fAddedRasterVersionToCache; |
| 440 | 475 |
| 441 typedef SkSpecialImage_Base INHERITED; | 476 typedef SkSpecialImage_Base INHERITED; |
| 442 }; | 477 }; |
| 443 | 478 |
| 444 sk_sp<SkSpecialImage> SkSpecialImage::MakeFromGpu(const SkIRect& subset, | 479 sk_sp<SkSpecialImage> SkSpecialImage::MakeFromGpu(const SkIRect& subset, |
| 445 uint32_t uniqueID, | 480 uint32_t uniqueID, |
| 446 sk_sp<GrTexture> tex, | 481 sk_sp<GrTexture> tex, |
| 447 sk_sp<SkColorSpace> colorSpace
, | 482 sk_sp<SkColorSpace> colorSpace
, |
| 448 const SkSurfaceProps* props, | 483 const SkSurfaceProps* props, |
| 449 SkAlphaType at) { | 484 SkAlphaType at) { |
| 450 SkASSERT(rect_fits(subset, tex->width(), tex->height())); | 485 SkASSERT(rect_fits(subset, tex->width(), tex->height())); |
| 451 return sk_make_sp<SkSpecialImage_Gpu>(subset, uniqueID, std::move(tex), at, | 486 return sk_make_sp<SkSpecialImage_Gpu>(subset, uniqueID, std::move(tex), at, |
| 452 std::move(colorSpace), props); | 487 std::move(colorSpace), props); |
| 453 } | 488 } |
| 454 | 489 |
| 455 #endif | 490 #endif |
| OLD | NEW |