ImageTexture::ImageTexture(SkBitmapRef* img) : m_imageRef(img) , m_image(0) , m_textureId(0) , m_refCount(0) { #ifdef DEBUG_COUNT ClassTracker::instance()->increment("ImageTexture"); #endif if (!m_imageRef) return; SkBitmap* bitmap = &m_imageRef->bitmap(); m_image = new SkBitmap(); int w = bitmap->width(); int h = bitmap->height(); m_image->setConfig(SkBitmap::kARGB_8888_Config, w, h); m_image->allocPixels(); SkDevice* device = new SkDevice(NULL, *m_image, false); SkCanvas canvas; canvas.setDevice(device); device->unref(); SkRect dest; dest.set(0, 0, w, h); m_image->setIsOpaque(false); m_image->eraseARGB(0, 0, 0, 0); canvas.drawBitmapRect(*bitmap, 0, dest); }
~DeviceCM() { if (NULL != fDevice) { fDevice->unlockPixels(); fDevice->unref(); } SkDELETE(fPaint); }
TiledPipeController::TiledPipeController(const SkBitmap& bitmap, const SkMatrix* initial) : INHERITED(NULL) { int32_t top = 0; int32_t bottom; int32_t height = bitmap.height() / NumberOfTiles; SkIRect rect; for (int i = 0; i < NumberOfTiles; i++) { bottom = i + 1 == NumberOfTiles ? bitmap.height() : top + height; rect.setLTRB(0, top, bitmap.width(), bottom); top = bottom; bool extracted = bitmap.extractSubset(&fBitmaps[i], rect); SkASSERT(extracted); SkDevice* device = new SkDevice(fBitmaps[i]); SkCanvas* canvas = new SkCanvas(device); device->unref(); if (initial != NULL) { canvas->setMatrix(*initial); } canvas->translate(SkIntToScalar(-rect.left()), SkIntToScalar(-rect.top())); if (0 == i) { fReader.setCanvas(canvas); } else { fReaders[i - 1].setCanvas(canvas); } canvas->unref(); } }
static SkBitmap createBitmap(const SkPath& path) { SkBitmap bitmap; bitmap.setConfig(SkBitmap::kARGB_8888_Config, SkImageWidget::kImageWidgetWidth, SkImageWidget::kImageWidgetHeight); bitmap.allocPixels(); bitmap.eraseColor(SK_ColorWHITE); SkDevice* device = new SkDevice(bitmap); SkCanvas canvas(device); device->unref(); const SkRect& bounds = path.getBounds(); if (bounds.width() > bounds.height()) { canvas.scale(SkDoubleToScalar((0.9*SkImageWidget::kImageWidgetWidth)/bounds.width()), SkDoubleToScalar((0.9*SkImageWidget::kImageWidgetHeight)/bounds.width())); } else { canvas.scale(SkDoubleToScalar((0.9*SkImageWidget::kImageWidgetWidth)/bounds.height()), SkDoubleToScalar((0.9*SkImageWidget::kImageWidgetHeight)/bounds.height())); } canvas.translate(-bounds.fLeft+2, -bounds.fTop+2); SkPaint p; p.setColor(SK_ColorBLACK); p.setStyle(SkPaint::kStroke_Style); canvas.drawPath(path, p); return bitmap; }
static void make_bitmap(SkBitmap* bitmap, GrContext* ctx, SkIRect* center) { SkDevice* dev; const int kFixed = 28; const int kStretchy = 8; const int kSize = 2*kFixed + kStretchy; #if SK_SUPPORT_GPU if (ctx) { dev = new SkGpuDevice(ctx, SkBitmap::kARGB_8888_Config, kSize, kSize); *bitmap = dev->accessBitmap(false); } else #endif { bitmap->setConfig(SkBitmap::kARGB_8888_Config, kSize, kSize); bitmap->allocPixels(); dev = new SkDevice(*bitmap); } SkCanvas canvas(dev); dev->unref(); canvas.clear(SK_ColorTRANSPARENT); SkRect r = SkRect::MakeWH(SkIntToScalar(kSize), SkIntToScalar(kSize)); const SkScalar strokeWidth = SkIntToScalar(6); const SkScalar radius = SkIntToScalar(kFixed) - strokeWidth/2; center->setXYWH(kFixed, kFixed, kStretchy, kStretchy); SkPaint paint; paint.setAntiAlias(true); paint.setColor(0xFFFF0000); canvas.drawRoundRect(r, radius, radius, paint); r.setXYWH(SkIntToScalar(kFixed), 0, SkIntToScalar(kStretchy), SkIntToScalar(kSize)); paint.setColor(0x8800FF00); canvas.drawRect(r, paint); r.setXYWH(0, SkIntToScalar(kFixed), SkIntToScalar(kSize), SkIntToScalar(kStretchy)); paint.setColor(0x880000FF); canvas.drawRect(r, paint); }
static SkBitmap createBitmap(const SkBitmap& input, const SkRect* srcRect) { SkBitmap bitmap; bitmap.setConfig(SkBitmap::kARGB_8888_Config, SkImageWidget::kImageWidgetWidth, SkImageWidget::kImageWidgetHeight); bitmap.allocPixels(); bitmap.eraseColor(SK_ColorLTGRAY); SkDevice* device = new SkDevice(bitmap); SkCanvas canvas(device); device->unref(); SkScalar xScale = (SkImageWidget::kImageWidgetWidth-2.0) / input.width(); SkScalar yScale = (SkImageWidget::kImageWidgetHeight-2.0) / input.height(); if (input.width() > input.height()) { yScale *= input.height() / (float) input.width(); } else { xScale *= input.width() / (float) input.height(); } SkRect dst = SkRect::MakeXYWH(SK_Scalar1, SK_Scalar1, xScale * input.width(), yScale * input.height()); canvas.drawBitmapRect(input, NULL, dst); if (NULL != srcRect) { SkRect r = SkRect::MakeLTRB(srcRect->fLeft * xScale + SK_Scalar1, srcRect->fTop * yScale + SK_Scalar1, srcRect->fRight * xScale + SK_Scalar1, srcRect->fBottom * yScale + SK_Scalar1); SkPaint p; p.setColor(SK_ColorRED); p.setStyle(SkPaint::kStroke_Style); canvas.drawRect(r, p); } return bitmap; }
void RasterRenderer::setupCanvas(const TileRenderInfo& renderInfo, SkCanvas* canvas) { if (renderInfo.baseTile->isLayerTile()) { g_bitmap->setIsOpaque(false); g_bitmap->eraseARGB(0, 0, 0, 0); } else { Color defaultBackground = Color::white; Color* background = renderInfo.tilePainter->background(); if (!background) { ALOGV("No background color for base layer!"); background = &defaultBackground; } ALOGV("setupCanvas use background on Base Layer %x", background->rgb()); g_bitmap->setIsOpaque(!background->hasAlpha()); g_bitmap->eraseARGB(background->alpha(), background->red(), background->green(), background->blue()); } SkDevice* device = new SkDevice(*g_bitmap); canvas->setDevice(device); device->unref(); }