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 "SkCanvas.h" | 10 #include "SkCanvas.h" |
11 #include "SkColorTable.h" | 11 #include "SkColorTable.h" |
12 #include "SkData.h" | 12 #include "SkData.h" |
13 #include "SkImagePriv.h" | 13 #include "SkImagePriv.h" |
14 #include "SkPixelRef.h" | 14 #include "SkPixelRef.h" |
15 #include "SkSurface.h" | 15 #include "SkSurface.h" |
16 | 16 |
17 #if SK_SUPPORT_GPU | 17 #if SK_SUPPORT_GPU |
18 #include "GrContext.h" | 18 #include "GrContext.h" |
19 #include "SkGr.h" | 19 #include "SkGr.h" |
20 #include "SkGrPriv.h" | 20 #include "SkGrPriv.h" |
21 #endif | 21 #endif |
22 | 22 |
| 23 // fixes https://bug.skia.org/5096 |
| 24 static bool is_not_subset(const SkBitmap& bm) { |
| 25 SkASSERT(bm.pixelRef()); |
| 26 SkISize dim = bm.pixelRef()->info().dimensions(); |
| 27 SkASSERT(dim != bm.dimensions() || bm.pixelRefOrigin().isZero()); |
| 28 return dim == bm.dimensions(); |
| 29 } |
| 30 |
23 class SkImage_Raster : public SkImage_Base { | 31 class SkImage_Raster : public SkImage_Base { |
24 public: | 32 public: |
25 static bool ValidArgs(const Info& info, size_t rowBytes, bool hasColorTable, | 33 static bool ValidArgs(const Info& info, size_t rowBytes, bool hasColorTable, |
26 size_t* minSize) { | 34 size_t* minSize) { |
27 const int maxDimension = SK_MaxS32 >> 2; | 35 const int maxDimension = SK_MaxS32 >> 2; |
28 | 36 |
29 if (info.width() <= 0 || info.height() <= 0) { | 37 if (info.width() <= 0 || info.height() <= 0) { |
30 return false; | 38 return false; |
31 } | 39 } |
32 if (info.width() > maxDimension || info.height() > maxDimension) { | 40 if (info.width() > maxDimension || info.height() > maxDimension) { |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
75 | 83 |
76 // exposed for SkSurface_Raster via SkNewImageFromPixelRef | 84 // exposed for SkSurface_Raster via SkNewImageFromPixelRef |
77 SkImage_Raster(const SkImageInfo&, SkPixelRef*, const SkIPoint& origin, size
_t rowBytes); | 85 SkImage_Raster(const SkImageInfo&, SkPixelRef*, const SkIPoint& origin, size
_t rowBytes); |
78 | 86 |
79 SkPixelRef* getPixelRef() const { return fBitmap.pixelRef(); } | 87 SkPixelRef* getPixelRef() const { return fBitmap.pixelRef(); } |
80 | 88 |
81 bool isOpaque() const override; | 89 bool isOpaque() const override; |
82 bool onAsLegacyBitmap(SkBitmap*, LegacyBitmapMode) const override; | 90 bool onAsLegacyBitmap(SkBitmap*, LegacyBitmapMode) const override; |
83 | 91 |
84 SkImage_Raster(const SkBitmap& bm) | 92 SkImage_Raster(const SkBitmap& bm) |
85 : INHERITED(bm.width(), bm.height(), bm.getGenerationID()) | 93 : INHERITED(bm.width(), bm.height(), |
| 94 is_not_subset(bm) ? bm.getGenerationID() |
| 95 : (uint32_t)kNeedNewImageUniqueID) |
86 , fBitmap(bm) | 96 , fBitmap(bm) |
87 { | 97 { |
88 if (bm.pixelRef()->isPreLocked()) { | 98 if (bm.pixelRef()->isPreLocked()) { |
89 // we only preemptively lock if there is no chance of triggering som
ething expensive | 99 // we only preemptively lock if there is no chance of triggering som
ething expensive |
90 // like a lazy decode or imagegenerator. PreLocked means it is flat
pixels already. | 100 // like a lazy decode or imagegenerator. PreLocked means it is flat
pixels already. |
91 fBitmap.lockPixels(); | 101 fBitmap.lockPixels(); |
92 } | 102 } |
93 SkASSERT(fBitmap.isImmutable()); | 103 SkASSERT(fBitmap.isImmutable()); |
94 } | 104 } |
95 | 105 |
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
278 // pixelref since the caller might call setImmutable() themselves | 288 // pixelref since the caller might call setImmutable() themselves |
279 // (thus changing our state). | 289 // (thus changing our state). |
280 if (fBitmap.isImmutable()) { | 290 if (fBitmap.isImmutable()) { |
281 bitmap->setInfo(fBitmap.info(), fBitmap.rowBytes()); | 291 bitmap->setInfo(fBitmap.info(), fBitmap.rowBytes()); |
282 bitmap->setPixelRef(fBitmap.pixelRef(), fBitmap.pixelRefOrigin()); | 292 bitmap->setPixelRef(fBitmap.pixelRef(), fBitmap.pixelRefOrigin()); |
283 return true; | 293 return true; |
284 } | 294 } |
285 } | 295 } |
286 return this->INHERITED::onAsLegacyBitmap(bitmap, mode); | 296 return this->INHERITED::onAsLegacyBitmap(bitmap, mode); |
287 } | 297 } |
OLD | NEW |