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);
static int kCheckSize = 16;
fCheckerboard.allocN32Pixels(kCheckerboardWidth, kCheckerboardHeight);
- SkAutoLockPixels lock(fCheckerboard);
for (int y = 0; y < kCheckerboardHeight; ++y) {
int even = (y / kCheckSize) % 2;
}
fAtlas.allocN32Pixels(kTotAtlasWidth, kTotAtlasHeight);
- SkAutoLockPixels lock(fAtlas);
for (int y = 0; y < kTotAtlasHeight; ++y) {
int colorY = y / (kAtlasCellHeight + kAtlasSpacer);
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);
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;
gDefinitelyThreadSafeWork.add([task,name,bitmap,data]{
std::unique_ptr<SkStreamAsset> 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;
canvas.drawBitmap(*bitmap, 0, 0, &paint);
*bitmap = uprighted;
- bitmap->lockPixels();
return "";
}
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;
SkASSERT(false);
return bm;
}
- SkAutoLockPixels autoLockPixels(bm);
uint8_t spectrum[256];
for (int y = 0; y < 256; ++y) {
spectrum[y] = y;
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);
p[x] = ((x + y) & 1) ? SK_ColorWHITE : SK_ColorBLACK;
}
}
- bm.unlockPixels();
return bm;
}
SkBitmap tmp;
GetResourceAsBitmap("yellow_rose.png", &tmp);
tmp.extractSubset(bitmap, SkIRect::MakeWH(256, 256));
- bitmap->lockPixels();
}
static void make_unpremul_256(SkBitmap* bitmap) {
#endif
static sk_sp<SkData> encode_data(SkEncodedImageFormat type, const SkBitmap& bitmap) {
- SkAutoLockPixels autoLockPixels(bitmap);
SkPixmap src;
if (!bitmap.peekPixels(&src)) {
return nullptr;
}
static sk_sp<SkData> encode_data(const SkBitmap& bitmap, SkEncodedImageFormat format) {
- SkAutoLockPixels autoLockPixels(bitmap);
SkPixmap src;
if (!bitmap.peekPixels(&src)) {
return nullptr;
class RasterGenerator : public SkImageGenerator {
public:
- RasterGenerator(const SkBitmap& bm) : SkImageGenerator(bm.info()), fBM(bm) {
- fBM.lockPixels();
- }
+ RasterGenerator(const SkBitmap& bm) : SkImageGenerator(bm.info()), fBM(bm)
+ {}
+
protected:
bool onGetPixels(const SkImageInfo& info, void* pixels, size_t rowBytes,
SkPMColor* ctable, int* ctableCount) override {
static void apply_gamma(const SkBitmap& bm) {
return; // below is our experiment for sRGB correction
- bm.lockPixels();
for (int y = 0; y < bm.height(); ++y) {
for (int x = 0; x < bm.width(); ++x) {
SkPMColor c = *bm.getAddr32(x, y);
SkScalar y = 4;
SkPixmap prevPM;
- baseBM.lockPixels();
baseBM.peekPixels(&prevPM);
SkDestinationSurfaceColorMode colorMode = SkDestinationSurfaceColorMode::kLegacy;
};
SkPixmap basePM;
- orig.lockPixels();
orig.peekPixels(&basePM);
for (auto method : methods) {
canvas->translate(orig.width()/2 + 8.0f, 0);
kPremul_SkAlphaType),
SkColorTable::Make(c, SK_ARRAY_COUNT(c)));
- bm.lockPixels();
*bm.getAddr8(0, 0) = 0;
- bm.unlockPixels();
return bm;
}
};
SkBitmap bg;
bg.allocN32Pixels(2, 2, true);
- SkAutoLockPixels bgAlp(bg);
memcpy(bg.getPixels(), kCheckData, sizeof(kCheckData));
SkMatrix lm;
"SK_IGNORE_GPU_DITHER",
"SK_SUPPORT_LEGACY_SHADER_ISABITMAP",
"SK_SUPPORT_LEGACY_EMBOSSMASKFILTER",
+ "SK_SUPPORT_OBSOLETE_LOCKPIXELS",
]
* "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();
}
/**
*/
void setPixelRef(sk_sp<SkPixelRef>, 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
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
///////////////////////////////////////////////////////////////////////////////
* 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);
}
*/
class SK_API SkPixelRef : public SkRefCnt {
public:
- explicit SkPixelRef(const SkImageInfo&, void* addr, size_t rowBytes,
- sk_sp<SkColorTable> = nullptr);
- virtual ~SkPixelRef();
+ SkPixelRef(const SkImageInfo&, void* addr, size_t rowBytes, sk_sp<SkColorTable> = 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) {}
*/
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
*/
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
private:
// mostly const. fInfo.fAlpahType can be changed at runtime.
const SkImageInfo fInfo;
- sk_sp<SkColorTable> fCTable; // duplicated in LockRec, will unify later
-
- // LockRec is only valid if we're in a locked state (isLocked())
- LockRec fRec;
+ sk_sp<SkColorTable> fCTable;
+ void* fPixels;
+ size_t fRowBytes;
// Bottom bit indicates the Gen ID is unique.
bool genIDIsUnique() const { return SkToBool(fTaggedGenID.load() & 1); }
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();
void restoreMutability();
friend class SkSurface_Raster; // For the two methods above.
- bool isPreLocked() const { return fPreLocked; }
friend class SkImage_Raster;
friend class SkSpecialImage_Raster;
/////////////////////////////////////////////////////////////////////////////////////////////
-/////////////////////////////////////////////////////////////////////////////////////////////
-
+#ifdef SK_SUPPORT_OBSOLETE_LOCKPIXELS
class SK_API SkAutoPixmapUnlock : ::SkNoncopyable {
public:
SkAutoPixmapUnlock() : fUnlockProc(NULL), fIsLocked(false) {}
friend class SkBitmap;
};
+#endif
#endif
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;
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++) {
p[x] = id;
}
}
- bm.unlockPixels();
return bm;
}
}
static void pre_dither(const SkBitmap& bm) {
- SkAutoLockPixels alp(bm);
-
for (int y = 0; y < bm.height(); y++) {
DITHER_4444_SCAN(y);
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;
}
}
static void setBitmapOpaque(SkBitmap* bm, bool isOpaque) {
- SkAutoLockPixels alp(*bm); // needed for ctable
bm->setAlphaType(isOpaque ? kOpaque_SkAlphaType : kPremul_SkAlphaType);
}
p[x] = ((x + y) & 1) ? SK_ColorWHITE : SK_ColorBLACK;
}
}
- bm.unlockPixels();
return bm;
}
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;
}
}
static void setBitmapOpaque(SkBitmap* bm, bool isOpaque) {
- SkAutoLockPixels alp(*bm); // needed for ctable
bm->setAlphaType(isOpaque ? kOpaque_SkAlphaType : kPremul_SkAlphaType);
}
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;
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);
}
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();
}
}
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 {
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;
}
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:
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());
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);
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) {
///////////////////////////////////////////////////////////////////////////////
+#ifdef SK_SUPPORT_OBSOLETE_LOCKPIXELS
bool SkBitmap::requestLock(SkAutoPixmapUnlock* result) const {
SkASSERT(result);
}
return false;
}
+#endif
bool SkBitmap::peekPixels(SkPixmap* pmap) const {
if (fPixels) {
if (fCanShadeHQ) {
fQuality = kHigh_SkFilterQuality;
SkAssertResult(provider.asBitmap(&fResultBitmap));
- fResultBitmap.lockPixels();
return true;
}
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;
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) {
SkASSERT(fResultBitmap.getPixels());
} else {
(void)provider.asBitmap(&fResultBitmap);
- fResultBitmap.lockPixels();
- // lock may fail to give us pixels
}
SkASSERT(fCanShadeHQ || fQuality <= kLow_SkFilterQuality);
, fRCStack(bitmap.width(), bitmap.height())
{
SkASSERT(valid_for_bitmap_device(bitmap.info(), nullptr));
- fBitmap.lockPixels();
}
SkBitmapDevice* SkBitmapDevice::Create(const SkImageInfo& info) {
, fRCStack(bitmap.width(), bitmap.height())
{
SkASSERT(valid_for_bitmap_device(bitmap.info(), nullptr));
- fBitmap.lockPixels();
}
SkBitmapDevice* SkBitmapDevice::Create(const SkImageInfo& origInfo,
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());
}
}
*resultPtr = result;
- resultPtr->lockPixels();
SkASSERT(resultPtr->getPixels());
return true;
}
return nullptr;
}
- SkAutoLockPixels inputLock(inputBM), tmpLock(tmp), dstLock(dst);
-
offset->fX = dstBounds.fLeft;
offset->fY = dstBounds.fTop;
SkPMColor* t = tmp.getAddr32(0, 0);
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;
}
}
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;
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;
// 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)) {
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.
}
} else {
*bitmap = tmpBitmap;
- bitmap->lockPixels();
bitmap->pixelRef()->setImmutableWithID(uniqueID);
}
return true;
//
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);
}
///////////////////////////////////////////////////////////////////////////////
-// 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));
sk_sp<SkColorTable> ctable)
: fInfo(validate_info(info))
, fCTable(std::move(ctable))
+ , fPixels(pixels)
+ , fRowBytes(rowBytes)
#ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK
, fStableID(SkNextID::ImageID())
#endif
#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);
}
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) {
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();
#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);
fUnlockContext = ctx;
fIsLocked = true;
}
+#endif
/////////////////////////////////////////////////////////////////////////////////////////////////
, 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());
}
this->writeBool(false);
// see if the caller wants to manually encode
- SkAutoPixmapUnlock result;
- if (fPixelSerializer && bitmap.requestLock(&result)) {
- sk_sp<SkData> data(fPixelSerializer->encode(result.pixmap()));
+ SkPixmap result;
+ if (fPixelSerializer && bitmap.peekPixels(&result)) {
+ sk_sp<SkData> 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
return nullptr;
}
- SkAutoLockPixels inputLock(inputBM);
-
if (!inputBM.getPixels() || inputBM.width() <= 0 || inputBM.height() <= 0) {
return nullptr;
}
return nullptr;
}
- SkAutoLockPixels dstLock(dst);
-
U8CPU innerThreshold = (U8CPU)(fInnerThreshold * 0xFF);
U8CPU outerThreshold = (U8CPU)(fOuterThreshold * 0xFF);
SkColor* dptr = dst.getAddr32(0, 0);
if (!img->getROPixels(&srcBM)) {
return;
}
- srcBM.lockPixels();
if (!srcBM.peekPixels(&src)) {
return;
}
return nullptr;
}
- SkAutoLockPixels colorLock(colorBM), displLock(displBM);
if (!colorBM.getPixels() || !displBM.getPixels()) {
return nullptr;
}
return nullptr;
}
- SkAutoLockPixels dstLock(dst);
-
computeDisplacement(fXChannelSelector, fYChannelSelector, scale, &dst,
displBM, colorOffset - displOffset, colorBM, colorBounds);
return nullptr;
}
- SkAutoLockPixels alp(inputBM);
if (!inputBM.getPixels()) {
return nullptr;
}
return nullptr;
}
- SkAutoLockPixels dstLock(dst);
-
SkMatrix matrix(ctx.ctm());
matrix.postTranslate(SkIntToScalar(-inputOffset.x()), SkIntToScalar(-inputOffset.y()));
return nullptr;
}
- SkAutoLockPixels alp(inputBM);
if (!inputBM.getPixels()) {
return nullptr;
}
return nullptr;
}
- SkAutoLockPixels dstLock(dst);
-
SpecularLightingType lightingType(fKS, fShininess);
SkMatrix matrix(ctx.ctm());
return nullptr;
}
- SkAutoLockPixels alp(inputBM);
SkASSERT(inputBM.getPixels());
if (!inputBM.getPixels() || inputBM.width() <= 0 || inputBM.height() <= 0) {
return nullptr;
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) {
// 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();
}
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);
inputBM = unpremultiply_bitmap(inputBM);
}
- SkAutoLockPixels alp(inputBM);
if (!inputBM.getPixels()) {
return nullptr;
}
return nullptr;
}
- SkAutoLockPixels dstLock(dst);
-
offset->fX = bounds.fLeft;
offset->fY = bounds.fTop;
bounds.offset(-inputOffset);
return nullptr;
}
- SkAutoLockPixels inputLock(inputBM), dstLock(dst);
-
SkMorphologyImageFilter::Proc procX, procY;
if (kDilate_Op == this->op()) {
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,
return nullptr;
}
- innerBM.lockPixels();
if (nullptr == innerBM.getPixels()) {
return nullptr;
}
void SkGradientShaderBase::initLinearBitmap(SkBitmap* bitmap) const {
const bool interpInPremul = SkToBool(fGradFlags &
SkGradientShader::kInterpolateColorsInPremul_Flag);
- bitmap->lockPixels();
SkHalf* pixelsF16 = reinterpret_cast<SkHalf*>(bitmap->getPixels());
uint32_t* pixelsS32 = reinterpret_cast<uint32_t*>(bitmap->getPixels());
prevIndex = nextIndex;
}
SkASSERT(prevIndex == kCache32Count - 1);
- bitmap->unlockPixels();
}
/*
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()) {
//////////////////////////////////////////////////////////////////////////////
sk_sp<GrTextureProxy> GrUploadBitmapToTextureProxy(GrResourceProvider* resourceProvider,
const SkBitmap& bitmap) {
- SkAutoLockPixels alp(bitmap);
if (!bitmap.readyToDraw()) {
return nullptr;
}
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<SkMipMap> mipmaps(SkMipMap::Build(pixmap, colorMode, nullptr));
if (!mipmaps) {
fKeyTable.insert(index, 1, &row);
rowNumber = static_cast<int>(row - fRows);
- SkAutoLockPixels lock(bitmap);
-
SkASSERT(bitmap.width() == fDesc.fWidth);
SkASSERT(bitmap.height() == fDesc.fRowHeight);
//
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
}
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;
}
}
: (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());
}
fBitmap.installPixels(info, addr, rowBytes, ctable, release_data, data.release());
fBitmap.setImmutable();
- fBitmap.lockPixels();
}
SkImage_Raster::~SkImage_Raster() {
sk_sp<SkImage> SkMakeImageFromRasterBitmap(const SkBitmap& bm, SkCopyPixelsMode cpm) {
bool hasColorTable = false;
if (kIndex_8_SkColorType == bm.colorType()) {
- SkAutoLockPixels autoLockPixels(bm);
hasColorTable = bm.getColorTable() != nullptr;
}
}
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 {
SkTLazy<SkBitmap> tmp;
if (!fBitmap.peekPixels(&src)) {
tmp.init(fBitmap);
- tmp.get()->lockPixels();
SkAssertResult(tmp.get()->peekPixels(&src));
}
} 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());
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();
}
SkBitmap copy;
const SkBitmap& bm = not4444(bitmap, ©);
- SkAutoLockPixels autoLockPixels(bm);
SkColorType colorType = bm.colorType();
SkAlphaType alphaType = bm.alphaType();
switch (colorType) {
}
SkBitmap copy;
const SkBitmap& bm = not4444(bitmap, ©);
- SkAutoLockPixels autoLockPixels(bm);
SkColorType colorType = bm.colorType();
switch (colorType) {
case kRGBA_8888_SkColorType:
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;
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.
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());
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
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);
// 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(),
&bmi,
DIB_RGB_COLORS);
(void)ret; // we're ignoring potential failures for now.
- bitmap.unlockPixels();
}
}
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()));
#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());
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);
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));
}
}
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));
SkColorSetRGB(0x80, 0xFF, 0x80));
// Clean up - surface depends on backingSurface and must be released first.
- bitmap.unlockPixels();
surface.reset();
backingSurface.reset();
}
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);
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) {
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);
}
}
#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();
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);
const SkMD5::Digest& goodDigest) {
SkBitmap bm;
bm.allocPixels(info);
- SkAutoLockPixels autoLockPixels(bm);
REPORTER_ASSERT(r, SkCodec::kSuccess == codec->startIncrementalDecode(info, bm.getPixels(),
bm.rowBytes()));
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);
// 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);
SkImageInfo grayInfo = codec->getInfo();
SkBitmap grayBm;
grayBm.allocPixels(grayInfo);
- SkAutoLockPixels alp(grayBm);
grayBm.eraseColor(SK_ColorBLACK);
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);
}
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<const uint8_t*>(bm.getAddr(0, y));
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);
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);
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
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);
paint.getColorFilter()->filterColor(paintColor));
}
}
- paintResult.unlockPixels();
- filterResult.unlockPixels();
}
DEF_TEST(HighContrastFilter_SanityCheck, 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),
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;
if (result.get()) {
SkBitmap resultBM;
REPORTER_ASSERT(reporter, result->getROPixels(&resultBM));
- SkAutoLockPixels lock(resultBM);
REPORTER_ASSERT(reporter, *resultBM.getAddr32(0, 0) == SK_ColorGREEN);
}
}
SkBitmap resultBM;
REPORTER_ASSERT(reporter, result->getROPixels(&resultBM));
- SkAutoLockPixels lock(resultBM);
REPORTER_ASSERT(reporter, resultBM.getColor(50, 50) == SK_ColorGREEN);
}
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);
}
#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()));
}
// Test correctness
{
- SkAutoLockPixels lockBm(bmt);
for (int y = 0; y < info.height(); y++) {
REPORTER_ASSERT(reporter, 0xFFFF0000 == bmt.getColor(0, y));
REPORTER_ASSERT(reporter, bitmap.isImmutable());
}
- SkAutoLockPixels alp(bitmap);
REPORTER_ASSERT(reporter, bitmap.getPixels());
const SkImageInfo info = SkImageInfo::MakeN32(1, 1, bitmap.alphaType());
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))));
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))));
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))));
}
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<intptr_t>(bitmap->getPixels());
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) {
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);
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}) {
test_readpixels_texture(reporter, std::move(sContext));
}
}
-
- bmp.unlockPixels();
}
#endif
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())) {
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)));
return false;
}
- SkAutoLockPixels alp(secretDevBitmap);
canvasRowBytes = secretDevBitmap.rowBytes();
canvasPixels = static_cast<const uint32_t*>(secretDevBitmap.getPixels());
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);
bool SkDrawCommand::flatten(const SkBitmap& bitmap, Json::Value* target,
UrlDataManager& urlDataManager) {
- bitmap.lockPixels();
sk_sp<SkImage> 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);
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);
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;
} 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;
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);
return;
}
- SkAutoLockPixels alpDiff(dr->fDifference.fBitmap);
- SkAutoLockPixels alpWhite(dr->fWhite.fBitmap);
int mismatchedPixels = 0;
int totalMismatchA = 0;
int totalMismatchR = 0;
/** 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);