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" |
11 #include "SkBitmapCache.h" | 11 #include "SkBitmapCache.h" |
12 #include "SkCanvas.h" | 12 #include "SkCanvas.h" |
13 #include "SkImage_Base.h" | 13 #include "SkImage_Base.h" |
14 #include "SkSpecialSurface.h" | 14 #include "SkSpecialSurface.h" |
15 #include "SkSurfacePriv.h" | 15 #include "SkSurfacePriv.h" |
16 #include "SkPixelRef.h" | 16 #include "SkPixelRef.h" |
17 | 17 |
18 #if SK_SUPPORT_GPU | 18 #if SK_SUPPORT_GPU |
19 #include "GrContext.h" | 19 #include "GrContext.h" |
20 #include "GrTexture.h" | 20 #include "GrTexture.h" |
21 #include "GrTextureParams.h" | 21 #include "GrTextureParams.h" |
22 #include "SkGr.h" | 22 #include "SkGr.h" |
23 #include "SkGrPixelRef.h" | |
24 #include "SkGrPriv.h" | 23 #include "SkGrPriv.h" |
25 #endif | 24 #endif |
26 | 25 |
27 // Currently the raster imagefilters can only handle certain imageinfos. Call th
is to know if | 26 // Currently the raster imagefilters can only handle certain imageinfos. Call th
is to know if |
28 // a given info is supported. | 27 // a given info is supported. |
29 static bool valid_for_imagefilters(const SkImageInfo& info) { | 28 static bool valid_for_imagefilters(const SkImageInfo& info) { |
30 // no support for other swizzles/depths yet | 29 // no support for other swizzles/depths yet |
31 return info.colorType() == kN32_SkColorType; | 30 return info.colorType() == kN32_SkColorType; |
32 } | 31 } |
33 | 32 |
(...skipping 10 matching lines...) Expand all Loading... |
44 virtual bool onGetROPixels(SkBitmap*) const = 0; | 43 virtual bool onGetROPixels(SkBitmap*) const = 0; |
45 | 44 |
46 virtual GrTexture* onPeekTexture() const { return nullptr; } | 45 virtual GrTexture* onPeekTexture() const { return nullptr; } |
47 | 46 |
48 virtual SkColorSpace* onGetColorSpace() const = 0; | 47 virtual SkColorSpace* onGetColorSpace() const = 0; |
49 | 48 |
50 #if SK_SUPPORT_GPU | 49 #if SK_SUPPORT_GPU |
51 virtual sk_sp<GrTexture> onAsTextureRef(GrContext* context) const = 0; | 50 virtual sk_sp<GrTexture> onAsTextureRef(GrContext* context) const = 0; |
52 #endif | 51 #endif |
53 | 52 |
54 // Delete this entry point ASAP (see skbug.com/4965) | |
55 virtual bool getBitmapDeprecated(SkBitmap* result) const = 0; | |
56 | |
57 virtual sk_sp<SkSpecialImage> onMakeSubset(const SkIRect& subset) const = 0; | 53 virtual sk_sp<SkSpecialImage> onMakeSubset(const SkIRect& subset) const = 0; |
58 | 54 |
59 virtual sk_sp<SkSpecialSurface> onMakeSurface(const SkImageInfo& info) const
= 0; | 55 virtual sk_sp<SkSpecialSurface> onMakeSurface(const SkImageInfo& info) const
= 0; |
60 | 56 |
61 virtual sk_sp<SkImage> onMakeTightSubset(const SkIRect& subset) const = 0; | 57 virtual sk_sp<SkImage> onMakeTightSubset(const SkIRect& subset) const = 0; |
62 | 58 |
63 virtual sk_sp<SkSurface> onMakeTightSurface(const SkImageInfo& info) const =
0; | 59 virtual sk_sp<SkSurface> onMakeTightSurface(const SkImageInfo& info) const =
0; |
64 | 60 |
65 private: | 61 private: |
66 typedef SkSpecialImage INHERITED; | 62 typedef SkSpecialImage INHERITED; |
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
248 return sk_ref_sp(GrRefCachedBitmapTexture(context, | 244 return sk_ref_sp(GrRefCachedBitmapTexture(context, |
249 fBitmap, | 245 fBitmap, |
250 GrTextureParams::ClampNoFi
lter(), | 246 GrTextureParams::ClampNoFi
lter(), |
251 SkSourceGammaTreatment::kR
espect)); | 247 SkSourceGammaTreatment::kR
espect)); |
252 } | 248 } |
253 | 249 |
254 return nullptr; | 250 return nullptr; |
255 } | 251 } |
256 #endif | 252 #endif |
257 | 253 |
258 bool getBitmapDeprecated(SkBitmap* result) const override { | |
259 *result = fBitmap; | |
260 return true; | |
261 } | |
262 | |
263 sk_sp<SkSpecialSurface> onMakeSurface(const SkImageInfo& info) const overrid
e { | 254 sk_sp<SkSpecialSurface> onMakeSurface(const SkImageInfo& info) const overrid
e { |
264 return SkSpecialSurface::MakeRaster(info, nullptr); | 255 return SkSpecialSurface::MakeRaster(info, nullptr); |
265 } | 256 } |
266 | 257 |
267 sk_sp<SkSpecialImage> onMakeSubset(const SkIRect& subset) const override { | 258 sk_sp<SkSpecialImage> onMakeSubset(const SkIRect& subset) const override { |
268 SkBitmap subsetBM; | 259 SkBitmap subsetBM; |
269 | 260 |
270 if (!fBitmap.extractSubset(&subsetBM, subset)) { | 261 if (!fBitmap.extractSubset(&subsetBM, subset)) { |
271 return nullptr; | 262 return nullptr; |
272 } | 263 } |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
384 dst->pixelRef()->setImmutableWithID(this->uniqueID()); | 375 dst->pixelRef()->setImmutableWithID(this->uniqueID()); |
385 SkBitmapCache::Add(this->uniqueID(), *dst); | 376 SkBitmapCache::Add(this->uniqueID(), *dst); |
386 fAddedRasterVersionToCache.store(true); | 377 fAddedRasterVersionToCache.store(true); |
387 return true; | 378 return true; |
388 } | 379 } |
389 | 380 |
390 SkColorSpace* onGetColorSpace() const override { | 381 SkColorSpace* onGetColorSpace() const override { |
391 return fColorSpace.get(); | 382 return fColorSpace.get(); |
392 } | 383 } |
393 | 384 |
394 bool getBitmapDeprecated(SkBitmap* result) const override { | |
395 const SkImageInfo info = GrMakeInfoFromTexture(fTexture.get(), | |
396 this->width(), this->heig
ht(), | |
397 this->isOpaque(), fColorS
pace); | |
398 if (!result->setInfo(info)) { | |
399 return false; | |
400 } | |
401 | |
402 const SkImageInfo prInfo = info.makeWH(fTexture->width(), fTexture->heig
ht()); | |
403 | |
404 SkAutoTUnref<SkGrPixelRef> pixelRef(new SkGrPixelRef(prInfo, fTexture.ge
t())); | |
405 result->setPixelRef(pixelRef, this->subset().fLeft, this->subset().fTop)
; | |
406 return true; | |
407 } | |
408 | |
409 sk_sp<SkSpecialSurface> onMakeSurface(const SkImageInfo& info) const overrid
e { | 385 sk_sp<SkSpecialSurface> onMakeSurface(const SkImageInfo& info) const overrid
e { |
410 if (!fTexture->getContext()) { | 386 if (!fTexture->getContext()) { |
411 return nullptr; | 387 return nullptr; |
412 } | 388 } |
413 | 389 |
414 GrPixelConfig config = SkImageInfo2GrPixelConfig(info, *fTexture->getCon
text()->caps()); | 390 GrPixelConfig config = SkImageInfo2GrPixelConfig(info, *fTexture->getCon
text()->caps()); |
415 | 391 |
416 return SkSpecialSurface::MakeRenderTarget(fTexture->getContext(), | 392 return SkSpecialSurface::MakeRenderTarget(fTexture->getContext(), |
417 info.width(), info.height(), | 393 info.width(), info.height(), |
418 config); | 394 config); |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
470 sk_sp<GrTexture> tex, | 446 sk_sp<GrTexture> tex, |
471 sk_sp<SkColorSpace> colorSpace
, | 447 sk_sp<SkColorSpace> colorSpace
, |
472 const SkSurfaceProps* props, | 448 const SkSurfaceProps* props, |
473 SkAlphaType at) { | 449 SkAlphaType at) { |
474 SkASSERT(rect_fits(subset, tex->width(), tex->height())); | 450 SkASSERT(rect_fits(subset, tex->width(), tex->height())); |
475 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, |
476 std::move(colorSpace), props); | 452 std::move(colorSpace), props); |
477 } | 453 } |
478 | 454 |
479 #endif | 455 #endif |
OLD | NEW |