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