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 SkIRect& size, SkAlphaTy
pe at) const = 0; |
56 | 56 |
57 virtual sk_sp<SkImage> onMakeTightSubset(const SkIRect& subset) const = 0; | 57 virtual sk_sp<SkImage> onMakeTightSubset(const SkIRect& subset) const = 0; |
58 | 58 |
59 virtual sk_sp<SkSurface> onMakeTightSurface(const SkImageInfo& info) const =
0; | 59 virtual sk_sp<SkSurface> onMakeTightSurface(const SkImageInfo& info) const =
0; |
60 | 60 |
61 private: | 61 private: |
62 typedef SkSpecialImage INHERITED; | 62 typedef SkSpecialImage INHERITED; |
63 }; | 63 }; |
64 | 64 |
65 /////////////////////////////////////////////////////////////////////////////// | 65 /////////////////////////////////////////////////////////////////////////////// |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
144 SkColorSpace* SkSpecialImage::getColorSpace() const { | 144 SkColorSpace* SkSpecialImage::getColorSpace() const { |
145 return as_SIB(this)->onGetColorSpace(); | 145 return as_SIB(this)->onGetColorSpace(); |
146 } | 146 } |
147 | 147 |
148 #if SK_SUPPORT_GPU | 148 #if SK_SUPPORT_GPU |
149 sk_sp<GrTexture> SkSpecialImage::asTextureRef(GrContext* context) const { | 149 sk_sp<GrTexture> SkSpecialImage::asTextureRef(GrContext* context) const { |
150 return as_SIB(this)->onAsTextureRef(context); | 150 return as_SIB(this)->onAsTextureRef(context); |
151 } | 151 } |
152 #endif | 152 #endif |
153 | 153 |
154 sk_sp<SkSpecialSurface> SkSpecialImage::makeSurface(const SkImageInfo& info) con
st { | 154 sk_sp<SkSpecialSurface> SkSpecialImage::makeSurface(const SkIRect& size, SkAlpha
Type at) const { |
155 return as_SIB(this)->onMakeSurface(info); | 155 return as_SIB(this)->onMakeSurface(size, at); |
156 } | 156 } |
157 | 157 |
158 sk_sp<SkSurface> SkSpecialImage::makeTightSurface(const SkImageInfo& info) const
{ | 158 sk_sp<SkSurface> SkSpecialImage::makeTightSurface(const SkImageInfo& info) const
{ |
159 return as_SIB(this)->onMakeTightSurface(info); | 159 return as_SIB(this)->onMakeTightSurface(info); |
160 } | 160 } |
161 | 161 |
162 sk_sp<SkSpecialImage> SkSpecialImage::makeSubset(const SkIRect& subset) const { | 162 sk_sp<SkSpecialImage> SkSpecialImage::makeSubset(const SkIRect& subset) const { |
163 return as_SIB(this)->onMakeSubset(subset); | 163 return as_SIB(this)->onMakeSubset(subset); |
164 } | 164 } |
165 | 165 |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
245 return sk_ref_sp(GrRefCachedBitmapTexture(context, | 245 return sk_ref_sp(GrRefCachedBitmapTexture(context, |
246 fBitmap, | 246 fBitmap, |
247 GrTextureParams::ClampNoFi
lter(), | 247 GrTextureParams::ClampNoFi
lter(), |
248 SkSourceGammaTreatment::kR
espect)); | 248 SkSourceGammaTreatment::kR
espect)); |
249 } | 249 } |
250 | 250 |
251 return nullptr; | 251 return nullptr; |
252 } | 252 } |
253 #endif | 253 #endif |
254 | 254 |
255 sk_sp<SkSpecialSurface> onMakeSurface(const SkImageInfo& info) const overrid
e { | 255 sk_sp<SkSpecialSurface> onMakeSurface(const SkIRect& size, SkAlphaType at) c
onst override { |
| 256 SkColorSpace* colorSpace = fBitmap.colorSpace(); |
| 257 SkColorType colorType = colorSpace && colorSpace->gammaIsLinear() |
| 258 ? kRGBA_F16_SkColorType : kN32_SkColorType; |
| 259 SkImageInfo info = SkImageInfo::Make(size.width(), size.height(), colorT
ype, at, |
| 260 sk_ref_sp(colorSpace)); |
256 return SkSpecialSurface::MakeRaster(info, nullptr); | 261 return SkSpecialSurface::MakeRaster(info, nullptr); |
257 } | 262 } |
258 | 263 |
259 sk_sp<SkSpecialImage> onMakeSubset(const SkIRect& subset) const override { | 264 sk_sp<SkSpecialImage> onMakeSubset(const SkIRect& subset) const override { |
260 SkBitmap subsetBM; | 265 SkBitmap subsetBM; |
261 | 266 |
262 if (!fBitmap.extractSubset(&subsetBM, subset)) { | 267 if (!fBitmap.extractSubset(&subsetBM, subset)) { |
263 return nullptr; | 268 return nullptr; |
264 } | 269 } |
265 | 270 |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
375 dst->pixelRef()->setImmutableWithID(this->uniqueID()); | 380 dst->pixelRef()->setImmutableWithID(this->uniqueID()); |
376 SkBitmapCache::Add(this->uniqueID(), *dst); | 381 SkBitmapCache::Add(this->uniqueID(), *dst); |
377 fAddedRasterVersionToCache.store(true); | 382 fAddedRasterVersionToCache.store(true); |
378 return true; | 383 return true; |
379 } | 384 } |
380 | 385 |
381 SkColorSpace* onGetColorSpace() const override { | 386 SkColorSpace* onGetColorSpace() const override { |
382 return fColorSpace.get(); | 387 return fColorSpace.get(); |
383 } | 388 } |
384 | 389 |
385 sk_sp<SkSpecialSurface> onMakeSurface(const SkImageInfo& info) const overrid
e { | 390 sk_sp<SkSpecialSurface> onMakeSurface(const SkIRect& size, SkAlphaType at) c
onst override { |
386 if (!fTexture->getContext()) { | 391 if (!fTexture->getContext()) { |
387 return nullptr; | 392 return nullptr; |
388 } | 393 } |
389 | 394 |
390 GrPixelConfig config = SkImageInfo2GrPixelConfig(info, *fTexture->getCon
text()->caps()); | 395 return SkSpecialSurface::MakeRenderTarget( |
391 | 396 fTexture->getContext(), size.width(), size.height(), |
392 return SkSpecialSurface::MakeRenderTarget(fTexture->getContext(), | 397 GrRenderableConfigForColorSpace(fColorSpace.get()), fColorSpace); |
393 info.width(), info.height(), | |
394 config, sk_ref_sp(info.colorSp
ace())); | |
395 } | 398 } |
396 | 399 |
397 sk_sp<SkSpecialImage> onMakeSubset(const SkIRect& subset) const override { | 400 sk_sp<SkSpecialImage> onMakeSubset(const SkIRect& subset) const override { |
398 return SkSpecialImage::MakeFromGpu(subset, | 401 return SkSpecialImage::MakeFromGpu(subset, |
399 this->uniqueID(), | 402 this->uniqueID(), |
400 fTexture, | 403 fTexture, |
401 fColorSpace, | 404 fColorSpace, |
402 &this->props(), | 405 &this->props(), |
403 fAlphaType); | 406 fAlphaType); |
404 } | 407 } |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
446 sk_sp<GrTexture> tex, | 449 sk_sp<GrTexture> tex, |
447 sk_sp<SkColorSpace> colorSpace
, | 450 sk_sp<SkColorSpace> colorSpace
, |
448 const SkSurfaceProps* props, | 451 const SkSurfaceProps* props, |
449 SkAlphaType at) { | 452 SkAlphaType at) { |
450 SkASSERT(rect_fits(subset, tex->width(), tex->height())); | 453 SkASSERT(rect_fits(subset, tex->width(), tex->height())); |
451 return sk_make_sp<SkSpecialImage_Gpu>(subset, uniqueID, std::move(tex), at, | 454 return sk_make_sp<SkSpecialImage_Gpu>(subset, uniqueID, std::move(tex), at, |
452 std::move(colorSpace), props); | 455 std::move(colorSpace), props); |
453 } | 456 } |
454 | 457 |
455 #endif | 458 #endif |
OLD | NEW |