From 4edb5d219eb99aa1e8fbe5e37260d3b34314e54b Mon Sep 17 00:00:00 2001 From: Mike Reed Date: Mon, 17 Apr 2017 11:02:51 -0400 Subject: hide lockpixels api behind flag guarded by SK_SUPPORT_OBSOLETE_LOCKPIXELS needs https://codereview.chromium.org/2820873002/# to land first Bug: skia:6481 Change-Id: I1c39902cbf6fe99f622adfa8192733b95f7fea09 Change-Id: I1c39902cbf6fe99f622adfa8192733b95f7fea09 Reviewed-on: https://skia-review.googlesource.com/13580 Reviewed-by: Florin Malita Reviewed-by: Leon Scroggins Commit-Queue: Mike Reed --- bench/BitmapBench.cpp | 3 - bench/GameBench.cpp | 2 - bench/RepeatTileBench.cpp | 3 - bench/TileBench.cpp | 1 - dm/DM.cpp | 3 - dm/DMSrcSink.cpp | 1 - fuzz/FuzzCanvas.cpp | 1 - gm/all_bitmap_configs.cpp | 3 - gm/drawbitmaprect.cpp | 1 - gm/encode-platform.cpp | 2 - gm/encode-srgb.cpp | 1 - gm/image_pict.cpp | 6 +- gm/showmiplevels.cpp | 3 - gm/tinybitmap.cpp | 2 - gm/xfermodes3.cpp | 1 - gn/android_framework_defines.gni | 1 + include/core/SkBitmap.h | 27 +++------ include/core/SkImageEncoder.h | 1 - include/core/SkPixelRef.h | 80 ++++++++++++-------------- include/core/SkPixmap.h | 4 +- samplecode/SampleApp.cpp | 1 - samplecode/SampleBlur.cpp | 2 - samplecode/SampleDither.cpp | 2 - samplecode/SampleDitherBitmap.cpp | 3 - samplecode/SampleTextureDomain.cpp | 1 - samplecode/SampleTinyBitmap.cpp | 3 - samplecode/SampleUnpremul.cpp | 1 - samplecode/SampleVertices.cpp | 2 - src/core/SkBitmap.cpp | 41 ++++++------- src/core/SkBitmapController.cpp | 11 ++-- src/core/SkBitmapDevice.cpp | 3 - src/core/SkBitmapScaler.cpp | 1 - src/core/SkBlurImageFilter.cpp | 2 - src/core/SkCanvas.cpp | 10 ++-- src/core/SkDraw.cpp | 15 ++--- src/core/SkImageCacherator.cpp | 1 - src/core/SkMipMap.cpp | 9 +-- src/core/SkPixelRef.cpp | 26 +++++---- src/core/SkPixmap.cpp | 2 + src/core/SkSpecialImage.cpp | 5 -- src/core/SkWriteBuffer.cpp | 6 +- src/effects/SkAlphaThresholdFilter.cpp | 4 -- src/effects/SkArithmeticImageFilter.cpp | 1 - src/effects/SkDisplacementMapEffect.cpp | 3 - src/effects/SkLightingImageFilter.cpp | 6 -- src/effects/SkMagnifierImageFilter.cpp | 3 - src/effects/SkMatrixConvolutionImageFilter.cpp | 8 +-- src/effects/SkMorphologyImageFilter.cpp | 4 -- src/effects/SkTableColorFilter.cpp | 1 - src/effects/gradients/SkGradientShader.cpp | 2 - src/gpu/SkGpuDevice.cpp | 6 -- src/gpu/SkGr.cpp | 10 +--- src/gpu/effects/GrTextureStripAtlas.cpp | 2 - src/image/SkImage.cpp | 10 ++-- src/image/SkImage_Raster.cpp | 12 +--- src/image/SkSurface_Raster.cpp | 1 - src/pdf/SkPDFBitmap.cpp | 12 +--- src/pdf/SkPDFDevice.cpp | 2 - src/pdf/SkPDFShader.cpp | 1 - src/utils/mac/SkCreateCGImageRef.cpp | 3 - src/views/win/SkOSWindow_win.cpp | 2 - src/xps/SkXPSDevice.cpp | 2 - tests/BitmapCopyTest.cpp | 3 - tests/BitmapTest.cpp | 2 - tests/BlendTest.cpp | 2 - tests/BlurTest.cpp | 4 -- tests/CodecPartialTest.cpp | 4 -- tests/CodecTest.cpp | 7 --- tests/DrawBitmapRectTest.cpp | 2 - tests/DrawTextTest.cpp | 3 - tests/FontHostStreamTest.cpp | 3 - tests/GradientTest.cpp | 1 - tests/HighContrastFilterTest.cpp | 4 -- tests/ImageFilterTest.cpp | 7 --- tests/ImageFrom565Bitmap.cpp | 1 - tests/ImageNewShaderTest.cpp | 4 -- tests/ImageTest.cpp | 4 -- tests/ReadPixelsTest.cpp | 7 --- tests/SerializationTest.cpp | 2 - tests/SurfaceTest.cpp | 1 - tests/WritePixelsTest.cpp | 2 - tools/debugger/SkDrawCommand.cpp | 2 - tools/picture_utils.cpp | 3 - tools/sk_tool_utils.cpp | 2 - tools/skdiff/skdiff.cpp | 2 - tools/skdiff/skdiff_utils.cpp | 1 - 86 files changed, 112 insertions(+), 349 deletions(-) diff --git a/bench/BitmapBench.cpp b/bench/BitmapBench.cpp index fdf17e90b1..2fd480bb7a 100644 --- a/bench/BitmapBench.cpp +++ b/bench/BitmapBench.cpp @@ -47,9 +47,6 @@ static void convertToIndex666(const SkBitmap& src, SkBitmap* dst, SkAlphaType aT dst->allocPixels(SkImageInfo::Make(src.width(), src.height(), kIndex_8_SkColorType, aType), SkColorTable::Make(storage, 216)); - SkAutoLockPixels alps(src); - SkAutoLockPixels alpd(*dst); - for (int y = 0; y < src.height(); y++) { const SkPMColor* srcP = src.getAddr32(0, y); uint8_t* dstP = dst->getAddr8(0, y); diff --git a/bench/GameBench.cpp b/bench/GameBench.cpp index bd7d11465d..dfd0aa1649 100644 --- a/bench/GameBench.cpp +++ b/bench/GameBench.cpp @@ -250,7 +250,6 @@ private: static int kCheckSize = 16; fCheckerboard.allocN32Pixels(kCheckerboardWidth, kCheckerboardHeight); - SkAutoLockPixels lock(fCheckerboard); for (int y = 0; y < kCheckerboardHeight; ++y) { int even = (y / kCheckSize) % 2; @@ -283,7 +282,6 @@ private: } fAtlas.allocN32Pixels(kTotAtlasWidth, kTotAtlasHeight); - SkAutoLockPixels lock(fAtlas); for (int y = 0; y < kTotAtlasHeight; ++y) { int colorY = y / (kAtlasCellHeight + kAtlasSpacer); diff --git a/bench/RepeatTileBench.cpp b/bench/RepeatTileBench.cpp index df58a14d10..550603143d 100644 --- a/bench/RepeatTileBench.cpp +++ b/bench/RepeatTileBench.cpp @@ -66,9 +66,6 @@ static void convert_to_index666(const SkBitmap& src, SkBitmap* dst) { kIndex_8_SkColorType, kOpaque_SkAlphaType), SkColorTable::Make(storage, 216)); - SkAutoLockPixels alps(src); - SkAutoLockPixels alpd(*dst); - for (int y = 0; y < src.height(); y++) { const SkPMColor* srcP = src.getAddr32(0, y); uint8_t* dstP = dst->getAddr8(0, y); diff --git a/bench/TileBench.cpp b/bench/TileBench.cpp index 3093016f72..cd2654611b 100644 --- a/bench/TileBench.cpp +++ b/bench/TileBench.cpp @@ -18,7 +18,6 @@ static void create_gradient(SkBitmap* bm) { float deltaB = 255.0f / height; float blue = 255.0f; - SkAutoLockPixels lock(*bm); for (int y = 0; y < height; y++) { *bm->getAddr32(0, y) = SkColorSetRGB(0, 0, (U8CPU) blue); blue -= deltaB; diff --git a/dm/DM.cpp b/dm/DM.cpp index 340c338c27..707c4c95b1 100644 --- a/dm/DM.cpp +++ b/dm/DM.cpp @@ -1110,9 +1110,6 @@ struct Task { gDefinitelyThreadSafeWork.add([task,name,bitmap,data]{ std::unique_ptr ownedData(data); - // Why doesn't the copy constructor do this when we have pre-locked pixels? - bitmap.lockPixels(); - SkString md5; if (!FLAGS_writePath.isEmpty() || !FLAGS_readPath.isEmpty()) { SkMD5 hash; diff --git a/dm/DMSrcSink.cpp b/dm/DMSrcSink.cpp index 3a19751409..b223c97f56 100644 --- a/dm/DMSrcSink.cpp +++ b/dm/DMSrcSink.cpp @@ -1567,7 +1567,6 @@ Error ViaUpright::draw(const Src& src, SkBitmap* bitmap, SkWStream* stream, SkSt canvas.drawBitmap(*bitmap, 0, 0, &paint); *bitmap = uprighted; - bitmap->lockPixels(); return ""; } diff --git a/fuzz/FuzzCanvas.cpp b/fuzz/FuzzCanvas.cpp index ba9f3eda90..3796812012 100644 --- a/fuzz/FuzzCanvas.cpp +++ b/fuzz/FuzzCanvas.cpp @@ -982,7 +982,6 @@ static SkBitmap make_fuzz_bitmap(Fuzz* fuzz) { fuzz->nextRange(&w, 1, 1024); fuzz->nextRange(&h, 1, 1024); bitmap.allocN32Pixels(w, h); - SkAutoLockPixels autoLockPixels(bitmap); for (int y = 0; y < h; ++y) { for (int x = 0; x < w; ++x) { SkColor c; diff --git a/gm/all_bitmap_configs.cpp b/gm/all_bitmap_configs.cpp index 60aec88ddf..7e9dfab522 100644 --- a/gm/all_bitmap_configs.cpp +++ b/gm/all_bitmap_configs.cpp @@ -37,7 +37,6 @@ static SkBitmap make_bitmap(SkColorType ct) { SkASSERT(false); return bm; } - SkAutoLockPixels autoLockPixels(bm); uint8_t spectrum[256]; for (int y = 0; y < 256; ++y) { spectrum[y] = y; @@ -127,8 +126,6 @@ static SkBitmap indexed_bitmap() { SkImageInfo info = SkImageInfo::Make(SCALE, SCALE, kIndex_8_SkColorType, kPremul_SkAlphaType); bm.allocPixels(info, SkColorTable::Make(pmColors, SK_ARRAY_COUNT(pmColors))); - SkAutoLockPixels autoLockPixels1(n32bitmap); - SkAutoLockPixels autoLockPixels2(bm); for (int y = 0; y < SCALE; ++y) { for (int x = 0; x < SCALE; ++x) { SkPMColor c = *n32bitmap.getAddr32(x, y); diff --git a/gm/drawbitmaprect.cpp b/gm/drawbitmaprect.cpp index bad5e2a143..0becf45183 100644 --- a/gm/drawbitmaprect.cpp +++ b/gm/drawbitmaprect.cpp @@ -28,7 +28,6 @@ static SkBitmap make_chessbm(int w, int h) { p[x] = ((x + y) & 1) ? SK_ColorWHITE : SK_ColorBLACK; } } - bm.unlockPixels(); return bm; } diff --git a/gm/encode-platform.cpp b/gm/encode-platform.cpp index ca3cda1d73..f08da73ce8 100644 --- a/gm/encode-platform.cpp +++ b/gm/encode-platform.cpp @@ -23,7 +23,6 @@ static void make_premul_256(SkBitmap* bitmap) { SkBitmap tmp; GetResourceAsBitmap("yellow_rose.png", &tmp); tmp.extractSubset(bitmap, SkIRect::MakeWH(256, 256)); - bitmap->lockPixels(); } static void make_unpremul_256(SkBitmap* bitmap) { @@ -57,7 +56,6 @@ static SkEncodedImageFormat kTypes[] { #endif static sk_sp encode_data(SkEncodedImageFormat type, const SkBitmap& bitmap) { - SkAutoLockPixels autoLockPixels(bitmap); SkPixmap src; if (!bitmap.peekPixels(&src)) { return nullptr; diff --git a/gm/encode-srgb.cpp b/gm/encode-srgb.cpp index 894b0ef8d5..3015baa4a0 100644 --- a/gm/encode-srgb.cpp +++ b/gm/encode-srgb.cpp @@ -109,7 +109,6 @@ static void make(SkBitmap* bitmap, SkColorType colorType, SkAlphaType alphaType, } static sk_sp encode_data(const SkBitmap& bitmap, SkEncodedImageFormat format) { - SkAutoLockPixels autoLockPixels(bitmap); SkPixmap src; if (!bitmap.peekPixels(&src)) { return nullptr; diff --git a/gm/image_pict.cpp b/gm/image_pict.cpp index f23b89e728..904daaebd5 100644 --- a/gm/image_pict.cpp +++ b/gm/image_pict.cpp @@ -118,9 +118,9 @@ static std::unique_ptr make_pic_generator(GrContext*, sk_sptranslate(orig.width()/2 + 8.0f, 0); diff --git a/gm/tinybitmap.cpp b/gm/tinybitmap.cpp index 1640cb23d1..f8103cfb88 100644 --- a/gm/tinybitmap.cpp +++ b/gm/tinybitmap.cpp @@ -21,9 +21,7 @@ static SkBitmap make_bitmap() { kPremul_SkAlphaType), SkColorTable::Make(c, SK_ARRAY_COUNT(c))); - bm.lockPixels(); *bm.getAddr8(0, 0) = 0; - bm.unlockPixels(); return bm; } diff --git a/gm/xfermodes3.cpp b/gm/xfermodes3.cpp index f977b66911..6e4d8b81bc 100644 --- a/gm/xfermodes3.cpp +++ b/gm/xfermodes3.cpp @@ -182,7 +182,6 @@ private: }; SkBitmap bg; bg.allocN32Pixels(2, 2, true); - SkAutoLockPixels bgAlp(bg); memcpy(bg.getPixels(), kCheckData, sizeof(kCheckData)); SkMatrix lm; diff --git a/gn/android_framework_defines.gni b/gn/android_framework_defines.gni index 67c6a2d5e2..bf5a0514f7 100644 --- a/gn/android_framework_defines.gni +++ b/gn/android_framework_defines.gni @@ -12,4 +12,5 @@ android_framework_defines = [ "SK_IGNORE_GPU_DITHER", "SK_SUPPORT_LEGACY_SHADER_ISABITMAP", "SK_SUPPORT_LEGACY_EMBOSSMASKFILTER", + "SK_SUPPORT_OBSOLETE_LOCKPIXELS", ] diff --git a/include/core/SkBitmap.h b/include/core/SkBitmap.h index 9520210888..e19f45232e 100644 --- a/include/core/SkBitmap.h +++ b/include/core/SkBitmap.h @@ -217,8 +217,8 @@ public: * "unknown" pixels. */ static bool ComputeIsOpaque(const SkBitmap& bm) { - SkAutoPixmapUnlock result; - return bm.requestLock(&result) && result.pixmap().computeIsOpaque(); + SkPixmap pmap; + return bm.peekPixels(&pmap) && pmap.computeIsOpaque(); } /** @@ -419,10 +419,11 @@ public: */ void setPixelRef(sk_sp, int dx, int dy); +#ifdef SK_SUPPORT_OBSOLETE_LOCKPIXELS void lockPixels() const {} void unlockPixels() const {} - bool requestLock(SkAutoPixmapUnlock* result) const; +#endif /** Call this to be sure that the bitmap is valid enough to be drawn (i.e. it has non-null pixels, and if required by its colortype, it has a @@ -755,26 +756,12 @@ private: friend class SkBinaryWriteBuffer; // rawpixels }; +#ifdef SK_SUPPORT_OBSOLETE_LOCKPIXELS class SkAutoLockPixels : SkNoncopyable { public: - SkAutoLockPixels(const SkBitmap& bm, bool doLock = true) : fBitmap(bm) { - fDidLock = doLock; - if (doLock) { - bm.lockPixels(); - } - } - ~SkAutoLockPixels() { - if (fDidLock) { - fBitmap.unlockPixels(); - } - } - -private: - const SkBitmap& fBitmap; - bool fDidLock; + SkAutoLockPixels(const SkBitmap&, bool = true) {} }; -//TODO(mtklein): uncomment when 71713004 lands and Chromium's fixed. -//#define SkAutoLockPixels(...) SK_REQUIRE_LOCAL_VAR(SkAutoLockPixels) +#endif /////////////////////////////////////////////////////////////////////////////// diff --git a/include/core/SkImageEncoder.h b/include/core/SkImageEncoder.h index e4f746ab96..5cd5f4a60f 100644 --- a/include/core/SkImageEncoder.h +++ b/include/core/SkImageEncoder.h @@ -34,7 +34,6 @@ SK_API bool SkEncodeImage(SkWStream* dst, const SkPixmap& src, * The following helper function wraps SkEncodeImage(). */ inline bool SkEncodeImage(SkWStream* dst, const SkBitmap& src, SkEncodedImageFormat f, int q) { - SkAutoLockPixels autoLockPixels(src); SkPixmap pixmap; return src.peekPixels(&pixmap) && SkEncodeImage(dst, pixmap, f, q); } diff --git a/include/core/SkPixelRef.h b/include/core/SkPixelRef.h index 0e66f25d31..56e0caf7c8 100644 --- a/include/core/SkPixelRef.h +++ b/include/core/SkPixelRef.h @@ -32,22 +32,18 @@ class SkDiscardableMemory; */ class SK_API SkPixelRef : public SkRefCnt { public: - explicit SkPixelRef(const SkImageInfo&, void* addr, size_t rowBytes, - sk_sp = nullptr); - virtual ~SkPixelRef(); + SkPixelRef(const SkImageInfo&, void* addr, size_t rowBytes, sk_sp = nullptr); + ~SkPixelRef() override; const SkImageInfo& info() const { return fInfo; } - void* pixels() const { return fRec.fPixels; } - SkColorTable* colorTable() const { return fRec.fColorTable; } - size_t rowBytes() const { return fRec.fRowBytes; } + void* pixels() const { return fPixels; } + SkColorTable* colorTable() const { return fCTable.get(); } + size_t rowBytes() const { return fRowBytes; } - /** - * To access the actual pixels of a pixelref, it must be "locked". - * Calling lockPixels returns a LockRec struct (on success). - */ +#ifdef SK_SUPPORT_OBSOLETE_LOCKPIXELS struct LockRec { LockRec() : fPixels(NULL), fColorTable(NULL) {} @@ -72,6 +68,33 @@ public: */ bool lockPixels(LockRec* rec); + struct LockRequest { + SkISize fSize; + SkFilterQuality fQuality; + }; + + struct LockResult { + LockResult() : fPixels(NULL), fCTable(NULL) {} + + void (*fUnlockProc)(void* ctx); + void* fUnlockContext; + + const void* fPixels; + SkColorTable* fCTable; // should be NULL unless colortype is kIndex8 + size_t fRowBytes; + SkISize fSize; + + void unlock() { + if (fUnlockProc) { + fUnlockProc(fUnlockContext); + fUnlockProc = NULL; // can't unlock twice! + } + } + }; + + bool requestLock(const LockRequest&, LockResult*); +#endif + /** Returns a non-zero, unique value corresponding to the pixels in this pixelref. Each time the pixels are changed (and notifyPixelsChanged is @@ -116,32 +139,6 @@ public: */ void setImmutable(); - struct LockRequest { - SkISize fSize; - SkFilterQuality fQuality; - }; - - struct LockResult { - LockResult() : fPixels(NULL), fCTable(NULL) {} - - void (*fUnlockProc)(void* ctx); - void* fUnlockContext; - - const void* fPixels; - SkColorTable* fCTable; // should be NULL unless colortype is kIndex8 - size_t fRowBytes; - SkISize fSize; - - void unlock() { - if (fUnlockProc) { - fUnlockProc(fUnlockContext); - fUnlockProc = NULL; // can't unlock twice! - } - } - }; - - bool requestLock(const LockRequest&, LockResult*); - // Register a listener that may be called the next time our generation ID changes. // // We'll only call the listener if we're confident that we are the only SkPixelRef with this @@ -188,10 +185,9 @@ protected: private: // mostly const. fInfo.fAlpahType can be changed at runtime. const SkImageInfo fInfo; - sk_sp fCTable; // duplicated in LockRec, will unify later - - // LockRec is only valid if we're in a locked state (isLocked()) - LockRec fRec; + sk_sp fCTable; + void* fPixels; + size_t fRowBytes; // Bottom bit indicates the Gen ID is unique. bool genIDIsUnique() const { return SkToBool(fTaggedGenID.load() & 1); } @@ -212,9 +208,6 @@ private: kImmutable, // Once set to this state, it never leaves. } fMutability : 8; // easily fits inside a byte - // only ever set in constructor, const after that - bool fPreLocked; - void needsNewGenID(); void callGenIDChangeListeners(); @@ -222,7 +215,6 @@ private: void restoreMutability(); friend class SkSurface_Raster; // For the two methods above. - bool isPreLocked() const { return fPreLocked; } friend class SkImage_Raster; friend class SkSpecialImage_Raster; diff --git a/include/core/SkPixmap.h b/include/core/SkPixmap.h index 6cf948e601..d028124222 100644 --- a/include/core/SkPixmap.h +++ b/include/core/SkPixmap.h @@ -221,8 +221,7 @@ private: ///////////////////////////////////////////////////////////////////////////////////////////// -///////////////////////////////////////////////////////////////////////////////////////////// - +#ifdef SK_SUPPORT_OBSOLETE_LOCKPIXELS class SK_API SkAutoPixmapUnlock : ::SkNoncopyable { public: SkAutoPixmapUnlock() : fUnlockProc(NULL), fIsLocked(false) {} @@ -268,5 +267,6 @@ private: friend class SkBitmap; }; +#endif #endif diff --git a/samplecode/SampleApp.cpp b/samplecode/SampleApp.cpp index feace008fd..bdd1ef1673 100644 --- a/samplecode/SampleApp.cpp +++ b/samplecode/SampleApp.cpp @@ -1282,7 +1282,6 @@ void SampleWindow::showZoomer(SkCanvas* canvas) { else if (fMouseY < 0) fMouseY = 0; SkBitmap bitmap = capture_bitmap(canvas); - bitmap.lockPixels(); // Find the size of the zoomed in view, forced to be odd, so the examined pixel is in the middle. int zoomedWidth = (width >> 1) | 1; diff --git a/samplecode/SampleBlur.cpp b/samplecode/SampleBlur.cpp index c43dc9bd43..4c4082cea0 100644 --- a/samplecode/SampleBlur.cpp +++ b/samplecode/SampleBlur.cpp @@ -25,7 +25,6 @@ static SkBitmap make_bitmap() { kPremul_SkAlphaType), SkColorTable::Make(c, 256)); - bm.lockPixels(); const float cx = bm.width() * 0.5f; const float cy = bm.height() * 0.5f; for (int y = 0; y < bm.height(); y++) { @@ -43,7 +42,6 @@ static SkBitmap make_bitmap() { p[x] = id; } } - bm.unlockPixels(); return bm; } diff --git a/samplecode/SampleDither.cpp b/samplecode/SampleDither.cpp index a1b751b96f..76ebecc25f 100644 --- a/samplecode/SampleDither.cpp +++ b/samplecode/SampleDither.cpp @@ -73,8 +73,6 @@ static void make_bm(SkBitmap* bm) { } static void pre_dither(const SkBitmap& bm) { - SkAutoLockPixels alp(bm); - for (int y = 0; y < bm.height(); y++) { DITHER_4444_SCAN(y); diff --git a/samplecode/SampleDitherBitmap.cpp b/samplecode/SampleDitherBitmap.cpp index bdd3071c0b..e5f7369ae1 100644 --- a/samplecode/SampleDitherBitmap.cpp +++ b/samplecode/SampleDitherBitmap.cpp @@ -60,14 +60,12 @@ static SkBitmap make_bitmap() { bm.allocPixels(SkImageInfo::Make(256, 32, kIndex_8_SkColorType, kPremul_SkAlphaType), SkColorTable::Make(c, 256)); - bm.lockPixels(); for (int y = 0; y < bm.height(); y++) { uint8_t* p = bm.getAddr8(0, y); for (int x = 0; x < 256; x++) { p[x] = x; } } - bm.unlockPixels(); return bm; } @@ -95,7 +93,6 @@ protected: } static void setBitmapOpaque(SkBitmap* bm, bool isOpaque) { - SkAutoLockPixels alp(*bm); // needed for ctable bm->setAlphaType(isOpaque ? kOpaque_SkAlphaType : kPremul_SkAlphaType); } diff --git a/samplecode/SampleTextureDomain.cpp b/samplecode/SampleTextureDomain.cpp index e615235a57..9c7f3de7a3 100644 --- a/samplecode/SampleTextureDomain.cpp +++ b/samplecode/SampleTextureDomain.cpp @@ -21,7 +21,6 @@ static SkBitmap make_bitmap() { p[x] = ((x + y) & 1) ? SK_ColorWHITE : SK_ColorBLACK; } } - bm.unlockPixels(); return bm; } diff --git a/samplecode/SampleTinyBitmap.cpp b/samplecode/SampleTinyBitmap.cpp index 6b01d11d5a..2212cbec23 100644 --- a/samplecode/SampleTinyBitmap.cpp +++ b/samplecode/SampleTinyBitmap.cpp @@ -25,14 +25,12 @@ static SkBitmap make_bitmap() { kPremul_SkAlphaType), SkColorTable::Make(c, N)); - bm.lockPixels(); for (int y = 0; y < bm.height(); y++) { uint8_t* p = bm.getAddr8(0, y); for (int x = 0; x < bm.width(); x++) { p[x] = 0; } } - bm.unlockPixels(); return bm; } @@ -54,7 +52,6 @@ protected: } static void setBitmapOpaque(SkBitmap* bm, bool isOpaque) { - SkAutoLockPixels alp(*bm); // needed for ctable bm->setAlphaType(isOpaque ? kOpaque_SkAlphaType : kPremul_SkAlphaType); } diff --git a/samplecode/SampleUnpremul.cpp b/samplecode/SampleUnpremul.cpp index 558bf935f1..be42d23bbd 100644 --- a/samplecode/SampleUnpremul.cpp +++ b/samplecode/SampleUnpremul.cpp @@ -116,7 +116,6 @@ protected: canvas->translate(height * 2, height * 2); if (!fPremul) { // A premultiplied bitmap cannot currently be drawn. - SkAutoLockPixels alp(fBitmap); // Copy it to a bitmap which can be drawn, converting // to premultiplied: SkBitmap bm; diff --git a/samplecode/SampleVertices.cpp b/samplecode/SampleVertices.cpp index 9d3e6015ee..9c6eeb8b1b 100644 --- a/samplecode/SampleVertices.cpp +++ b/samplecode/SampleVertices.cpp @@ -30,11 +30,9 @@ static sk_sp make_shader0(SkIPoint* size) { SkPMColor color1 = SkPreMultiplyARGB(0x40, 0xff, 0x00, 0xff); bm.allocN32Pixels(size->fX, size->fY); bm.eraseColor(color0); - bm.lockPixels(); uint32_t* pixels = (uint32_t*) bm.getPixels(); pixels[0] = pixels[2] = color0; pixels[1] = pixels[3] = color1; - bm.unlockPixels(); return SkShader::MakeBitmapShader(bm, SkShader::kRepeat_TileMode, SkShader::kRepeat_TileMode); } diff --git a/src/core/SkBitmap.cpp b/src/core/SkBitmap.cpp index 5c6efd49bd..7e3b2c97b3 100644 --- a/src/core/SkBitmap.cpp +++ b/src/core/SkBitmap.cpp @@ -478,12 +478,12 @@ void SkBitmap::erase(SkColor c, const SkIRect& area) const { break; } - SkAutoPixmapUnlock result; - if (!this->requestLock(&result)) { + SkPixmap result; + if (!this->peekPixels(&result)) { return; } - if (result.pixmap().erase(c, area)) { + if (result.erase(c, area)) { this->notifyPixelsChanged(); } } @@ -566,11 +566,11 @@ bool SkBitmap::canCopyTo(SkColorType dstCT) const { bool SkBitmap::readPixels(const SkImageInfo& requestedDstInfo, void* dstPixels, size_t dstRB, int x, int y) const { - SkAutoPixmapUnlock src; - if (!this->requestLock(&src)) { + SkPixmap src; + if (!this->peekPixels(&src)) { return false; } - return src.pixmap().readPixels(requestedDstInfo, dstPixels, dstRB, x, y); + return src.readPixels(requestedDstInfo, dstPixels, dstRB, x, y); } bool SkBitmap::readPixels(const SkPixmap& dst, int srcX, int srcY) const { @@ -579,11 +579,6 @@ bool SkBitmap::readPixels(const SkPixmap& dst, int srcX, int srcY) const { bool SkBitmap::writePixels(const SkPixmap& src, int dstX, int dstY, SkTransferFunctionBehavior behavior) { - SkAutoPixmapUnlock dst; - if (!this->requestLock(&dst)) { - return false; - } - if (!SkImageInfoValidConversion(fInfo, src.info())) { return false; } @@ -605,11 +600,10 @@ bool SkBitmap::internalCopyTo(SkBitmap* dst, SkColorType dstColorType, Allocator return false; } - SkAutoPixmapUnlock srcUnlocker; - if (!this->requestLock(&srcUnlocker)) { + SkPixmap srcPM; + if (!this->peekPixels(&srcPM)) { return false; } - SkPixmap srcPM = srcUnlocker.pixmap(); // Various Android specific compatibility modes. // TODO: @@ -654,13 +648,11 @@ bool SkBitmap::internalCopyTo(SkBitmap* dst, SkColorType dstColorType, Allocator return false; } - SkAutoPixmapUnlock dstUnlocker; - if (!tmpDst.requestLock(&dstUnlocker)) { + SkPixmap dstPM; + if (!tmpDst.peekPixels(&dstPM)) { return false; } - SkPixmap dstPM = dstUnlocker.pixmap(); - // We can't do a sane conversion from F16 without a src color space. Guess sRGB in this case. if (kRGBA_F16_SkColorType == srcPM.colorType() && !dstPM.colorSpace()) { dstPM.setColorSpace(SkColorSpace::MakeSRGB()); @@ -721,15 +713,14 @@ static bool GetBitmapAlpha(const SkBitmap& src, uint8_t* SK_RESTRICT alpha, int SkASSERT(alpha != nullptr); SkASSERT(alphaRowBytes >= src.width()); - SkAutoPixmapUnlock apl; - if (!src.requestLock(&apl)) { + SkPixmap pmap; + if (!src.peekPixels(&pmap)) { for (int y = 0; y < src.height(); ++y) { memset(alpha, 0, src.width()); alpha += alphaRowBytes; } return false; } - const SkPixmap& pmap = apl.pixmap(); SkConvertPixels(SkImageInfo::MakeA8(pmap.width(), pmap.height()), alpha, alphaRowBytes, pmap.info(), pmap.addr(), pmap.rowBytes(), pmap.ctable(), SkTransferFunctionBehavior::kRespect); @@ -841,13 +832,13 @@ void SkBitmap::WriteRawPixels(SkWriteBuffer* buffer, const SkBitmap& bitmap) { return; } - SkAutoPixmapUnlock result; - if (!bitmap.requestLock(&result)) { + SkPixmap result; + if (!bitmap.peekPixels(&result)) { buffer->writeUInt(0); // instead of snugRB, signaling no pixels return; } - write_raw_pixels(buffer, result.pixmap()); + write_raw_pixels(buffer, result); } bool SkBitmap::ReadRawPixels(SkReadBuffer* buffer, SkBitmap* bitmap) { @@ -1003,6 +994,7 @@ void SkBitmap::toString(SkString* str) const { /////////////////////////////////////////////////////////////////////////////// +#ifdef SK_SUPPORT_OBSOLETE_LOCKPIXELS bool SkBitmap::requestLock(SkAutoPixmapUnlock* result) const { SkASSERT(result); @@ -1031,6 +1023,7 @@ bool SkBitmap::requestLock(SkAutoPixmapUnlock* result) const { } return false; } +#endif bool SkBitmap::peekPixels(SkPixmap* pmap) const { if (fPixels) { diff --git a/src/core/SkBitmapController.cpp b/src/core/SkBitmapController.cpp index c72693fe88..ba287b584a 100644 --- a/src/core/SkBitmapController.cpp +++ b/src/core/SkBitmapController.cpp @@ -116,7 +116,6 @@ bool SkDefaultBitmapControllerState::processHQRequest(const SkBitmapProvider& pr if (fCanShadeHQ) { fQuality = kHigh_SkFilterQuality; SkAssertResult(provider.asBitmap(&fResultBitmap)); - fResultBitmap.lockPixels(); return true; } @@ -129,15 +128,15 @@ bool SkDefaultBitmapControllerState::processHQRequest(const SkBitmapProvider& pr if (!provider.asBitmap(&orig)) { return false; } - SkAutoPixmapUnlock src; - if (!orig.requestLock(&src)) { + SkPixmap src; + if (!orig.peekPixels(&src)) { return false; } SkPixmap dst; SkBitmapCache::RecPtr rec; const SkImageInfo info = SkImageInfo::MakeN32(desc.fScaledWidth, desc.fScaledHeight, - src.pixmap().alphaType()); + src.alphaType()); if (provider.isVolatile()) { if (!fResultBitmap.tryAllocPixels(info)) { return false; @@ -151,7 +150,7 @@ bool SkDefaultBitmapControllerState::processHQRequest(const SkBitmapProvider& pr return false; } } - if (!SkBitmapScaler::Resize(dst, src.pixmap(), kHQ_RESIZE_METHOD)) { + if (!SkBitmapScaler::Resize(dst, src, kHQ_RESIZE_METHOD)) { return false; // we failed to create fScaledBitmap } if (rec) { @@ -241,8 +240,6 @@ SkDefaultBitmapControllerState::SkDefaultBitmapControllerState(const SkBitmapPro SkASSERT(fResultBitmap.getPixels()); } else { (void)provider.asBitmap(&fResultBitmap); - fResultBitmap.lockPixels(); - // lock may fail to give us pixels } SkASSERT(fCanShadeHQ || fQuality <= kLow_SkFilterQuality); diff --git a/src/core/SkBitmapDevice.cpp b/src/core/SkBitmapDevice.cpp index fd387acb90..09f25fb332 100644 --- a/src/core/SkBitmapDevice.cpp +++ b/src/core/SkBitmapDevice.cpp @@ -74,7 +74,6 @@ SkBitmapDevice::SkBitmapDevice(const SkBitmap& bitmap) , fRCStack(bitmap.width(), bitmap.height()) { SkASSERT(valid_for_bitmap_device(bitmap.info(), nullptr)); - fBitmap.lockPixels(); } SkBitmapDevice* SkBitmapDevice::Create(const SkImageInfo& info) { @@ -89,7 +88,6 @@ SkBitmapDevice::SkBitmapDevice(const SkBitmap& bitmap, const SkSurfaceProps& sur , fRCStack(bitmap.width(), bitmap.height()) { SkASSERT(valid_for_bitmap_device(bitmap.info(), nullptr)); - fBitmap.lockPixels(); } SkBitmapDevice* SkBitmapDevice::Create(const SkImageInfo& origInfo, @@ -134,7 +132,6 @@ void SkBitmapDevice::replaceBitmapBackendForRasterSurface(const SkBitmap& bm) { SkASSERT(bm.width() == fBitmap.width()); SkASSERT(bm.height() == fBitmap.height()); fBitmap = bm; // intent is to use bm's pixelRef (and rowbytes/config) - fBitmap.lockPixels(); this->privateResize(fBitmap.info().width(), fBitmap.info().height()); } diff --git a/src/core/SkBitmapScaler.cpp b/src/core/SkBitmapScaler.cpp index b4ade85a75..c803da7e8e 100644 --- a/src/core/SkBitmapScaler.cpp +++ b/src/core/SkBitmapScaler.cpp @@ -249,7 +249,6 @@ bool SkBitmapScaler::Resize(SkBitmap* resultPtr, const SkPixmap& source, ResizeM } *resultPtr = result; - resultPtr->lockPixels(); SkASSERT(resultPtr->getPixels()); return true; } diff --git a/src/core/SkBlurImageFilter.cpp b/src/core/SkBlurImageFilter.cpp index 5e7f2a53ce..320097bdd0 100644 --- a/src/core/SkBlurImageFilter.cpp +++ b/src/core/SkBlurImageFilter.cpp @@ -214,8 +214,6 @@ sk_sp SkBlurImageFilterImpl::onFilterImage(SkSpecialImage* sourc return nullptr; } - SkAutoLockPixels inputLock(inputBM), tmpLock(tmp), dstLock(dst); - offset->fX = dstBounds.fLeft; offset->fY = dstBounds.fTop; SkPMColor* t = tmp.getAddr32(0, 0); diff --git a/src/core/SkCanvas.cpp b/src/core/SkCanvas.cpp index 1b96f4934e..844de43b8a 100644 --- a/src/core/SkCanvas.cpp +++ b/src/core/SkCanvas.cpp @@ -841,9 +841,8 @@ bool SkCanvas::readPixels(SkBitmap* bitmap, int x, int y) { weAllocated = true; } - SkAutoPixmapUnlock unlocker; - if (bitmap->requestLock(&unlocker)) { - const SkPixmap& pm = unlocker.pixmap(); + SkPixmap pm; + if (bitmap->peekPixels(&pm)) { if (this->readPixels(pm.info(), pm.writable_addr(), pm.rowBytes(), x, y)) { return true; } @@ -894,9 +893,8 @@ bool SkCanvas::readPixels(const SkBitmap& bm, int x, int y) { } bool SkCanvas::writePixels(const SkBitmap& bitmap, int x, int y) { - SkAutoPixmapUnlock unlocker; - if (bitmap.requestLock(&unlocker)) { - const SkPixmap& pm = unlocker.pixmap(); + SkPixmap pm; + if (bitmap.peekPixels(&pm)) { return this->writePixels(pm.info(), pm.addr(), pm.rowBytes(), x, y); } return false; diff --git a/src/core/SkDraw.cpp b/src/core/SkDraw.cpp index 07129f62b3..1e6c900ca7 100644 --- a/src/core/SkDraw.cpp +++ b/src/core/SkDraw.cpp @@ -1170,11 +1170,10 @@ void SkDraw::drawBitmapAsMask(const SkBitmap& bitmap, const SkPaint& paint) cons int ix = SkScalarRoundToInt(fMatrix->getTranslateX()); int iy = SkScalarRoundToInt(fMatrix->getTranslateY()); - SkAutoPixmapUnlock result; - if (!bitmap.requestLock(&result)) { + SkPixmap pmap; + if (!bitmap.peekPixels(&pmap)) { return; } - const SkPixmap& pmap = result.pixmap(); SkMask mask; mask.fBounds.set(ix, iy, ix + pmap.width(), iy + pmap.height()); mask.fFormat = SkMask::kA8_Format; @@ -1290,11 +1289,10 @@ void SkDraw::drawBitmap(const SkBitmap& bitmap, const SkMatrix& prematrix, // It is safe to call lock pixels now, since we know the matrix is // (more or less) identity. // - SkAutoPixmapUnlock unlocker; - if (!bitmap.requestLock(&unlocker)) { + SkPixmap pmap; + if (!bitmap.peekPixels(&pmap)) { return; } - const SkPixmap& pmap = unlocker.pixmap(); int ix = SkScalarRoundToInt(matrix.getTranslateX()); int iy = SkScalarRoundToInt(matrix.getTranslateY()); if (clipHandlesSprite(*fRC, ix, iy, pmap)) { @@ -1348,11 +1346,10 @@ void SkDraw::drawSprite(const SkBitmap& bitmap, int x, int y, const SkPaint& ori SkPaint paint(origPaint); paint.setStyle(SkPaint::kFill_Style); - SkAutoPixmapUnlock unlocker; - if (!bitmap.requestLock(&unlocker)) { + SkPixmap pmap; + if (!bitmap.peekPixels(&pmap)) { return; } - const SkPixmap& pmap = unlocker.pixmap(); if (nullptr == paint.getColorFilter() && clipHandlesSprite(*fRC, x, y, pmap)) { // blitter will be owned by the allocator. diff --git a/src/core/SkImageCacherator.cpp b/src/core/SkImageCacherator.cpp index a31d31ff96..c755f5d4d2 100644 --- a/src/core/SkImageCacherator.cpp +++ b/src/core/SkImageCacherator.cpp @@ -241,7 +241,6 @@ bool SkImageCacherator::tryLockAsBitmap(SkBitmap* bitmap, const SkImage* client, } } else { *bitmap = tmpBitmap; - bitmap->lockPixels(); bitmap->pixelRef()->setImmutableWithID(uniqueID); } return true; diff --git a/src/core/SkMipMap.cpp b/src/core/SkMipMap.cpp index d15d2c96dd..b3766e5cc2 100644 --- a/src/core/SkMipMap.cpp +++ b/src/core/SkMipMap.cpp @@ -779,15 +779,10 @@ bool SkMipMap::extractLevel(const SkSize& scaleSize, Level* levelPtr) const { // SkMipMap* SkMipMap::Build(const SkBitmap& src, SkDestinationSurfaceColorMode colorMode, SkDiscardableFactoryProc fact) { - SkAutoPixmapUnlock srcUnlocker; - if (!src.requestLock(&srcUnlocker)) { + SkPixmap srcPixmap; + if (!src.peekPixels(&srcPixmap)) { return nullptr; } - const SkPixmap& srcPixmap = srcUnlocker.pixmap(); - // Try to catch where we might have returned nullptr for src crbug.com/492818 - if (nullptr == srcPixmap.addr()) { - sk_throw(); - } return Build(srcPixmap, colorMode, fact); } diff --git a/src/core/SkPixelRef.cpp b/src/core/SkPixelRef.cpp index 37a450d1fd..3bf20fa3f6 100644 --- a/src/core/SkPixelRef.cpp +++ b/src/core/SkPixelRef.cpp @@ -26,9 +26,6 @@ uint32_t SkNextID::ImageID() { /////////////////////////////////////////////////////////////////////////////// -// just need a > 0 value, so pick a funny one to aid in debugging -#define SKPIXELREF_PRELOCKED_LOCKCOUNT 123456789 - static SkImageInfo validate_info(const SkImageInfo& info) { SkAlphaType newAlphaType = info.alphaType(); SkAssertResult(SkColorTypeValidateAlphaType(info.colorType(), info.alphaType(), &newAlphaType)); @@ -54,6 +51,8 @@ SkPixelRef::SkPixelRef(const SkImageInfo& info, void* pixels, size_t rowBytes, sk_sp ctable) : fInfo(validate_info(info)) , fCTable(std::move(ctable)) + , fPixels(pixels) + , fRowBytes(rowBytes) #ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK , fStableID(SkNextID::ImageID()) #endif @@ -63,13 +62,9 @@ SkPixelRef::SkPixelRef(const SkImageInfo& info, void* pixels, size_t rowBytes, #ifdef SK_TRACE_PIXELREF_LIFETIME SkDebugf(" pixelref %d\n", sk_atomic_inc(&gInstCounter)); #endif - fRec.fPixels = pixels; - fRec.fRowBytes = rowBytes; - fRec.fColorTable = fCTable.get(); this->needsNewGenID(); fMutability = kMutable; - fPreLocked = true; fAddedToCache.store(false); } @@ -116,9 +111,15 @@ void SkPixelRef::cloneGenID(const SkPixelRef& that) { SkASSERT(!that. genIDIsUnique()); } +#ifdef SK_SUPPORT_OBSOLETE_LOCKPIXELS bool SkPixelRef::lockPixels(LockRec* rec) { - *rec = fRec; - return true; + if (fPixels) { + rec->fPixels = fPixels; + rec->fRowBytes = fRowBytes; + rec->fColorTable = fCTable.get(); + return true; + } + return false; } bool SkPixelRef::requestLock(const LockRequest& request, LockResult* result) { @@ -133,12 +134,13 @@ bool SkPixelRef::requestLock(const LockRequest& request, LockResult* result) { result->fUnlockProc = nullptr; result->fUnlockContext = nullptr; - result->fCTable = fRec.fColorTable; - result->fPixels = fRec.fPixels; - result->fRowBytes = fRec.fRowBytes; + result->fCTable = fCTable.get(); + result->fPixels = fPixels; + result->fRowBytes = fRowBytes; result->fSize.set(fInfo.width(), fInfo.height()); return true; } +#endif uint32_t SkPixelRef::getGenerationID() const { uint32_t id = fTaggedGenID.load(); diff --git a/src/core/SkPixmap.cpp b/src/core/SkPixmap.cpp index 7eac6c4ed5..4d482181a5 100644 --- a/src/core/SkPixmap.cpp +++ b/src/core/SkPixmap.cpp @@ -20,6 +20,7 @@ #include "SkSurface.h" #include "SkUtils.h" +#ifdef SK_SUPPORT_OBSOLETE_LOCKPIXELS void SkAutoPixmapUnlock::reset(const SkPixmap& pm, void (*unlock)(void*), void* ctx) { SkASSERT(pm.addr() != nullptr); @@ -29,6 +30,7 @@ void SkAutoPixmapUnlock::reset(const SkPixmap& pm, void (*unlock)(void*), void* fUnlockContext = ctx; fIsLocked = true; } +#endif ///////////////////////////////////////////////////////////////////////////////////////////////// diff --git a/src/core/SkSpecialImage.cpp b/src/core/SkSpecialImage.cpp index 0853432d79..a142576c2e 100644 --- a/src/core/SkSpecialImage.cpp +++ b/src/core/SkSpecialImage.cpp @@ -218,11 +218,6 @@ public: , fBitmap(bm) { SkASSERT(bm.pixelRef()); - - // We have to lock now, while bm is still in scope, since it may have come from our - // cache, which means we need to keep it locked until we (the special) are done, since - // we cannot re-generate the cache entry (if bm came from a generator). - fBitmap.lockPixels(); SkASSERT(fBitmap.getPixels()); } diff --git a/src/core/SkWriteBuffer.cpp b/src/core/SkWriteBuffer.cpp index 79422abcea..3322e8a8c8 100644 --- a/src/core/SkWriteBuffer.cpp +++ b/src/core/SkWriteBuffer.cpp @@ -154,9 +154,9 @@ void SkBinaryWriteBuffer::writeBitmap(const SkBitmap& bitmap) { this->writeBool(false); // see if the caller wants to manually encode - SkAutoPixmapUnlock result; - if (fPixelSerializer && bitmap.requestLock(&result)) { - sk_sp data(fPixelSerializer->encode(result.pixmap())); + SkPixmap result; + if (fPixelSerializer && bitmap.peekPixels(&result)) { + sk_sp data(fPixelSerializer->encode(result)); if (data) { // if we have to "encode" the bitmap, then we assume there is no // offset to share, since we are effectively creating a new pixelref diff --git a/src/effects/SkAlphaThresholdFilter.cpp b/src/effects/SkAlphaThresholdFilter.cpp index 35328d5227..b725257f59 100644 --- a/src/effects/SkAlphaThresholdFilter.cpp +++ b/src/effects/SkAlphaThresholdFilter.cpp @@ -198,8 +198,6 @@ sk_sp SkAlphaThresholdFilterImpl::onFilterImage(SkSpecialImage* return nullptr; } - SkAutoLockPixels inputLock(inputBM); - if (!inputBM.getPixels() || inputBM.width() <= 0 || inputBM.height() <= 0) { return nullptr; } @@ -218,8 +216,6 @@ sk_sp SkAlphaThresholdFilterImpl::onFilterImage(SkSpecialImage* return nullptr; } - SkAutoLockPixels dstLock(dst); - U8CPU innerThreshold = (U8CPU)(fInnerThreshold * 0xFF); U8CPU outerThreshold = (U8CPU)(fOuterThreshold * 0xFF); SkColor* dptr = dst.getAddr32(0, 0); diff --git a/src/effects/SkArithmeticImageFilter.cpp b/src/effects/SkArithmeticImageFilter.cpp index cf85cfafec..a80ce19c78 100644 --- a/src/effects/SkArithmeticImageFilter.cpp +++ b/src/effects/SkArithmeticImageFilter.cpp @@ -431,7 +431,6 @@ void ArithmeticImageFilterImpl::drawForeground(SkCanvas* canvas, SkSpecialImage* if (!img->getROPixels(&srcBM)) { return; } - srcBM.lockPixels(); if (!srcBM.peekPixels(&src)) { return; } diff --git a/src/effects/SkDisplacementMapEffect.cpp b/src/effects/SkDisplacementMapEffect.cpp index 06f16f0195..2c0d5f014f 100644 --- a/src/effects/SkDisplacementMapEffect.cpp +++ b/src/effects/SkDisplacementMapEffect.cpp @@ -388,7 +388,6 @@ sk_sp SkDisplacementMapEffect::onFilterImage(SkSpecialImage* sou return nullptr; } - SkAutoLockPixels colorLock(colorBM), displLock(displBM); if (!colorBM.getPixels() || !displBM.getPixels()) { return nullptr; } @@ -401,8 +400,6 @@ sk_sp SkDisplacementMapEffect::onFilterImage(SkSpecialImage* sou return nullptr; } - SkAutoLockPixels dstLock(dst); - computeDisplacement(fXChannelSelector, fYChannelSelector, scale, &dst, displBM, colorOffset - displOffset, colorBM, colorBounds); diff --git a/src/effects/SkLightingImageFilter.cpp b/src/effects/SkLightingImageFilter.cpp index 58c45ff0ae..5933cffd2a 100644 --- a/src/effects/SkLightingImageFilter.cpp +++ b/src/effects/SkLightingImageFilter.cpp @@ -1278,7 +1278,6 @@ sk_sp SkDiffuseLightingImageFilter::onFilterImage(SkSpecialImage return nullptr; } - SkAutoLockPixels alp(inputBM); if (!inputBM.getPixels()) { return nullptr; } @@ -1290,8 +1289,6 @@ sk_sp SkDiffuseLightingImageFilter::onFilterImage(SkSpecialImage return nullptr; } - SkAutoLockPixels dstLock(dst); - SkMatrix matrix(ctx.ctm()); matrix.postTranslate(SkIntToScalar(-inputOffset.x()), SkIntToScalar(-inputOffset.y())); @@ -1445,7 +1442,6 @@ sk_sp SkSpecularLightingImageFilter::onFilterImage(SkSpecialImag return nullptr; } - SkAutoLockPixels alp(inputBM); if (!inputBM.getPixels()) { return nullptr; } @@ -1457,8 +1453,6 @@ sk_sp SkSpecularLightingImageFilter::onFilterImage(SkSpecialImag return nullptr; } - SkAutoLockPixels dstLock(dst); - SpecularLightingType lightingType(fKS, fShininess); SkMatrix matrix(ctx.ctm()); diff --git a/src/effects/SkMagnifierImageFilter.cpp b/src/effects/SkMagnifierImageFilter.cpp index 9be3438502..8552c8113e 100644 --- a/src/effects/SkMagnifierImageFilter.cpp +++ b/src/effects/SkMagnifierImageFilter.cpp @@ -389,7 +389,6 @@ sk_sp SkMagnifierImageFilter::onFilterImage(SkSpecialImage* sour return nullptr; } - SkAutoLockPixels alp(inputBM); SkASSERT(inputBM.getPixels()); if (!inputBM.getPixels() || inputBM.width() <= 0 || inputBM.height() <= 0) { return nullptr; @@ -402,8 +401,6 @@ sk_sp SkMagnifierImageFilter::onFilterImage(SkSpecialImage* sour return nullptr; } - SkAutoLockPixels dstLock(dst); - SkColor* dptr = dst.getAddr32(0, 0); int dstWidth = dst.width(), dstHeight = dst.height(); for (int y = 0; y < dstHeight; ++y) { diff --git a/src/effects/SkMatrixConvolutionImageFilter.cpp b/src/effects/SkMatrixConvolutionImageFilter.cpp index 092cb661bd..6644ef8045 100644 --- a/src/effects/SkMatrixConvolutionImageFilter.cpp +++ b/src/effects/SkMatrixConvolutionImageFilter.cpp @@ -244,9 +244,7 @@ void SkMatrixConvolutionImageFilter::filterBorderPixels(const SkBitmap& src, // FIXME: This should be refactored to SkImageFilterUtils for // use by other filters. For now, we assume the input is always // premultiplied and unpremultiply it -static SkBitmap unpremultiply_bitmap(const SkBitmap& src) -{ - SkAutoLockPixels alp(src); +static SkBitmap unpremultiply_bitmap(const SkBitmap& src) { if (!src.getPixels()) { return SkBitmap(); } @@ -256,7 +254,6 @@ static SkBitmap unpremultiply_bitmap(const SkBitmap& src) if (!result.tryAllocPixels(info)) { return SkBitmap(); } - SkAutoLockPixels resultLock(result); for (int y = 0; y < src.height(); ++y) { const uint32_t* srcRow = src.getAddr32(0, y); uint32_t* dstRow = result.getAddr32(0, y); @@ -350,7 +347,6 @@ sk_sp SkMatrixConvolutionImageFilter::onFilterImage(SkSpecialIma inputBM = unpremultiply_bitmap(inputBM); } - SkAutoLockPixels alp(inputBM); if (!inputBM.getPixels()) { return nullptr; } @@ -363,8 +359,6 @@ sk_sp SkMatrixConvolutionImageFilter::onFilterImage(SkSpecialIma return nullptr; } - SkAutoLockPixels dstLock(dst); - offset->fX = bounds.fLeft; offset->fY = bounds.fTop; bounds.offset(-inputOffset); diff --git a/src/effects/SkMorphologyImageFilter.cpp b/src/effects/SkMorphologyImageFilter.cpp index d7454a4688..d11b4da60e 100644 --- a/src/effects/SkMorphologyImageFilter.cpp +++ b/src/effects/SkMorphologyImageFilter.cpp @@ -621,8 +621,6 @@ sk_sp SkMorphologyImageFilter::onFilterImage(SkSpecialImage* sou return nullptr; } - SkAutoLockPixels inputLock(inputBM), dstLock(dst); - SkMorphologyImageFilter::Proc procX, procY; if (kDilate_Op == this->op()) { @@ -639,8 +637,6 @@ sk_sp SkMorphologyImageFilter::onFilterImage(SkSpecialImage* sou return nullptr; } - SkAutoLockPixels tmpLock(tmp); - call_proc_X(procX, inputBM, &tmp, width, srcBounds); SkIRect tmpBounds = SkIRect::MakeWH(srcBounds.width(), srcBounds.height()); call_proc_Y(procY, diff --git a/src/effects/SkTableColorFilter.cpp b/src/effects/SkTableColorFilter.cpp index 0667f51b75..0253e60b59 100644 --- a/src/effects/SkTableColorFilter.cpp +++ b/src/effects/SkTableColorFilter.cpp @@ -321,7 +321,6 @@ sk_sp SkTable_ColorFilter::makeComposed(sk_sp inne return nullptr; } - innerBM.lockPixels(); if (nullptr == innerBM.getPixels()) { return nullptr; } diff --git a/src/effects/gradients/SkGradientShader.cpp b/src/effects/gradients/SkGradientShader.cpp index 730cfbfa4f..276eaac8ed 100644 --- a/src/effects/gradients/SkGradientShader.cpp +++ b/src/effects/gradients/SkGradientShader.cpp @@ -607,7 +607,6 @@ void SkGradientShaderBase::GradientShaderCache::initCache32(GradientShaderCache* void SkGradientShaderBase::initLinearBitmap(SkBitmap* bitmap) const { const bool interpInPremul = SkToBool(fGradFlags & SkGradientShader::kInterpolateColorsInPremul_Flag); - bitmap->lockPixels(); SkHalf* pixelsF16 = reinterpret_cast(bitmap->getPixels()); uint32_t* pixelsS32 = reinterpret_cast(bitmap->getPixels()); @@ -657,7 +656,6 @@ void SkGradientShaderBase::initLinearBitmap(SkBitmap* bitmap) const { prevIndex = nextIndex; } SkASSERT(prevIndex == kCache32Count - 1); - bitmap->unlockPixels(); } /* diff --git a/src/gpu/SkGpuDevice.cpp b/src/gpu/SkGpuDevice.cpp index 11ed637250..7046f1cefe 100644 --- a/src/gpu/SkGpuDevice.cpp +++ b/src/gpu/SkGpuDevice.cpp @@ -957,12 +957,6 @@ void SkGpuDevice::drawTiledBitmap(const SkBitmap& bitmap, SK_HISTOGRAM_BOOLEAN("DrawTiled", true); LogDrawScaleFactor(viewMatrix, origPaint.getFilterQuality()); - // The following pixel lock is technically redundant, but it is desirable - // to lock outside of the tile loop to prevent redecoding the whole image - // at each tile in cases where 'bitmap' holds an SkDiscardablePixelRef that - // is larger than the limit of the discardable memory pool. - SkAutoLockPixels alp(bitmap); - const SkPaint* paint = &origPaint; SkPaint tempPaint; if (origPaint.isAntiAlias() && !fRenderTargetContext->isUnifiedMultisampled()) { diff --git a/src/gpu/SkGr.cpp b/src/gpu/SkGr.cpp index 84be09e357..e4b31558ae 100644 --- a/src/gpu/SkGr.cpp +++ b/src/gpu/SkGr.cpp @@ -93,7 +93,6 @@ GrPixelConfig GrIsCompressedTextureDataSupported(GrContext* ctx, SkData* data, ////////////////////////////////////////////////////////////////////////////// sk_sp GrUploadBitmapToTextureProxy(GrResourceProvider* resourceProvider, const SkBitmap& bitmap) { - SkAutoLockPixels alp(bitmap); if (!bitmap.readyToDraw()) { return nullptr; } @@ -212,15 +211,10 @@ sk_sp GrGenerateMipMapsAndUploadToTextureProxy(GrContext* ctx, GrSurfaceDesc desc = GrImageInfoToSurfaceDesc(bitmap.info(), *ctx->caps()); - SkAutoPixmapUnlock srcUnlocker; - if (!bitmap.requestLock(&srcUnlocker)) { + SkPixmap pixmap; + if (!bitmap.peekPixels(&pixmap)) { return nullptr; } - const SkPixmap& pixmap = srcUnlocker.pixmap(); - // Try to catch where we might have returned nullptr for src crbug.com/492818 - if (nullptr == pixmap.addr()) { - sk_throw(); - } std::unique_ptr mipmaps(SkMipMap::Build(pixmap, colorMode, nullptr)); if (!mipmaps) { diff --git a/src/gpu/effects/GrTextureStripAtlas.cpp b/src/gpu/effects/GrTextureStripAtlas.cpp index 26ef5963c1..72817b2133 100644 --- a/src/gpu/effects/GrTextureStripAtlas.cpp +++ b/src/gpu/effects/GrTextureStripAtlas.cpp @@ -153,8 +153,6 @@ int GrTextureStripAtlas::lockRow(const SkBitmap& bitmap) { fKeyTable.insert(index, 1, &row); rowNumber = static_cast(row - fRows); - SkAutoLockPixels lock(bitmap); - SkASSERT(bitmap.width() == fDesc.fWidth); SkASSERT(bitmap.height() == fDesc.fRowHeight); diff --git a/src/image/SkImage.cpp b/src/image/SkImage.cpp index 0847eb1c57..bbe1754c08 100644 --- a/src/image/SkImage.cpp +++ b/src/image/SkImage.cpp @@ -67,7 +67,6 @@ bool SkImage::scalePixels(const SkPixmap& dst, SkFilterQuality quality, CachingH // SkBitmap bm; if (as_IB(this)->getROPixels(&bm, dst.info().colorSpace(), chint)) { - bm.lockPixels(); SkPixmap pmap; // Note: By calling the pixmap scaler, we never cache the final result, so the chint // is (currently) only being applied to the getROPixels. If we get a request to @@ -115,15 +114,14 @@ SkData* SkImage::encode(SkPixelSerializer* serializer) const { } SkBitmap bm; - SkAutoPixmapUnlock apu; + SkPixmap pmap; SkColorSpace* legacyColorSpace = nullptr; - if (as_IB(this)->getROPixels(&bm, legacyColorSpace) && - bm.requestLock(&apu)) { + if (as_IB(this)->getROPixels(&bm, legacyColorSpace) && bm.peekPixels(&pmap)) { if (serializer) { - return serializer->encode(apu.pixmap()); + return serializer->encode(pmap); } else { SkDynamicMemoryWStream buf; - return SkEncodeImage(&buf, apu.pixmap(), SkEncodedImageFormat::kPNG, 100) + return SkEncodeImage(&buf, pmap, SkEncodedImageFormat::kPNG, 100) ? buf.detachAsData().release() : nullptr; } } diff --git a/src/image/SkImage_Raster.cpp b/src/image/SkImage_Raster.cpp index 1aca5a9c52..91de4c5b0b 100644 --- a/src/image/SkImage_Raster.cpp +++ b/src/image/SkImage_Raster.cpp @@ -109,11 +109,6 @@ public: : (uint32_t)kNeedNewImageUniqueID) , fBitmap(bm) { - if (bm.pixelRef()->isPreLocked()) { - // we only preemptively lock if there is no chance of triggering something expensive - // like a lazy decode or imagegenerator. PreLocked means it is flat pixels already. - fBitmap.lockPixels(); - } SkASSERT(bitmapMayBeMutable || fBitmap.isImmutable()); } @@ -152,7 +147,6 @@ SkImage_Raster::SkImage_Raster(const Info& info, sk_sp data, size_t rowB fBitmap.installPixels(info, addr, rowBytes, ctable, release_data, data.release()); fBitmap.setImmutable(); - fBitmap.lockPixels(); } SkImage_Raster::~SkImage_Raster() { @@ -307,7 +301,6 @@ sk_sp SkImage::MakeFromRaster(const SkPixmap& pmap, RasterReleaseProc p sk_sp SkMakeImageFromRasterBitmap(const SkBitmap& bm, SkCopyPixelsMode cpm) { bool hasColorTable = false; if (kIndex_8_SkColorType == bm.colorType()) { - SkAutoLockPixels autoLockPixels(bm); hasColorTable = bm.getColorTable() != nullptr; } @@ -316,10 +309,8 @@ sk_sp SkMakeImageFromRasterBitmap(const SkBitmap& bm, SkCopyPixelsMode } if (kAlways_SkCopyPixelsMode == cpm || (!bm.isImmutable() && kNever_SkCopyPixelsMode != cpm)) { - SkBitmap tmp(bm); - tmp.lockPixels(); SkPixmap pmap; - if (tmp.getPixels() && tmp.peekPixels(&pmap)) { + if (bm.getPixels() && bm.peekPixels(&pmap)) { return SkImage::MakeRasterCopy(pmap); } } else { @@ -405,7 +396,6 @@ sk_sp SkImage_Raster::onMakeColorSpace(sk_sp target) cons SkTLazy tmp; if (!fBitmap.peekPixels(&src)) { tmp.init(fBitmap); - tmp.get()->lockPixels(); SkAssertResult(tmp.get()->peekPixels(&src)); } diff --git a/src/image/SkSurface_Raster.cpp b/src/image/SkSurface_Raster.cpp index 92f5301061..2de1ed70d3 100644 --- a/src/image/SkSurface_Raster.cpp +++ b/src/image/SkSurface_Raster.cpp @@ -165,7 +165,6 @@ void SkSurface_Raster::onCopyOnWrite(ContentChangeMode mode) { } else { SkBitmap prev(fBitmap); fBitmap.allocPixels(); - prev.lockPixels(); SkASSERT(prev.info() == fBitmap.info()); SkASSERT(prev.rowBytes() == fBitmap.rowBytes()); memcpy(fBitmap.getPixels(), prev.getPixels(), fBitmap.getSafeSize()); diff --git a/src/pdf/SkPDFBitmap.cpp b/src/pdf/SkPDFBitmap.cpp index 511fca8370..19460a44f0 100644 --- a/src/pdf/SkPDFBitmap.cpp +++ b/src/pdf/SkPDFBitmap.cpp @@ -23,8 +23,6 @@ void image_get_ro_pixels(const SkImage* image, SkBitmap* dst) { if (dst->colorType() != kIndex_8_SkColorType) { return; } - // We must check to see if the bitmap has a color table. - SkAutoLockPixels autoLockPixels(*dst); if (!dst->getColorTable()) { // We can't use an indexed bitmap with no colortable. dst->reset(); @@ -181,7 +179,6 @@ static void bitmap_to_pdf_pixels(const SkBitmap& bitmap, SkWStream* out) { } SkBitmap copy; const SkBitmap& bm = not4444(bitmap, ©); - SkAutoLockPixels autoLockPixels(bm); SkColorType colorType = bm.colorType(); SkAlphaType alphaType = bm.alphaType(); switch (colorType) { @@ -257,7 +254,6 @@ static void bitmap_alpha_to_a8(const SkBitmap& bitmap, SkWStream* out) { } SkBitmap copy; const SkBitmap& bm = not4444(bitmap, ©); - SkAutoLockPixels autoLockPixels(bm); SkColorType colorType = bm.colorType(); switch (colorType) { case kRGBA_8888_SkColorType: @@ -350,7 +346,6 @@ static void emit_image_xobject(SkWStream* stream, const SkPDFObjNumMap& objNumMap) { SkBitmap bitmap; image_get_ro_pixels(image, &bitmap); // TODO(halcanary): test - SkAutoLockPixels autoLockPixels(bitmap); // with malformed images. // Write to a temporary buffer to get the compressed length. SkDynamicMemoryWStream buffer; @@ -502,11 +497,10 @@ sk_sp SkPDFCreateBitmapObject(sk_sp image, if (pixelSerializer) { SkBitmap bm; - SkAutoPixmapUnlock apu; + SkPixmap pmap; SkColorSpace* legacyColorSpace = nullptr; - if (as_IB(image.get())->getROPixels(&bm, legacyColorSpace) && - bm.requestLock(&apu)) { - data.reset(pixelSerializer->encode(apu.pixmap())); + if (as_IB(image.get())->getROPixels(&bm, legacyColorSpace) && bm.peekPixels(&pmap)) { + data.reset(pixelSerializer->encode(pmap)); if (data && SkIsJFIF(data.get(), &info)) { bool yuv = info.fType == SkJFIFInfo::kYCbCr; if (info.fSize == image->dimensions()) { // Sanity check. diff --git a/src/pdf/SkPDFDevice.cpp b/src/pdf/SkPDFDevice.cpp index 992508db24..358ba1638f 100644 --- a/src/pdf/SkPDFDevice.cpp +++ b/src/pdf/SkPDFDevice.cpp @@ -104,12 +104,10 @@ static SkPaint calculate_text_paint(const SkPaint& paint) { static SkImageSubset make_image_subset(const SkBitmap& bitmap) { SkASSERT(!bitmap.drawsNothing()); SkIRect subset = bitmap.getSubset(); - SkAutoLockPixels autoLockPixels(bitmap); SkASSERT(bitmap.pixelRef()); SkBitmap tmp; tmp.setInfo(bitmap.pixelRef()->info(), bitmap.rowBytes()); tmp.setPixelRef(sk_ref_sp(bitmap.pixelRef()), 0, 0); - tmp.lockPixels(); auto img = SkImage::MakeFromBitmap(tmp); if (img) { SkASSERT(!bitmap.isImmutable() || img->uniqueID() == bitmap.getGenerationID()); diff --git a/src/pdf/SkPDFShader.cpp b/src/pdf/SkPDFShader.cpp index 6a511855b9..13a9ecd1d5 100644 --- a/src/pdf/SkPDFShader.cpp +++ b/src/pdf/SkPDFShader.cpp @@ -962,7 +962,6 @@ static sk_sp make_image_shader(SkPDFDocument* doc, SkBitmap image) { SkASSERT(state.fBitmapKey == (SkBitmapKey{image.getSubset(), image.getGenerationID()})); - SkAutoLockPixels SkAutoLockPixels(image); // The image shader pattern cell will be drawn into a separate device // in pattern cell space (no scaling on the bitmap, though there may be diff --git a/src/utils/mac/SkCreateCGImageRef.cpp b/src/utils/mac/SkCreateCGImageRef.cpp index e3735920a1..880c566c73 100644 --- a/src/utils/mac/SkCreateCGImageRef.cpp +++ b/src/utils/mac/SkCreateCGImageRef.cpp @@ -134,9 +134,6 @@ CGImageRef SkCreateCGImageRefWithColorspace(const SkBitmap& bm, const size_t s = bitmap->getSize(); // our provider "owns" the bitmap*, and will take care of deleting it - // we initially lock it, so we can access the pixels. The bitmap will be deleted in the release - // proc, which will in turn unlock the pixels - bitmap->lockPixels(); CGDataProviderRef dataRef = CGDataProviderCreateWithData(bitmap, bitmap->getPixels(), s, SkBitmap_ReleaseInfo); diff --git a/src/views/win/SkOSWindow_win.cpp b/src/views/win/SkOSWindow_win.cpp index 983b253c53..8be15d1d20 100644 --- a/src/views/win/SkOSWindow_win.cpp +++ b/src/views/win/SkOSWindow_win.cpp @@ -207,7 +207,6 @@ void SkOSWindow::doPaint(void* ctx) { // seems to be to copy the bitmap to a temporary (contiguous) // buffer before passing to SetDIBitsToDevice(). SkASSERT(bitmap.width() * bitmap.bytesPerPixel() == bitmap.rowBytes()); - bitmap.lockPixels(); int ret = SetDIBitsToDevice(hdc, 0, 0, bitmap.width(), bitmap.height(), @@ -217,7 +216,6 @@ void SkOSWindow::doPaint(void* ctx) { &bmi, DIB_RGB_COLORS); (void)ret; // we're ignoring potential failures for now. - bitmap.unlockPixels(); } } diff --git a/src/xps/SkXPSDevice.cpp b/src/xps/SkXPSDevice.cpp index 4a018a97fd..202259090e 100644 --- a/src/xps/SkXPSDevice.cpp +++ b/src/xps/SkXPSDevice.cpp @@ -749,8 +749,6 @@ HRESULT SkXPSDevice::createXpsImageBrush( if (SkShader::kClamp_TileMode == xy[0] && SkShader::kClamp_TileMode == xy[1]) { - SkAutoLockPixels alp(bitmap); - const SkColor tlColor = bitmap.getColor(0,0); const SkRect tlArea = SkRect::MakeLTRB(-BIG, -BIG, 0, 0); HR(this->cornerOfClamp(tlArea, tlColor, brushVisuals.get())); diff --git a/tests/BitmapCopyTest.cpp b/tests/BitmapCopyTest.cpp index d2fda9e0b7..aadf192285 100644 --- a/tests/BitmapCopyTest.cpp +++ b/tests/BitmapCopyTest.cpp @@ -11,7 +11,6 @@ #include "Test.h" static void init_src(const SkBitmap& bitmap) { - SkAutoLockPixels lock(bitmap); if (bitmap.getPixels()) { if (bitmap.getColorTable()) { sk_bzero(bitmap.getPixels(), bitmap.getSize()); @@ -130,8 +129,6 @@ DEF_TEST(BitmapCopy_extractSubset, reporter) { REPORTER_ASSERT(reporter, copy.height() == 2); if (gPairs[i].fColorType == gPairs[j].fColorType) { - SkAutoLockPixels alp0(subset); - SkAutoLockPixels alp1(copy); // they should both have, or both not-have, a colortable bool hasCT = subset.getColorTable() != nullptr; REPORTER_ASSERT(reporter, (copy.getColorTable() != nullptr) == hasCT); diff --git a/tests/BitmapTest.cpp b/tests/BitmapTest.cpp index 76621e6b38..0d4b785231 100644 --- a/tests/BitmapTest.cpp +++ b/tests/BitmapTest.cpp @@ -141,8 +141,6 @@ DEF_TEST(Bitmap_getColor_Swizzle, r) { ERRORF(r, "SkBitmap::copy failed %d", (int)ct); continue; } - SkAutoLockPixels autoLockPixels1(copy); - SkAutoLockPixels autoLockPixels2(source); REPORTER_ASSERT(r, source.getColor(0, 0) == copy.getColor(0, 0)); } } diff --git a/tests/BlendTest.cpp b/tests/BlendTest.cpp index 8f688e2d69..0acbd07957 100644 --- a/tests/BlendTest.cpp +++ b/tests/BlendTest.cpp @@ -187,7 +187,6 @@ DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(ES2BlendWithNoTexture, reporter, ctxInfo) SkBitmap bitmap; REPORTER_ASSERT(reporter, bitmap.tryAllocPixels(SkImageInfo::Make( kWidth, kHeight, kColorType, kPremul_SkAlphaType))); - bitmap.lockPixels(); REPORTER_ASSERT( reporter, surface->readPixels(bitmap.info(), bitmap.getPixels(), bitmap.rowBytes(), 0, 0)); @@ -199,7 +198,6 @@ DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(ES2BlendWithNoTexture, reporter, ctxInfo) SkColorSetRGB(0x80, 0xFF, 0x80)); // Clean up - surface depends on backingSurface and must be released first. - bitmap.unlockPixels(); surface.reset(); backingSurface.reset(); } diff --git a/tests/BlurTest.cpp b/tests/BlurTest.cpp index 985917f1c0..5d957185bb 100644 --- a/tests/BlurTest.cpp +++ b/tests/BlurTest.cpp @@ -76,9 +76,6 @@ static bool compare(const SkBitmap& ref, const SkIRect& iref, const int xOff = itest.fLeft - iref.fLeft; const int yOff = itest.fTop - iref.fTop; - SkAutoLockPixels alpRef(ref); - SkAutoLockPixels alpTest(test); - for (int y = 0; y < test.height(); ++y) { for (int x = 0; x < test.width(); ++x) { SkColor testColor = test.getColor(x, y); @@ -244,7 +241,6 @@ static void readback(SkCanvas* canvas, int* result, int resultCount) { readback.allocN32Pixels(resultCount, 30); canvas->readPixels(readback, 0, 0); - readback.lockPixels(); SkPMColor* pixels = (SkPMColor*) readback.getAddr32(0, 15); for (int i = 0; i < resultCount; ++i) { diff --git a/tests/CodecPartialTest.cpp b/tests/CodecPartialTest.cpp index f5eea371d9..20cd1d11f0 100644 --- a/tests/CodecPartialTest.cpp +++ b/tests/CodecPartialTest.cpp @@ -277,10 +277,6 @@ DEF_TEST(Codec_partialAnim, r) { frameInfo = partialCodec->getFrameInfo(); REPORTER_ASSERT(r, frameInfo.size() == i + 1); REPORTER_ASSERT(r, frameInfo[i].fFullyReceived); - - // allocPixels locked the pixels for frame, but frames[i] was copied - // from another bitmap, and did not retain the locked status. - SkAutoLockPixels alp(frames[i]); compare_bitmaps(r, frames[i], frame); } } diff --git a/tests/CodecTest.cpp b/tests/CodecTest.cpp index 2c601fadb0..ceafa15cb1 100644 --- a/tests/CodecTest.cpp +++ b/tests/CodecTest.cpp @@ -38,7 +38,6 @@ #endif static void md5(const SkBitmap& bm, SkMD5::Digest* digest) { - SkAutoLockPixels autoLockPixels(bm); SkASSERT(bm.getPixels()); SkMD5 md5; size_t rowLen = bm.info().bytesPerPixel() * bm.width(); @@ -72,7 +71,6 @@ static void test_info(skiatest::Reporter* r, Codec* codec, const SkImageInfo& in SkCodec::Result expectedResult, const SkMD5::Digest* goodDigest) { SkBitmap bm; bm.allocPixels(info); - SkAutoLockPixels autoLockPixels(bm); SkCodec::Result result = codec->getPixels(info, bm.getPixels(), bm.rowBytes()); REPORTER_ASSERT(r, result == expectedResult); @@ -98,7 +96,6 @@ static void test_incremental_decode(skiatest::Reporter* r, SkCodec* codec, const const SkMD5::Digest& goodDigest) { SkBitmap bm; bm.allocPixels(info); - SkAutoLockPixels autoLockPixels(bm); REPORTER_ASSERT(r, SkCodec::kSuccess == codec->startIncrementalDecode(info, bm.getPixels(), bm.rowBytes())); @@ -157,7 +154,6 @@ static void test_codec(skiatest::Reporter* r, Codec* codec, SkBitmap& bm, const REPORTER_ASSERT(r, info.dimensions() == size); bm.allocPixels(info); - SkAutoLockPixels autoLockPixels(bm); SkCodec::Result result = codec->getPixels(info, bm.getPixels(), bm.rowBytes()); REPORTER_ASSERT(r, result == expectedResult); @@ -174,7 +170,6 @@ static void test_codec(skiatest::Reporter* r, Codec* codec, SkBitmap& bm, const // Decoding to 565 should succeed. SkBitmap bm565; bm565.allocPixels(info565); - SkAutoLockPixels alp(bm565); // This will allow comparison even if the image is incomplete. bm565.eraseColor(SK_ColorBLACK); @@ -199,7 +194,6 @@ static void test_codec(skiatest::Reporter* r, Codec* codec, SkBitmap& bm, const SkImageInfo grayInfo = codec->getInfo(); SkBitmap grayBm; grayBm.allocPixels(grayInfo); - SkAutoLockPixels alp(grayBm); grayBm.eraseColor(SK_ColorBLACK); @@ -442,7 +436,6 @@ static void check(skiatest::Reporter* r, SkCodecImageGenerator::MakeFromEncodedCodec(fullData)); SkBitmap bm; bm.allocPixels(info); - SkAutoLockPixels autoLockPixels(bm); REPORTER_ASSERT(r, gen->getPixels(info, bm.getPixels(), bm.rowBytes())); compare_to_good_digest(r, codecDigest, bm); diff --git a/tests/DrawBitmapRectTest.cpp b/tests/DrawBitmapRectTest.cpp index df410b2b00..991290142e 100644 --- a/tests/DrawBitmapRectTest.cpp +++ b/tests/DrawBitmapRectTest.cpp @@ -226,8 +226,6 @@ static void test_nan_antihair() { } static bool check_for_all_zeros(const SkBitmap& bm) { - SkAutoLockPixels alp(bm); - size_t count = bm.width() * bm.bytesPerPixel(); for (int y = 0; y < bm.height(); y++) { const uint8_t* ptr = reinterpret_cast(bm.getAddr(0, y)); diff --git a/tests/DrawTextTest.cpp b/tests/DrawTextTest.cpp index bf9bd39f8d..a98b36f321 100644 --- a/tests/DrawTextTest.cpp +++ b/tests/DrawTextTest.cpp @@ -37,9 +37,6 @@ static bool compare(const SkBitmap& ref, const SkIRect& iref, const int xOff = itest.fLeft - iref.fLeft; const int yOff = itest.fTop - iref.fTop; - SkAutoLockPixels alpRef(ref); - SkAutoLockPixels alpTest(test); - for (int y = 0; y < test.height(); ++y) { for (int x = 0; x < test.width(); ++x) { SkColor testColor = test.getColor(x, y); diff --git a/tests/FontHostStreamTest.cpp b/tests/FontHostStreamTest.cpp index 7c4cb67b00..2bb439b791 100644 --- a/tests/FontHostStreamTest.cpp +++ b/tests/FontHostStreamTest.cpp @@ -39,9 +39,6 @@ static bool compare(const SkBitmap& ref, const SkIRect& iref, const int xOff = itest.fLeft - iref.fLeft; const int yOff = itest.fTop - iref.fTop; - SkAutoLockPixels alpRef(ref); - SkAutoLockPixels alpTest(test); - for (int y = 0; y < test.height(); ++y) { for (int x = 0; x < test.width(); ++x) { SkColor testColor = test.getColor(x, y); diff --git a/tests/GradientTest.cpp b/tests/GradientTest.cpp index e46bfb46c6..ec2753dc96 100644 --- a/tests/GradientTest.cpp +++ b/tests/GradientTest.cpp @@ -149,7 +149,6 @@ static void TestConstantGradient(skiatest::Reporter*) { outBitmap.allocN32Pixels(10, 1); SkCanvas canvas(outBitmap); canvas.drawPaint(paint); - SkAutoLockPixels alp(outBitmap); for (int i = 0; i < 10; i++) { // The following is commented out because it currently fails // Related bug: https://code.google.com/p/skia/issues/detail?id=1098 diff --git a/tests/HighContrastFilterTest.cpp b/tests/HighContrastFilterTest.cpp index 35b0c9febd..26f1a7c1f4 100644 --- a/tests/HighContrastFilterTest.cpp +++ b/tests/HighContrastFilterTest.cpp @@ -33,8 +33,6 @@ DEF_TEST(HighContrastFilter_FilterImage, reporter) { paint.setColorFilter(SkHighContrastFilter::Make(config)); canvasFilter.drawRect(r, paint); - paintResult.lockPixels(); - filterResult.lockPixels(); for (int y = r.top(); y < r.bottom(); ++y) { for (int x = r.left(); x < r.right(); ++x) { SkColor paintColor = paintResult.getColor(x, y); @@ -44,8 +42,6 @@ DEF_TEST(HighContrastFilter_FilterImage, reporter) { paint.getColorFilter()->filterColor(paintColor)); } } - paintResult.unlockPixels(); - filterResult.unlockPixels(); } DEF_TEST(HighContrastFilter_SanityCheck, reporter) { diff --git a/tests/ImageFilterTest.cpp b/tests/ImageFilterTest.cpp index 79f34f7654..5d959d16dd 100644 --- a/tests/ImageFilterTest.cpp +++ b/tests/ImageFilterTest.cpp @@ -594,10 +594,6 @@ static void test_negative_blur_sigma(skiatest::Reporter* reporter, REPORTER_ASSERT(reporter, negativeResult1->getROPixels(&negativeResultBM1)); REPORTER_ASSERT(reporter, negativeResult2->getROPixels(&negativeResultBM2)); - SkAutoLockPixels lockP1(positiveResultBM1); - SkAutoLockPixels lockP2(positiveResultBM2); - SkAutoLockPixels lockN1(negativeResultBM1); - SkAutoLockPixels lockN2(negativeResultBM2); for (int y = 0; y < height; y++) { int diffs = memcmp(positiveResultBM1.getAddr32(0, y), negativeResultBM1.getAddr32(0, y), @@ -656,7 +652,6 @@ static void test_zero_blur_sigma(skiatest::Reporter* reporter, GrContext* contex REPORTER_ASSERT(reporter, result->getROPixels(&resultBM)); - SkAutoLockPixels lock(resultBM); for (int y = 0; y < resultBM.height(); y++) { for (int x = 0; x < resultBM.width(); x++) { bool diff = *resultBM.getAddr32(x, y) != SK_ColorGREEN; @@ -696,7 +691,6 @@ static void test_fail_affects_transparent_black(skiatest::Reporter* reporter, Gr if (result.get()) { SkBitmap resultBM; REPORTER_ASSERT(reporter, result->getROPixels(&resultBM)); - SkAutoLockPixels lock(resultBM); REPORTER_ASSERT(reporter, *resultBM.getAddr32(0, 0) == SK_ColorGREEN); } } @@ -1573,7 +1567,6 @@ static void test_composed_imagefilter_bounds(skiatest::Reporter* reporter, GrCon SkBitmap resultBM; REPORTER_ASSERT(reporter, result->getROPixels(&resultBM)); - SkAutoLockPixels lock(resultBM); REPORTER_ASSERT(reporter, resultBM.getColor(50, 50) == SK_ColorGREEN); } diff --git a/tests/ImageFrom565Bitmap.cpp b/tests/ImageFrom565Bitmap.cpp index fada9f0b62..53f65df269 100644 --- a/tests/ImageFrom565Bitmap.cpp +++ b/tests/ImageFrom565Bitmap.cpp @@ -14,7 +14,6 @@ DEF_TEST(ImageFrom565Bitmap, r) { SkBitmap bm; bm.allocPixels(SkImageInfo::Make( 5, 7, kRGB_565_SkColorType, kOpaque_SkAlphaType)); - SkAutoLockPixels autoLockPixels(bm); bm.eraseColor(SK_ColorBLACK); REPORTER_ASSERT(r, SkImage::MakeFromBitmap(bm) != nullptr); } diff --git a/tests/ImageNewShaderTest.cpp b/tests/ImageNewShaderTest.cpp index 37e1e301ee..fe01f04c94 100644 --- a/tests/ImageNewShaderTest.cpp +++ b/tests/ImageNewShaderTest.cpp @@ -17,9 +17,6 @@ #endif static void test_bitmap_equality(skiatest::Reporter* reporter, SkBitmap& bm1, SkBitmap& bm2) { - SkAutoLockPixels lockBm1(bm1); - SkAutoLockPixels lockBm2(bm2); - REPORTER_ASSERT(reporter, bm1.getSize() == bm2.getSize()); REPORTER_ASSERT(reporter, 0 == memcmp(bm1.getPixels(), bm2.getPixels(), bm1.getSize())); } @@ -90,7 +87,6 @@ static void run_shader_test(skiatest::Reporter* reporter, SkSurface* sourceSurfa // Test correctness { - SkAutoLockPixels lockBm(bmt); for (int y = 0; y < info.height(); y++) { REPORTER_ASSERT(reporter, 0xFFFF0000 == bmt.getColor(0, y)); diff --git a/tests/ImageTest.cpp b/tests/ImageTest.cpp index 22004a07c6..77017f3885 100644 --- a/tests/ImageTest.cpp +++ b/tests/ImageTest.cpp @@ -691,7 +691,6 @@ static void check_legacy_bitmap(skiatest::Reporter* reporter, const SkImage* ima REPORTER_ASSERT(reporter, bitmap.isImmutable()); } - SkAutoLockPixels alp(bitmap); REPORTER_ASSERT(reporter, bitmap.getPixels()); const SkImageInfo info = SkImageInfo::MakeN32(1, 1, bitmap.alphaType()); @@ -1065,7 +1064,6 @@ DEF_TEST(Image_makeColorSpace, r) { SkBitmap p3Bitmap; bool success = p3Image->asLegacyBitmap(&p3Bitmap, SkImage::kRO_LegacyBitmapMode); REPORTER_ASSERT(r, success); - p3Bitmap.lockPixels(); REPORTER_ASSERT(r, almost_equal(0x28, SkGetPackedR32(*p3Bitmap.getAddr32(0, 0)))); REPORTER_ASSERT(r, almost_equal(0x40, SkGetPackedG32(*p3Bitmap.getAddr32(0, 0)))); REPORTER_ASSERT(r, almost_equal(0x5E, SkGetPackedB32(*p3Bitmap.getAddr32(0, 0)))); @@ -1075,7 +1073,6 @@ DEF_TEST(Image_makeColorSpace, r) { SkBitmap adobeBitmap; success = adobeImage->asLegacyBitmap(&adobeBitmap, SkImage::kRO_LegacyBitmapMode); REPORTER_ASSERT(r, success); - adobeBitmap.lockPixels(); REPORTER_ASSERT(r, almost_equal(0x21, SkGetPackedR32(*adobeBitmap.getAddr32(0, 0)))); REPORTER_ASSERT(r, almost_equal(0x31, SkGetPackedG32(*adobeBitmap.getAddr32(0, 0)))); REPORTER_ASSERT(r, almost_equal(0x4C, SkGetPackedB32(*adobeBitmap.getAddr32(0, 0)))); @@ -1084,7 +1081,6 @@ DEF_TEST(Image_makeColorSpace, r) { p3Image = srgbImage->makeColorSpace(p3, SkTransferFunctionBehavior::kIgnore); success = p3Image->asLegacyBitmap(&p3Bitmap, SkImage::kRO_LegacyBitmapMode); REPORTER_ASSERT(r, success); - p3Bitmap.lockPixels(); REPORTER_ASSERT(r, almost_equal(0x8B, SkGetPackedR32(*p3Bitmap.getAddr32(0, 0)))); REPORTER_ASSERT(r, almost_equal(0x82, SkGetPackedG32(*p3Bitmap.getAddr32(0, 0)))); REPORTER_ASSERT(r, almost_equal(0x77, SkGetPackedB32(*p3Bitmap.getAddr32(0, 0)))); diff --git a/tests/ReadPixelsTest.cpp b/tests/ReadPixelsTest.cpp index 697d3ee99e..89706ac5c0 100644 --- a/tests/ReadPixelsTest.cpp +++ b/tests/ReadPixelsTest.cpp @@ -124,7 +124,6 @@ static void fill_src_canvas(SkCanvas* canvas) { } static void fill_dst_bmp_with_init_data(SkBitmap* bitmap) { - SkAutoLockPixels alp(*bitmap); int w = bitmap->width(); int h = bitmap->height(); intptr_t pixels = reinterpret_cast(bitmap->getPixels()); @@ -184,7 +183,6 @@ static bool check_read(skiatest::Reporter* reporter, if (!clippedSrcRect.intersect(srcRect)) { clippedSrcRect.setEmpty(); } - SkAutoLockPixels alp(bitmap); if (kAlpha_8_SkColorType == ct) { for (int by = 0; by < bh; ++by) { for (int bx = 0; bx < bw; ++bx) { @@ -440,11 +438,9 @@ static void test_readpixels_texture(skiatest::Reporter* reporter, if (gReadPixelsConfigs[c].fAlphaType == kUnpremul_SkAlphaType) { flags = GrContextPriv::kUnpremul_PixelOpsFlag; } - bmp.lockPixels(); bool success = sContext->readPixels(bmp.info(), bmp.getPixels(), bmp.rowBytes(), srcRect.fLeft, srcRect.fTop, flags); - bmp.unlockPixels(); check_read(reporter, bmp, srcRect.fLeft, srcRect.fTop, success, true, gReadPixelsConfigs[c].fColorType, gReadPixelsConfigs[c].fAlphaType); @@ -458,7 +454,6 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ReadPixels_Texture, reporter, ctxInfo) { GrContext* context = ctxInfo.grContext(); SkBitmap bmp = make_src_bitmap(); - bmp.lockPixels(); // On the GPU we will also try reading back from a non-renderable texture. for (auto origin : {kBottomLeft_GrSurfaceOrigin, kTopLeft_GrSurfaceOrigin}) { @@ -481,8 +476,6 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ReadPixels_Texture, reporter, ctxInfo) { test_readpixels_texture(reporter, std::move(sContext)); } } - - bmp.unlockPixels(); } #endif diff --git a/tests/SerializationTest.cpp b/tests/SerializationTest.cpp index 3de422b969..10aec539fa 100644 --- a/tests/SerializationTest.cpp +++ b/tests/SerializationTest.cpp @@ -318,8 +318,6 @@ static void compare_bitmaps(skiatest::Reporter* reporter, const SkBitmap& b1, const SkBitmap& b2) { REPORTER_ASSERT(reporter, b1.width() == b2.width()); REPORTER_ASSERT(reporter, b1.height() == b2.height()); - SkAutoLockPixels autoLockPixels1(b1); - SkAutoLockPixels autoLockPixels2(b2); if ((b1.width() != b2.width()) || (b1.height() != b2.height())) { diff --git a/tests/SurfaceTest.cpp b/tests/SurfaceTest.cpp index f620cff996..e236928da7 100644 --- a/tests/SurfaceTest.cpp +++ b/tests/SurfaceTest.cpp @@ -912,7 +912,6 @@ static void test_overdraw_surface(skiatest::Reporter* r, SkSurface* surface) { SkBitmap bitmap; image->asLegacyBitmap(&bitmap, SkImage::kRO_LegacyBitmapMode); - bitmap.lockPixels(); for (int y = 0; y < 10; y++) { for (int x = 0; x < 10; x++) { REPORTER_ASSERT(r, 1 == SkGetPackedA32(*bitmap.getAddr32(x, y))); diff --git a/tests/WritePixelsTest.cpp b/tests/WritePixelsTest.cpp index bf2e64efc1..f5cdddccd0 100644 --- a/tests/WritePixelsTest.cpp +++ b/tests/WritePixelsTest.cpp @@ -196,7 +196,6 @@ static bool check_write(skiatest::Reporter* reporter, SkCanvas* canvas, const Sk return false; } - SkAutoLockPixels alp(secretDevBitmap); canvasRowBytes = secretDevBitmap.rowBytes(); canvasPixels = static_cast(secretDevBitmap.getPixels()); @@ -279,7 +278,6 @@ static bool setup_bitmap(SkBitmap* bm, SkColorType ct, SkAlphaType at, int w, in if (!alloc_row_bytes(bm, info, rowBytes)) { return false; } - SkAutoLockPixels alp(*bm); for (int y = 0; y < h; ++y) { for (int x = 0; x < w; ++x) { *bm->getAddr32(x, y) = get_bitmap_color(x, y, w, ct, at); diff --git a/tools/debugger/SkDrawCommand.cpp b/tools/debugger/SkDrawCommand.cpp index 691a4f8012..e386f46f22 100644 --- a/tools/debugger/SkDrawCommand.cpp +++ b/tools/debugger/SkDrawCommand.cpp @@ -889,9 +889,7 @@ static sk_sp load_image(const Json::Value& jsonImage, UrlDataManager& u bool SkDrawCommand::flatten(const SkBitmap& bitmap, Json::Value* target, UrlDataManager& urlDataManager) { - bitmap.lockPixels(); sk_sp image(SkImage::MakeFromBitmap(bitmap)); - bitmap.unlockPixels(); (*target)[SKDEBUGCANVAS_ATTRIBUTE_COLOR] = Json::Value(color_type_name(bitmap.colorType())); (*target)[SKDEBUGCANVAS_ATTRIBUTE_ALPHA] = Json::Value(alpha_type_name(bitmap.alphaType())); bool success = flatten(*image, target, urlDataManager); diff --git a/tools/picture_utils.cpp b/tools/picture_utils.cpp index b0fd224a94..27e91ccdeb 100644 --- a/tools/picture_utils.cpp +++ b/tools/picture_utils.cpp @@ -26,7 +26,6 @@ namespace sk_tools { return; } - SkAutoLockPixels lock(bitmap); for (int y = 0; y < bitmap.height(); y++) { for (int x = 0; x < bitmap.width(); x++) { *bitmap.getAddr32(x, y) |= (SK_A32_MASK << SK_A32_SHIFT); @@ -87,7 +86,6 @@ namespace sk_tools { bitmap.colorSpace() == srgbColorSpace.get()) { // These are premul sRGB 8-bit pixels in SkPMColor order. // We want unpremul sRGB 8-bit pixels in RGBA order. We'll get there via floats. - bitmap.lockPixels(); auto px = (const uint32_t*)bitmap.getPixels(); if (!px) { return nullptr; @@ -105,7 +103,6 @@ namespace sk_tools { } else if (bitmap.colorType() == kRGBA_F16_SkColorType) { // These are premul linear half-float pixels in RGBA order. // We want unpremul sRGB 8-bit pixels in RGBA order. We'll get there via floats. - bitmap.lockPixels(); auto px = (const uint64_t*)bitmap.getPixels(); if (!px) { return nullptr; diff --git a/tools/sk_tool_utils.cpp b/tools/sk_tool_utils.cpp index f8236bfa45..9a4bb2ba8c 100644 --- a/tools/sk_tool_utils.cpp +++ b/tools/sk_tool_utils.cpp @@ -225,8 +225,6 @@ void set_portable_typeface(SkPaint* paint, const char* name, SkFontStyle style) void write_pixels(SkCanvas* canvas, const SkBitmap& bitmap, int x, int y, SkColorType colorType, SkAlphaType alphaType) { SkBitmap tmp(bitmap); - tmp.lockPixels(); - const SkImageInfo info = SkImageInfo::Make(tmp.width(), tmp.height(), colorType, alphaType); canvas->writePixels(info, tmp.getPixels(), tmp.rowBytes(), x, y); diff --git a/tools/skdiff/skdiff.cpp b/tools/skdiff/skdiff.cpp index ae6d72cd7a..c7ddf7dca5 100644 --- a/tools/skdiff/skdiff.cpp +++ b/tools/skdiff/skdiff.cpp @@ -163,8 +163,6 @@ void compute_diff(DiffRecord* dr, DiffMetricProc diffFunction, const int colorTh return; } - SkAutoLockPixels alpDiff(dr->fDifference.fBitmap); - SkAutoLockPixels alpWhite(dr->fWhite.fBitmap); int mismatchedPixels = 0; int totalMismatchA = 0; int totalMismatchR = 0; diff --git a/tools/skdiff/skdiff_utils.cpp b/tools/skdiff/skdiff_utils.cpp index f8eed908b7..05e1c50388 100644 --- a/tools/skdiff/skdiff_utils.cpp +++ b/tools/skdiff/skdiff_utils.cpp @@ -71,7 +71,6 @@ bool get_bitmap(sk_sp fileBits, DiffResource& resource, bool sizeOnly) { /** Thanks to PNG, we need to force all pixels 100% opaque. */ static void force_all_opaque(const SkBitmap& bitmap) { - SkAutoLockPixels lock(bitmap); for (int y = 0; y < bitmap.height(); y++) { for (int x = 0; x < bitmap.width(); x++) { *bitmap.getAddr32(x, y) |= (SK_A32_MASK << SK_A32_SHIFT); -- cgit v1.2.3