michael@0: /* michael@0: * Copyright 2013 Google Inc. michael@0: * michael@0: * Use of this source code is governed by a BSD-style license that can be michael@0: * found in the LICENSE file. michael@0: */ michael@0: michael@0: #include "SkBitmapDevice.h" michael@0: #include "SkConfig8888.h" michael@0: #include "SkDraw.h" michael@0: #include "SkRasterClip.h" michael@0: #include "SkShader.h" michael@0: #include "SkSurface.h" michael@0: michael@0: #define CHECK_FOR_ANNOTATION(paint) \ michael@0: do { if (paint.getAnnotation()) { return; } } while (0) michael@0: michael@0: static bool valid_for_bitmap_device(const SkImageInfo& info, michael@0: SkAlphaType* newAlphaType) { michael@0: if (info.width() < 0 || info.height() < 0) { michael@0: return false; michael@0: } michael@0: michael@0: // TODO: can we stop supporting kUnknown in SkBitmkapDevice? michael@0: if (kUnknown_SkColorType == info.colorType()) { michael@0: if (newAlphaType) { michael@0: *newAlphaType = kIgnore_SkAlphaType; michael@0: } michael@0: return true; michael@0: } michael@0: michael@0: switch (info.alphaType()) { michael@0: case kPremul_SkAlphaType: michael@0: case kOpaque_SkAlphaType: michael@0: break; michael@0: default: michael@0: return false; michael@0: } michael@0: michael@0: SkAlphaType canonicalAlphaType = info.alphaType(); michael@0: michael@0: switch (info.colorType()) { michael@0: case kAlpha_8_SkColorType: michael@0: break; michael@0: case kRGB_565_SkColorType: michael@0: canonicalAlphaType = kOpaque_SkAlphaType; michael@0: break; michael@0: case kPMColor_SkColorType: michael@0: break; michael@0: default: michael@0: return false; michael@0: } michael@0: michael@0: if (newAlphaType) { michael@0: *newAlphaType = canonicalAlphaType; michael@0: } michael@0: return true; michael@0: } michael@0: michael@0: SkBitmapDevice::SkBitmapDevice(const SkBitmap& bitmap) : fBitmap(bitmap) { michael@0: SkASSERT(valid_for_bitmap_device(bitmap.info(), NULL)); michael@0: } michael@0: michael@0: SkBitmapDevice::SkBitmapDevice(const SkBitmap& bitmap, const SkDeviceProperties& deviceProperties) michael@0: : SkBaseDevice(deviceProperties) michael@0: , fBitmap(bitmap) michael@0: { michael@0: SkASSERT(valid_for_bitmap_device(bitmap.info(), NULL)); michael@0: } michael@0: michael@0: #ifdef SK_SUPPORT_LEGACY_COMPATIBLEDEVICE_CONFIG michael@0: void SkBitmapDevice::init(SkBitmap::Config config, int width, int height, bool isOpaque) { michael@0: fBitmap.setConfig(config, width, height, 0, isOpaque ? michael@0: kOpaque_SkAlphaType : kPremul_SkAlphaType); michael@0: michael@0: if (SkBitmap::kNo_Config != config) { michael@0: if (!fBitmap.allocPixels()) { michael@0: // indicate failure by zeroing our bitmap michael@0: fBitmap.setConfig(config, 0, 0, 0, isOpaque ? michael@0: kOpaque_SkAlphaType : kPremul_SkAlphaType); michael@0: } else if (!isOpaque) { michael@0: fBitmap.eraseColor(SK_ColorTRANSPARENT); michael@0: } michael@0: } michael@0: } michael@0: michael@0: SkBitmapDevice::SkBitmapDevice(SkBitmap::Config config, int width, int height, bool isOpaque) { michael@0: this->init(config, width, height, isOpaque); michael@0: } michael@0: michael@0: SkBitmapDevice::SkBitmapDevice(SkBitmap::Config config, int width, int height, bool isOpaque, michael@0: const SkDeviceProperties& deviceProperties) michael@0: : SkBaseDevice(deviceProperties) michael@0: { michael@0: this->init(config, width, height, isOpaque); michael@0: } michael@0: #endif michael@0: SkBitmapDevice* SkBitmapDevice::Create(const SkImageInfo& origInfo, michael@0: const SkDeviceProperties* props) { michael@0: SkImageInfo info = origInfo; michael@0: if (!valid_for_bitmap_device(info, &info.fAlphaType)) { michael@0: return NULL; michael@0: } michael@0: michael@0: SkBitmap bitmap; michael@0: michael@0: if (kUnknown_SkColorType == info.colorType()) { michael@0: if (!bitmap.setConfig(info)) { michael@0: return NULL; michael@0: } michael@0: } else { michael@0: if (!bitmap.allocPixels(info)) { michael@0: return NULL; michael@0: } michael@0: if (!bitmap.info().isOpaque()) { michael@0: bitmap.eraseColor(SK_ColorTRANSPARENT); michael@0: } michael@0: } michael@0: michael@0: if (props) { michael@0: return SkNEW_ARGS(SkBitmapDevice, (bitmap, *props)); michael@0: } else { michael@0: return SkNEW_ARGS(SkBitmapDevice, (bitmap)); michael@0: } michael@0: } michael@0: michael@0: SkImageInfo SkBitmapDevice::imageInfo() const { michael@0: return fBitmap.info(); michael@0: } michael@0: michael@0: void SkBitmapDevice::replaceBitmapBackendForRasterSurface(const SkBitmap& bm) { michael@0: SkASSERT(bm.width() == fBitmap.width()); michael@0: SkASSERT(bm.height() == fBitmap.height()); michael@0: fBitmap = bm; // intent is to use bm's pixelRef (and rowbytes/config) michael@0: fBitmap.lockPixels(); michael@0: } michael@0: michael@0: SkBaseDevice* SkBitmapDevice::onCreateDevice(const SkImageInfo& info, Usage usage) { michael@0: return SkBitmapDevice::Create(info, &this->getDeviceProperties()); michael@0: } michael@0: michael@0: void SkBitmapDevice::lockPixels() { michael@0: if (fBitmap.lockPixelsAreWritable()) { michael@0: fBitmap.lockPixels(); michael@0: } michael@0: } michael@0: michael@0: void SkBitmapDevice::unlockPixels() { michael@0: if (fBitmap.lockPixelsAreWritable()) { michael@0: fBitmap.unlockPixels(); michael@0: } michael@0: } michael@0: michael@0: void SkBitmapDevice::clear(SkColor color) { michael@0: fBitmap.eraseColor(color); michael@0: } michael@0: michael@0: const SkBitmap& SkBitmapDevice::onAccessBitmap() { michael@0: return fBitmap; michael@0: } michael@0: michael@0: bool SkBitmapDevice::canHandleImageFilter(const SkImageFilter*) { michael@0: return false; michael@0: } michael@0: michael@0: bool SkBitmapDevice::filterImage(const SkImageFilter* filter, const SkBitmap& src, michael@0: const SkImageFilter::Context& ctx, SkBitmap* result, michael@0: SkIPoint* offset) { michael@0: return false; michael@0: } michael@0: michael@0: bool SkBitmapDevice::allowImageFilter(const SkImageFilter*) { michael@0: return true; michael@0: } michael@0: michael@0: bool SkBitmapDevice::onReadPixels(const SkBitmap& bitmap, michael@0: int x, int y, michael@0: SkCanvas::Config8888 config8888) { michael@0: SkASSERT(SkBitmap::kARGB_8888_Config == bitmap.config()); michael@0: SkASSERT(!bitmap.isNull()); michael@0: SkASSERT(SkIRect::MakeWH(this->width(), this->height()).contains(SkIRect::MakeXYWH(x, y, michael@0: bitmap.width(), michael@0: bitmap.height()))); michael@0: michael@0: SkIRect srcRect = SkIRect::MakeXYWH(x, y, bitmap.width(), bitmap.height()); michael@0: const SkBitmap& src = this->accessBitmap(false); michael@0: michael@0: SkBitmap subset; michael@0: if (!src.extractSubset(&subset, srcRect)) { michael@0: return false; michael@0: } michael@0: if (kPMColor_SkColorType != subset.colorType()) { michael@0: // It'd be preferable to do this directly to bitmap. michael@0: subset.copyTo(&subset, kPMColor_SkColorType); michael@0: } michael@0: SkAutoLockPixels alp(bitmap); michael@0: uint32_t* bmpPixels = reinterpret_cast(bitmap.getPixels()); michael@0: SkCopyBitmapToConfig8888(bmpPixels, bitmap.rowBytes(), config8888, subset); michael@0: return true; michael@0: } michael@0: michael@0: #ifdef SK_SUPPORT_LEGACY_WRITEPIXELSCONFIG michael@0: void SkBitmapDevice::writePixels(const SkBitmap& bitmap, michael@0: int x, int y, michael@0: SkCanvas::Config8888 config8888) { michael@0: if (bitmap.isNull() || bitmap.getTexture()) { michael@0: return; michael@0: } michael@0: const SkBitmap* sprite = &bitmap; michael@0: // check whether we have to handle a config8888 that doesn't match SkPMColor michael@0: if (SkBitmap::kARGB_8888_Config == bitmap.config() && michael@0: SkCanvas::kNative_Premul_Config8888 != config8888 && michael@0: kPMColorAlias != config8888) { michael@0: michael@0: // We're going to have to convert from a config8888 to the native config michael@0: // First we clip to the device bounds. michael@0: SkBitmap dstBmp = this->accessBitmap(true); michael@0: SkIRect spriteRect = SkIRect::MakeXYWH(x, y, michael@0: bitmap.width(), bitmap.height()); michael@0: SkIRect devRect = SkIRect::MakeWH(dstBmp.width(), dstBmp.height()); michael@0: if (!spriteRect.intersect(devRect)) { michael@0: return; michael@0: } michael@0: michael@0: // write directly to the device if it has pixels and is SkPMColor michael@0: bool drawSprite; michael@0: if (SkBitmap::kARGB_8888_Config == dstBmp.config() && !dstBmp.isNull()) { michael@0: // we can write directly to the dst when doing the conversion michael@0: dstBmp.extractSubset(&dstBmp, spriteRect); michael@0: drawSprite = false; michael@0: } else { michael@0: // we convert to a temporary bitmap and draw that as a sprite michael@0: if (!dstBmp.allocPixels(SkImageInfo::MakeN32Premul(spriteRect.width(), michael@0: spriteRect.height()))) { michael@0: return; michael@0: } michael@0: drawSprite = true; michael@0: } michael@0: michael@0: // copy pixels to dstBmp and convert from config8888 to native config. michael@0: SkAutoLockPixels alp(bitmap); michael@0: uint32_t* srcPixels = bitmap.getAddr32(spriteRect.fLeft - x, michael@0: spriteRect.fTop - y); michael@0: SkCopyConfig8888ToBitmap(dstBmp, michael@0: srcPixels, michael@0: bitmap.rowBytes(), michael@0: config8888); michael@0: michael@0: if (drawSprite) { michael@0: // we've clipped the sprite when we made a copy michael@0: x = spriteRect.fLeft; michael@0: y = spriteRect.fTop; michael@0: sprite = &dstBmp; michael@0: } else { michael@0: return; michael@0: } michael@0: } michael@0: michael@0: SkPaint paint; michael@0: paint.setXfermodeMode(SkXfermode::kSrc_Mode); michael@0: SkRasterClip clip(SkIRect::MakeWH(fBitmap.width(), fBitmap.height())); michael@0: SkDraw draw; michael@0: draw.fRC = &clip; michael@0: draw.fClip = &clip.bwRgn(); michael@0: draw.fBitmap = &fBitmap; // canvas should have already called accessBitmap michael@0: draw.fMatrix = &SkMatrix::I(); michael@0: this->drawSprite(draw, *sprite, x, y, paint); michael@0: } michael@0: #endif michael@0: michael@0: void* SkBitmapDevice::onAccessPixels(SkImageInfo* info, size_t* rowBytes) { michael@0: if (fBitmap.getPixels()) { michael@0: *info = fBitmap.info(); michael@0: *rowBytes = fBitmap.rowBytes(); michael@0: return fBitmap.getPixels(); michael@0: } michael@0: return NULL; michael@0: } michael@0: michael@0: static void rect_memcpy(void* dst, size_t dstRB, const void* src, size_t srcRB, size_t bytesPerRow, michael@0: int rowCount) { michael@0: SkASSERT(bytesPerRow <= srcRB); michael@0: SkASSERT(bytesPerRow <= dstRB); michael@0: for (int i = 0; i < rowCount; ++i) { michael@0: memcpy(dst, src, bytesPerRow); michael@0: dst = (char*)dst + dstRB; michael@0: src = (const char*)src + srcRB; michael@0: } michael@0: } michael@0: michael@0: static bool info2config8888(const SkImageInfo& info, SkCanvas::Config8888* config) { michael@0: bool pre; michael@0: switch (info.alphaType()) { michael@0: case kPremul_SkAlphaType: michael@0: case kOpaque_SkAlphaType: michael@0: pre = true; michael@0: break; michael@0: case kUnpremul_SkAlphaType: michael@0: pre = false; michael@0: break; michael@0: default: michael@0: return false; michael@0: } michael@0: switch (info.colorType()) { michael@0: case kRGBA_8888_SkColorType: michael@0: *config = pre ? SkCanvas::kRGBA_Premul_Config8888 : SkCanvas::kRGBA_Unpremul_Config8888; michael@0: return true; michael@0: case kBGRA_8888_SkColorType: michael@0: *config = pre ? SkCanvas::kBGRA_Premul_Config8888 : SkCanvas::kBGRA_Unpremul_Config8888; michael@0: return true; michael@0: default: michael@0: return false; michael@0: } michael@0: } michael@0: michael@0: // TODO: make this guy real, and not rely on legacy config8888 utility michael@0: #include "SkConfig8888.h" michael@0: static bool write_pixels(const SkImageInfo& dstInfo, void* dstPixels, size_t dstRowBytes, michael@0: const SkImageInfo& srcInfo, const void* srcPixels, size_t srcRowBytes) { michael@0: if (srcInfo.dimensions() != dstInfo.dimensions()) { michael@0: return false; michael@0: } michael@0: if (4 == srcInfo.bytesPerPixel() && 4 == dstInfo.bytesPerPixel()) { michael@0: SkCanvas::Config8888 srcConfig, dstConfig; michael@0: if (!info2config8888(srcInfo, &srcConfig) || !info2config8888(dstInfo, &dstConfig)) { michael@0: return false; michael@0: } michael@0: SkConvertConfig8888Pixels((uint32_t*)dstPixels, dstRowBytes, dstConfig, michael@0: (const uint32_t*)srcPixels, srcRowBytes, srcConfig, michael@0: srcInfo.width(), srcInfo.height()); michael@0: return true; michael@0: } michael@0: if (srcInfo.colorType() == dstInfo.colorType()) { michael@0: switch (srcInfo.colorType()) { michael@0: case kRGB_565_SkColorType: michael@0: case kAlpha_8_SkColorType: michael@0: break; michael@0: case kARGB_4444_SkColorType: michael@0: if (srcInfo.alphaType() != dstInfo.alphaType()) { michael@0: return false; michael@0: } michael@0: break; michael@0: default: michael@0: return false; michael@0: } michael@0: rect_memcpy(dstPixels, dstRowBytes, srcPixels, srcRowBytes, michael@0: srcInfo.width() * srcInfo.bytesPerPixel(), srcInfo.height()); michael@0: } michael@0: // TODO: add support for more conversions as needed michael@0: return false; michael@0: } michael@0: michael@0: bool SkBitmapDevice::onWritePixels(const SkImageInfo& srcInfo, const void* srcPixels, michael@0: size_t srcRowBytes, int x, int y) { michael@0: // since we don't stop creating un-pixeled devices yet, check for no pixels here michael@0: if (NULL == fBitmap.getPixels()) { michael@0: return false; michael@0: } michael@0: michael@0: SkImageInfo dstInfo = fBitmap.info(); michael@0: dstInfo.fWidth = srcInfo.width(); michael@0: dstInfo.fHeight = srcInfo.height(); michael@0: michael@0: void* dstPixels = fBitmap.getAddr(x, y); michael@0: size_t dstRowBytes = fBitmap.rowBytes(); michael@0: michael@0: if (write_pixels(dstInfo, dstPixels, dstRowBytes, srcInfo, srcPixels, srcRowBytes)) { michael@0: fBitmap.notifyPixelsChanged(); michael@0: return true; michael@0: } michael@0: return false; michael@0: } michael@0: michael@0: /////////////////////////////////////////////////////////////////////////////// michael@0: michael@0: void SkBitmapDevice::drawPaint(const SkDraw& draw, const SkPaint& paint) { michael@0: draw.drawPaint(paint); michael@0: } michael@0: michael@0: void SkBitmapDevice::drawPoints(const SkDraw& draw, SkCanvas::PointMode mode, size_t count, michael@0: const SkPoint pts[], const SkPaint& paint) { michael@0: CHECK_FOR_ANNOTATION(paint); michael@0: draw.drawPoints(mode, count, pts, paint); michael@0: } michael@0: michael@0: void SkBitmapDevice::drawRect(const SkDraw& draw, const SkRect& r, const SkPaint& paint) { michael@0: CHECK_FOR_ANNOTATION(paint); michael@0: draw.drawRect(r, paint); michael@0: } michael@0: michael@0: void SkBitmapDevice::drawOval(const SkDraw& draw, const SkRect& oval, const SkPaint& paint) { michael@0: CHECK_FOR_ANNOTATION(paint); michael@0: michael@0: SkPath path; michael@0: path.addOval(oval); michael@0: // call the VIRTUAL version, so any subclasses who do handle drawPath aren't michael@0: // required to override drawOval. michael@0: this->drawPath(draw, path, paint, NULL, true); michael@0: } michael@0: michael@0: void SkBitmapDevice::drawRRect(const SkDraw& draw, const SkRRect& rrect, const SkPaint& paint) { michael@0: CHECK_FOR_ANNOTATION(paint); michael@0: michael@0: #ifdef SK_IGNORE_BLURRED_RRECT_OPT michael@0: SkPath path; michael@0: michael@0: path.addRRect(rrect); michael@0: // call the VIRTUAL version, so any subclasses who do handle drawPath aren't michael@0: // required to override drawRRect. michael@0: this->drawPath(draw, path, paint, NULL, true); michael@0: #else michael@0: draw.drawRRect(rrect, paint); michael@0: #endif michael@0: } michael@0: michael@0: void SkBitmapDevice::drawPath(const SkDraw& draw, const SkPath& path, michael@0: const SkPaint& paint, const SkMatrix* prePathMatrix, michael@0: bool pathIsMutable) { michael@0: CHECK_FOR_ANNOTATION(paint); michael@0: draw.drawPath(path, paint, prePathMatrix, pathIsMutable); michael@0: } michael@0: michael@0: void SkBitmapDevice::drawBitmap(const SkDraw& draw, const SkBitmap& bitmap, michael@0: const SkMatrix& matrix, const SkPaint& paint) { michael@0: draw.drawBitmap(bitmap, matrix, paint); michael@0: } michael@0: michael@0: void SkBitmapDevice::drawBitmapRect(const SkDraw& draw, const SkBitmap& bitmap, michael@0: const SkRect* src, const SkRect& dst, michael@0: const SkPaint& paint, michael@0: SkCanvas::DrawBitmapRectFlags flags) { michael@0: SkMatrix matrix; michael@0: SkRect bitmapBounds, tmpSrc, tmpDst; michael@0: SkBitmap tmpBitmap; michael@0: michael@0: bitmapBounds.isetWH(bitmap.width(), bitmap.height()); michael@0: michael@0: // Compute matrix from the two rectangles michael@0: if (src) { michael@0: tmpSrc = *src; michael@0: } else { michael@0: tmpSrc = bitmapBounds; michael@0: } michael@0: matrix.setRectToRect(tmpSrc, dst, SkMatrix::kFill_ScaleToFit); michael@0: michael@0: const SkRect* dstPtr = &dst; michael@0: const SkBitmap* bitmapPtr = &bitmap; michael@0: michael@0: // clip the tmpSrc to the bounds of the bitmap, and recompute dstRect if michael@0: // needed (if the src was clipped). No check needed if src==null. michael@0: if (src) { michael@0: if (!bitmapBounds.contains(*src)) { michael@0: if (!tmpSrc.intersect(bitmapBounds)) { michael@0: return; // nothing to draw michael@0: } michael@0: // recompute dst, based on the smaller tmpSrc michael@0: matrix.mapRect(&tmpDst, tmpSrc); michael@0: dstPtr = &tmpDst; michael@0: } michael@0: michael@0: // since we may need to clamp to the borders of the src rect within michael@0: // the bitmap, we extract a subset. michael@0: SkIRect srcIR; michael@0: tmpSrc.roundOut(&srcIR); michael@0: if (!bitmap.extractSubset(&tmpBitmap, srcIR)) { michael@0: return; michael@0: } michael@0: bitmapPtr = &tmpBitmap; michael@0: michael@0: // Since we did an extract, we need to adjust the matrix accordingly michael@0: SkScalar dx = 0, dy = 0; michael@0: if (srcIR.fLeft > 0) { michael@0: dx = SkIntToScalar(srcIR.fLeft); michael@0: } michael@0: if (srcIR.fTop > 0) { michael@0: dy = SkIntToScalar(srcIR.fTop); michael@0: } michael@0: if (dx || dy) { michael@0: matrix.preTranslate(dx, dy); michael@0: } michael@0: michael@0: SkRect extractedBitmapBounds; michael@0: extractedBitmapBounds.isetWH(bitmapPtr->width(), bitmapPtr->height()); michael@0: if (extractedBitmapBounds == tmpSrc) { michael@0: // no fractional part in src, we can just call drawBitmap michael@0: goto USE_DRAWBITMAP; michael@0: } michael@0: } else { michael@0: USE_DRAWBITMAP: michael@0: // We can go faster by just calling drawBitmap, which will concat the michael@0: // matrix with the CTM, and try to call drawSprite if it can. If not, michael@0: // it will make a shader and call drawRect, as we do below. michael@0: this->drawBitmap(draw, *bitmapPtr, matrix, paint); michael@0: return; michael@0: } michael@0: michael@0: // construct a shader, so we can call drawRect with the dst michael@0: SkShader* s = SkShader::CreateBitmapShader(*bitmapPtr, michael@0: SkShader::kClamp_TileMode, michael@0: SkShader::kClamp_TileMode); michael@0: if (NULL == s) { michael@0: return; michael@0: } michael@0: s->setLocalMatrix(matrix); michael@0: michael@0: SkPaint paintWithShader(paint); michael@0: paintWithShader.setStyle(SkPaint::kFill_Style); michael@0: paintWithShader.setShader(s)->unref(); michael@0: michael@0: // Call ourself, in case the subclass wanted to share this setup code michael@0: // but handle the drawRect code themselves. michael@0: this->drawRect(draw, *dstPtr, paintWithShader); michael@0: } michael@0: michael@0: void SkBitmapDevice::drawSprite(const SkDraw& draw, const SkBitmap& bitmap, michael@0: int x, int y, const SkPaint& paint) { michael@0: draw.drawSprite(bitmap, x, y, paint); michael@0: } michael@0: michael@0: void SkBitmapDevice::drawText(const SkDraw& draw, const void* text, size_t len, michael@0: SkScalar x, SkScalar y, const SkPaint& paint) { michael@0: draw.drawText((const char*)text, len, x, y, paint); michael@0: } michael@0: michael@0: void SkBitmapDevice::drawPosText(const SkDraw& draw, const void* text, size_t len, michael@0: const SkScalar xpos[], SkScalar y, michael@0: int scalarsPerPos, const SkPaint& paint) { michael@0: draw.drawPosText((const char*)text, len, xpos, y, scalarsPerPos, paint); michael@0: } michael@0: michael@0: void SkBitmapDevice::drawTextOnPath(const SkDraw& draw, const void* text, michael@0: size_t len, const SkPath& path, michael@0: const SkMatrix* matrix, michael@0: const SkPaint& paint) { michael@0: draw.drawTextOnPath((const char*)text, len, path, matrix, paint); michael@0: } michael@0: michael@0: void SkBitmapDevice::drawVertices(const SkDraw& draw, SkCanvas::VertexMode vmode, michael@0: int vertexCount, michael@0: const SkPoint verts[], const SkPoint textures[], michael@0: const SkColor colors[], SkXfermode* xmode, michael@0: const uint16_t indices[], int indexCount, michael@0: const SkPaint& paint) { michael@0: draw.drawVertices(vmode, vertexCount, verts, textures, colors, xmode, michael@0: indices, indexCount, paint); michael@0: } michael@0: michael@0: void SkBitmapDevice::drawDevice(const SkDraw& draw, SkBaseDevice* device, michael@0: int x, int y, const SkPaint& paint) { michael@0: const SkBitmap& src = device->accessBitmap(false); michael@0: draw.drawSprite(src, x, y, paint); michael@0: } michael@0: michael@0: SkSurface* SkBitmapDevice::newSurface(const SkImageInfo& info) { michael@0: return SkSurface::NewRaster(info); michael@0: } michael@0: michael@0: const void* SkBitmapDevice::peekPixels(SkImageInfo* info, size_t* rowBytes) { michael@0: if (fBitmap.getPixels() && fBitmap.asImageInfo(info)) { michael@0: if (rowBytes) { michael@0: *rowBytes = fBitmap.rowBytes(); michael@0: } michael@0: return fBitmap.getPixels(); michael@0: } michael@0: return NULL; michael@0: } michael@0: michael@0: /////////////////////////////////////////////////////////////////////////////// michael@0: michael@0: bool SkBitmapDevice::filterTextFlags(const SkPaint& paint, TextFlags* flags) { michael@0: if (!paint.isLCDRenderText() || !paint.isAntiAlias()) { michael@0: // we're cool with the paint as is michael@0: return false; michael@0: } michael@0: michael@0: if (SkBitmap::kARGB_8888_Config != fBitmap.config() || michael@0: paint.getRasterizer() || michael@0: paint.getPathEffect() || michael@0: paint.isFakeBoldText() || michael@0: paint.getStyle() != SkPaint::kFill_Style || michael@0: !SkXfermode::IsMode(paint.getXfermode(), SkXfermode::kSrcOver_Mode)) { michael@0: // turn off lcd michael@0: flags->fFlags = paint.getFlags() & ~SkPaint::kLCDRenderText_Flag; michael@0: flags->fHinting = paint.getHinting(); michael@0: return true; michael@0: } michael@0: // we're cool with the paint as is michael@0: return false; michael@0: }