diff options
author | 2010-12-20 18:26:13 +0000 | |
---|---|---|
committer | 2010-12-20 18:26:13 +0000 | |
commit | f2b98d67dcb6fcb3120feede9c72016fc7b3ead8 (patch) | |
tree | d78b57945b29865dcdeb1badbb360575289b292d /src/core/SkDevice.cpp | |
parent | 29e5054dd07c97c2195c5f64bf67aaa6b5afa204 (diff) |
merge with changes for GPU backend
git-svn-id: http://skia.googlecode.com/svn/trunk@637 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'src/core/SkDevice.cpp')
-rw-r--r-- | src/core/SkDevice.cpp | 80 |
1 files changed, 67 insertions, 13 deletions
diff --git a/src/core/SkDevice.cpp b/src/core/SkDevice.cpp index 12efaacbaf..8df0e41d72 100644 --- a/src/core/SkDevice.cpp +++ b/src/core/SkDevice.cpp @@ -4,9 +4,20 @@ SkDeviceFactory::~SkDeviceFactory() {} -SkDevice::SkDevice() {} - -SkDevice::SkDevice(const SkBitmap& bitmap) : fBitmap(bitmap) {} +SkDevice::SkDevice(SkCanvas* canvas) : fCanvas(canvas) {} + +SkDevice::SkDevice(SkCanvas* canvas, const SkBitmap& bitmap, bool isForLayer) + : fCanvas(canvas), fBitmap(bitmap) { + // auto-allocate if we're for offscreen drawing + if (isForLayer) { + if (NULL == fBitmap.getPixels() && NULL == fBitmap.pixelRef()) { + fBitmap.allocPixels(); + if (!fBitmap.isOpaque()) { + fBitmap.eraseColor(0); + } + } + } +} void SkDevice::lockPixels() { fBitmap.lockPixels(); @@ -47,6 +58,39 @@ void SkDevice::setMatrixClip(const SkMatrix&, const SkRegion&) {} /////////////////////////////////////////////////////////////////////////////// +bool SkDevice::readPixels(const SkIRect& srcRect, SkBitmap* bitmap) { + const SkBitmap& src = this->accessBitmap(false); + + SkIRect bounds; + bounds.set(0, 0, src.width(), src.height()); + if (!bounds.intersect(srcRect)) { + return false; + } + + SkBitmap subset; + if (!src.extractSubset(&subset, bounds)) { + return false; + } + + SkBitmap tmp; + if (!subset.copyTo(&tmp, SkBitmap::kARGB_8888_Config)) { + return false; + } + + tmp.swap(*bitmap); + return true; +} + +void SkDevice::writePixels(const SkBitmap& bitmap, int x, int y) { + SkPaint paint; + paint.setXfermodeMode(SkXfermode::kSrc_Mode); + + SkCanvas canvas(this); + canvas.drawSprite(bitmap, x, y, &paint); +} + +/////////////////////////////////////////////////////////////////////////////// + void SkDevice::drawPaint(const SkDraw& draw, const SkPaint& paint) { draw.drawPaint(paint); } @@ -62,13 +106,24 @@ void SkDevice::drawRect(const SkDraw& draw, const SkRect& r, } void SkDevice::drawPath(const SkDraw& draw, const SkPath& path, - const SkPaint& paint) { - draw.drawPath(path, paint); + const SkPaint& paint, const SkMatrix* prePathMatrix, + bool pathIsMutable) { + draw.drawPath(path, paint, prePathMatrix, pathIsMutable); } void SkDevice::drawBitmap(const SkDraw& draw, const SkBitmap& bitmap, - const SkMatrix& matrix, const SkPaint& paint) { - draw.drawBitmap(bitmap, matrix, paint); + const SkIRect* srcRect, + const SkMatrix& matrix, const SkPaint& paint) { + SkBitmap tmp; // storage if we need a subset of bitmap + const SkBitmap* bitmapPtr = &bitmap; + + if (srcRect) { + if (!bitmap.extractSubset(&tmp, *srcRect)) { + return; // extraction failed + } + bitmapPtr = &tmp; + } + draw.drawBitmap(*bitmapPtr, matrix, paint); } void SkDevice::drawSprite(const SkDraw& draw, const SkBitmap& bitmap, @@ -109,16 +164,15 @@ void SkDevice::drawDevice(const SkDraw& draw, SkDevice* device, draw.drawSprite(device->accessBitmap(false), x, y, paint); } -SkDevice* SkRasterDeviceFactory::newDevice(SkBitmap::Config config, int width, +/////////////////////////////////////////////////////////////////////////////// + +SkDevice* SkRasterDeviceFactory::newDevice(SkCanvas* canvas, + SkBitmap::Config config, int width, int height, bool isOpaque, bool isForLayer) { SkBitmap bitmap; bitmap.setConfig(config, width, height); bitmap.setIsOpaque(isOpaque); - bitmap.allocPixels(); - if (!bitmap.isOpaque()) - bitmap.eraseARGB(0, 0, 0, 0); - - return SkNEW_ARGS(SkDevice, (bitmap)); + return SkNEW_ARGS(SkDevice, (canvas, bitmap, isForLayer)); } |