Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(218)

Side by Side Diff: src/core/SkSpecialImage.cpp

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

Powered by Google App Engine
This is Rietveld 408576698