Make SkDevice::onReadPixels take a const& rather than const*

git-svn-id: http://skia.googlecode.com/svn/trunk@2587 2bbb7eff-a529-9590-31e7-b0007b416f81
This commit is contained in:
bsalomon@google.com 2011-11-02 20:06:25 +00:00
parent c69809745e
commit 910267dde2
6 changed files with 24 additions and 25 deletions

View File

@ -275,9 +275,8 @@ protected:
* 2. bitmap has pixels. * 2. bitmap has pixels.
* 3. The rectangle (x, y, x + bitmap->width(), y + bitmap->height()) is * 3. The rectangle (x, y, x + bitmap->width(), y + bitmap->height()) is
* contained in the device bounds. * contained in the device bounds.
* 4. the bitmap struct is safe to partially overwrite in case of failure
*/ */
virtual bool onReadPixels(const SkBitmap* bitmap, int x, int y); virtual bool onReadPixels(const SkBitmap& bitmap, int x, int y);
/** Called when this device is installed into a Canvas. Balanaced by a call /** Called when this device is installed into a Canvas. Balanaced by a call

View File

@ -141,7 +141,7 @@ protected:
int x, int y, int x, int y,
const SkPaint& paint) SK_OVERRIDE; const SkPaint& paint) SK_OVERRIDE;
virtual bool onReadPixels(const SkBitmap* bitmap, virtual bool onReadPixels(const SkBitmap& bitmap,
int x, int x,
int y) SK_OVERRIDE { int y) SK_OVERRIDE {
return false; return false;

View File

@ -141,7 +141,7 @@ protected:
friend class SkAutoTexCache; friend class SkAutoTexCache;
// overrides from SkDevice // overrides from SkDevice
virtual bool onReadPixels(const SkBitmap* bitmap, virtual bool onReadPixels(const SkBitmap& bitmap,
int x, int y) SK_OVERRIDE; int x, int y) SK_OVERRIDE;

View File

@ -158,7 +158,7 @@ public:
} }
protected: protected:
virtual bool onReadPixels(const SkBitmap* bitmap, virtual bool onReadPixels(const SkBitmap& bitmap,
int x, int y) SK_OVERRIDE { int x, int y) SK_OVERRIDE {
return false; return false;
} }

View File

@ -135,20 +135,20 @@ bool SkDevice::readPixels(SkBitmap* bitmap, int x, int y) {
SkBitmap bmpSubset; SkBitmap bmpSubset;
bmp->extractSubset(&bmpSubset, subrect); bmp->extractSubset(&bmpSubset, subrect);
bool result = this->onReadPixels(&bmpSubset, srcRect.fLeft, srcRect.fTop); bool result = this->onReadPixels(bmpSubset, srcRect.fLeft, srcRect.fTop);
if (result && bmp == &tmp) { if (result && bmp == &tmp) {
tmp.swap(*bitmap); tmp.swap(*bitmap);
} }
return result; return result;
} }
bool SkDevice::onReadPixels(const SkBitmap* bitmap, int x, int y) { bool SkDevice::onReadPixels(const SkBitmap& bitmap, int x, int y) {
SkASSERT(SkBitmap::kARGB_8888_Config == bitmap->config()); SkASSERT(SkBitmap::kARGB_8888_Config == bitmap.config());
SkASSERT(!bitmap->isNull()); SkASSERT(!bitmap.isNull());
SkASSERT(SkIRect::MakeWH(this->width(), this->height()).contains(SkIRect::MakeXYWH(x, y, bitmap->width(), bitmap->height()))); SkASSERT(SkIRect::MakeWH(this->width(), this->height()).contains(SkIRect::MakeXYWH(x, y, bitmap.width(), bitmap.height())));
SkIRect srcRect = SkIRect::MakeXYWH(x, y, bitmap->width(), SkIRect srcRect = SkIRect::MakeXYWH(x, y, bitmap.width(),
bitmap->height()); bitmap.height());
const SkBitmap& src = this->accessBitmap(false); const SkBitmap& src = this->accessBitmap(false);
SkBitmap subset; SkBitmap subset;
@ -161,10 +161,10 @@ bool SkDevice::onReadPixels(const SkBitmap* bitmap, int x, int y) {
// or make copyTo lazily allocate. // or make copyTo lazily allocate.
subset.copyTo(&subset, SkBitmap::kARGB_8888_Config); subset.copyTo(&subset, SkBitmap::kARGB_8888_Config);
} }
SkAutoLockPixels alp(*bitmap); SkAutoLockPixels alp(bitmap);
return subset.copyPixelsTo(bitmap->getPixels(), return subset.copyPixelsTo(bitmap.getPixels(),
bitmap->getSize(), bitmap.getSize(),
bitmap->rowBytes(), bitmap.rowBytes(),
true); true);
} }

View File

@ -256,19 +256,19 @@ void SkGpuDevice::makeRenderTargetCurrent() {
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
bool SkGpuDevice::onReadPixels(const SkBitmap* bitmap, int x, int y) { bool SkGpuDevice::onReadPixels(const SkBitmap& bitmap, int x, int y) {
SkASSERT(SkBitmap::kARGB_8888_Config == bitmap->config()); SkASSERT(SkBitmap::kARGB_8888_Config == bitmap.config());
SkASSERT(!bitmap->isNull()); SkASSERT(!bitmap.isNull());
SkASSERT(SkIRect::MakeWH(this->width(), this->height()).contains(SkIRect::MakeXYWH(x, y, bitmap->width(), bitmap->height()))); SkASSERT(SkIRect::MakeWH(this->width(), this->height()).contains(SkIRect::MakeXYWH(x, y, bitmap.width(), bitmap.height())));
SkAutoLockPixels alp(*bitmap); SkAutoLockPixels alp(bitmap);
return fContext->readRenderTargetPixels(fRenderTarget, return fContext->readRenderTargetPixels(fRenderTarget,
x, y, x, y,
bitmap->width(), bitmap.width(),
bitmap->height(), bitmap.height(),
kRGBA_8888_GrPixelConfig, kRGBA_8888_GrPixelConfig,
bitmap->getPixels(), bitmap.getPixels(),
bitmap->rowBytes()); bitmap.rowBytes());
} }
void SkGpuDevice::writePixels(const SkBitmap& bitmap, int x, int y) { void SkGpuDevice::writePixels(const SkBitmap& bitmap, int x, int y) {