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

Side by Side Diff: src/image/SkImage_Raster.cpp

Issue 1327313002: make a shallow-copy so we don't get racy trying to lock/unlock our private bitmap (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 5 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698