Chromium Code Reviews| 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" |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 158 const SkImageInfo info = fBitmap.info(); | 158 const SkImageInfo info = fBitmap.info(); |
| 159 if ((kUnknown_SkColorType == info.colorType()) || !fBitmap.getPixels()) { | 159 if ((kUnknown_SkColorType == info.colorType()) || !fBitmap.getPixels()) { |
| 160 return nullptr; | 160 return nullptr; |
| 161 } | 161 } |
| 162 *infoPtr = info; | 162 *infoPtr = info; |
| 163 *rowBytesPtr = fBitmap.rowBytes(); | 163 *rowBytesPtr = fBitmap.rowBytes(); |
| 164 return fBitmap.getPixels(); | 164 return fBitmap.getPixels(); |
| 165 } | 165 } |
| 166 | 166 |
| 167 void SkImage_Raster::onPreroll(GrContext* ctx) const { | 167 void SkImage_Raster::onPreroll(GrContext* ctx) const { |
| 168 fBitmap.lockPixels(); | 168 // SkImage can be called from lots of threads, but our fBitmap is *not* thre ad-safe, |
| 169 fBitmap.unlockPixels(); | 169 // so we have to perform this lock/unlock in a non-racy way... we make a cop y! |
| 170 SkBitmap localShallowCopy(fBitmap); | |
| 171 localShallowCopy.lockPixels(); | |
| 172 localShallowCopy.unlockPixels(); | |
|
f(malita)
2015/09/10 18:36:37
This may solve the preRoll race, but don't we have
| |
| 170 } | 173 } |
| 171 | 174 |
| 172 SkData* SkImage_Raster::onRefEncoded() const { | 175 SkData* SkImage_Raster::onRefEncoded() const { |
| 173 SkPixelRef* pr = fBitmap.pixelRef(); | 176 SkPixelRef* pr = fBitmap.pixelRef(); |
| 174 const SkImageInfo prInfo = pr->info(); | 177 const SkImageInfo prInfo = pr->info(); |
| 175 const SkImageInfo bmInfo = fBitmap.info(); | 178 const SkImageInfo bmInfo = fBitmap.info(); |
| 176 | 179 |
| 177 // we only try if we (the image) cover the entire area of the pixelRef | 180 // we only try if we (the image) cover the entire area of the pixelRef |
| 178 if (prInfo.width() == bmInfo.width() && prInfo.height() == bmInfo.height()) { | 181 if (prInfo.width() == bmInfo.width() && prInfo.height() == bmInfo.height()) { |
| 179 return pr->refEncodedData(); | 182 return pr->refEncodedData(); |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 291 // pixelref since the caller might call setImmutable() themselves | 294 // pixelref since the caller might call setImmutable() themselves |
| 292 // (thus changing our state). | 295 // (thus changing our state). |
| 293 if (fBitmap.isImmutable()) { | 296 if (fBitmap.isImmutable()) { |
| 294 bitmap->setInfo(fBitmap.info(), fBitmap.rowBytes()); | 297 bitmap->setInfo(fBitmap.info(), fBitmap.rowBytes()); |
| 295 bitmap->setPixelRef(fBitmap.pixelRef(), fBitmap.pixelRefOrigin()); | 298 bitmap->setPixelRef(fBitmap.pixelRef(), fBitmap.pixelRefOrigin()); |
| 296 return true; | 299 return true; |
| 297 } | 300 } |
| 298 } | 301 } |
| 299 return this->INHERITED::onAsLegacyBitmap(bitmap, mode); | 302 return this->INHERITED::onAsLegacyBitmap(bitmap, mode); |
| 300 } | 303 } |
| OLD | NEW |