OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2012 Google Inc. | 2 * Copyright 2012 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 "SkImage_Base.h" | 8 #include "SkImage_Base.h" |
9 #include "SkBitmap.h" | 9 #include "SkBitmap.h" |
10 #include "SkBitmapProcShader.h" | 10 #include "SkBitmapProcShader.h" |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
71 } | 71 } |
72 return true; | 72 return true; |
73 } | 73 } |
74 | 74 |
75 SkImage_Raster(const SkImageInfo&, sk_sp<SkData>, size_t rb, SkColorTable*); | 75 SkImage_Raster(const SkImageInfo&, sk_sp<SkData>, size_t rb, SkColorTable*); |
76 virtual ~SkImage_Raster(); | 76 virtual ~SkImage_Raster(); |
77 | 77 |
78 SkImageInfo onImageInfo() const override { | 78 SkImageInfo onImageInfo() const override { |
79 return fBitmap.info(); | 79 return fBitmap.info(); |
80 } | 80 } |
| 81 SkAlphaType onAlphaType() const override { |
| 82 return fBitmap.alphaType(); |
| 83 } |
81 | 84 |
82 bool onReadPixels(const SkImageInfo&, void*, size_t, int srcX, int srcY, Cac
hingHint) const override; | 85 bool onReadPixels(const SkImageInfo&, void*, size_t, int srcX, int srcY, Cac
hingHint) const override; |
83 bool onPeekPixels(SkPixmap*) const override; | 86 bool onPeekPixels(SkPixmap*) const override; |
84 const SkBitmap* onPeekBitmap() const override { return &fBitmap; } | 87 const SkBitmap* onPeekBitmap() const override { return &fBitmap; } |
85 | 88 |
86 SkData* onRefEncoded(GrContext*) const override; | 89 SkData* onRefEncoded(GrContext*) const override; |
87 bool getROPixels(SkBitmap*, CachingHint) const override; | 90 bool getROPixels(SkBitmap*, CachingHint) const override; |
88 GrTexture* asTextureRef(GrContext*, const GrTextureParams&, | 91 GrTexture* asTextureRef(GrContext*, const GrTextureParams&, |
89 SkSourceGammaTreatment) const override; | 92 SkSourceGammaTreatment) const override; |
90 sk_sp<SkImage> onMakeSubset(const SkIRect&) const override; | 93 sk_sp<SkImage> onMakeSubset(const SkIRect&) const override; |
91 | 94 |
92 // exposed for SkSurface_Raster via SkNewImageFromPixelRef | 95 // exposed for SkSurface_Raster via SkNewImageFromPixelRef |
93 SkImage_Raster(const SkImageInfo&, SkPixelRef*, const SkIPoint& origin, size
_t rowBytes); | 96 SkImage_Raster(const SkImageInfo&, SkPixelRef*, const SkIPoint& origin, size
_t rowBytes); |
94 | 97 |
95 SkPixelRef* getPixelRef() const { return fBitmap.pixelRef(); } | 98 SkPixelRef* getPixelRef() const { return fBitmap.pixelRef(); } |
96 | 99 |
97 bool isOpaque() const override; | |
98 bool onAsLegacyBitmap(SkBitmap*, LegacyBitmapMode) const override; | 100 bool onAsLegacyBitmap(SkBitmap*, LegacyBitmapMode) const override; |
99 | 101 |
100 SkImage_Raster(const SkBitmap& bm, bool bitmapMayBeMutable = false) | 102 SkImage_Raster(const SkBitmap& bm, bool bitmapMayBeMutable = false) |
101 : INHERITED(bm.width(), bm.height(), | 103 : INHERITED(bm.width(), bm.height(), |
102 is_not_subset(bm) ? bm.getGenerationID() | 104 is_not_subset(bm) ? bm.getGenerationID() |
103 : (uint32_t)kNeedNewImageUniqueID) | 105 : (uint32_t)kNeedNewImageUniqueID) |
104 , fBitmap(bm) | 106 , fBitmap(bm) |
105 { | 107 { |
106 if (bm.pixelRef()->isPreLocked()) { | 108 if (bm.pixelRef()->isPreLocked()) { |
107 // we only preemptively lock if there is no chance of triggering som
ething expensive | 109 // we only preemptively lock if there is no chance of triggering som
ething expensive |
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
353 image = sk_make_sp<SkImage_Raster>(bm, kNever_SkCopyPixelsMode == cp
m); | 355 image = sk_make_sp<SkImage_Raster>(bm, kNever_SkCopyPixelsMode == cp
m); |
354 } | 356 } |
355 } | 357 } |
356 return image; | 358 return image; |
357 } | 359 } |
358 | 360 |
359 const SkPixelRef* SkBitmapImageGetPixelRef(const SkImage* image) { | 361 const SkPixelRef* SkBitmapImageGetPixelRef(const SkImage* image) { |
360 return ((const SkImage_Raster*)image)->getPixelRef(); | 362 return ((const SkImage_Raster*)image)->getPixelRef(); |
361 } | 363 } |
362 | 364 |
363 bool SkImage_Raster::isOpaque() const { | |
364 return fBitmap.isOpaque(); | |
365 } | |
366 | |
367 bool SkImage_Raster::onAsLegacyBitmap(SkBitmap* bitmap, LegacyBitmapMode mode) c
onst { | 365 bool SkImage_Raster::onAsLegacyBitmap(SkBitmap* bitmap, LegacyBitmapMode mode) c
onst { |
368 if (kRO_LegacyBitmapMode == mode) { | 366 if (kRO_LegacyBitmapMode == mode) { |
369 // When we're a snapshot from a surface, our bitmap may not be marked im
mutable | 367 // When we're a snapshot from a surface, our bitmap may not be marked im
mutable |
370 // even though logically always we are, but in that case we can't physic
ally share our | 368 // even though logically always we are, but in that case we can't physic
ally share our |
371 // pixelref since the caller might call setImmutable() themselves | 369 // pixelref since the caller might call setImmutable() themselves |
372 // (thus changing our state). | 370 // (thus changing our state). |
373 if (fBitmap.isImmutable()) { | 371 if (fBitmap.isImmutable()) { |
374 bitmap->setInfo(fBitmap.info(), fBitmap.rowBytes()); | 372 bitmap->setInfo(fBitmap.info(), fBitmap.rowBytes()); |
375 bitmap->setPixelRef(fBitmap.pixelRef(), fBitmap.pixelRefOrigin()); | 373 bitmap->setPixelRef(fBitmap.pixelRef(), fBitmap.pixelRefOrigin()); |
376 return true; | 374 return true; |
377 } | 375 } |
378 } | 376 } |
379 return this->INHERITED::onAsLegacyBitmap(bitmap, mode); | 377 return this->INHERITED::onAsLegacyBitmap(bitmap, mode); |
380 } | 378 } |
OLD | NEW |