void SkGridView::onDraw(SkCanvas* canvas) { this->INHERITED::onDraw(canvas); canvas->drawPaint(fPaint[kBG_Attr]); if (fSource == NULL) return; #if 0 int visibleCount = SkMin32(fVisibleRowCount, fSource->countRows() - fScrollIndex); if (visibleCount == 0) return; this->ensureStrCache(visibleCount); int currIndex = this->logicalToVisualIndex(fCurrIndex); #endif SkPaint p; for (int i = 0; i < fSource->countRows(); i++) { bool forced = false; SkEvent* evt = fSource->getEvent(i); SkASSERT(evt); SkString path(evt->findString("path")); delete evt; SkBitmapRef* bmr = SkBitmapRef::Decode(path.c_str(), false); if (bmr == NULL) { bmr = SkBitmapRef::Decode(path.c_str(), true); if (bmr) forced = true; } if (bmr) { SkAutoTDelete<SkBitmapRef> autoRef(bmr); SkRect r; if (!this->getCellRect(i, &r)) break; copybits(canvas, bmr->bitmap(), r, p); } // only draw one forced bitmap at a time if (forced) { this->inval(NULL); // could inval only the remaining visible cells... break; } } // draw the hilite { SkRect r; if (fCurrIndex >= 0 && this->getCellRect(fCurrIndex, &r)) canvas->drawRect(r, fPaint[kHiliteCell_Attr]); } }
/// M: added for HTML5-benchmark performance @{ PassRefPtr<Image> ImageBuffer::getContextImageRef() const { SkCanvas* canvas = imageBufferCanvas(this); if (!canvas) return 0; SkDevice* device = canvas->getDevice(); const SkBitmap& orig = device->accessBitmap(false); SkBitmapRef* ref = new SkBitmapRef(orig); RefPtr<Image> image = BitmapImage::create(ref, 0); ref->unref(); return image; }
SkShader* Pattern::platformPattern(const AffineTransform&) { if (m_pattern) return m_pattern; SkBitmapRef* ref = tileImage()->nativeImageForCurrentFrame(); if (!ref) return 0; m_pattern = SkShader::CreateBitmapShader(ref->bitmap(), toTileMode(m_repeatX), toTileMode(m_repeatY)); m_pattern->setLocalMatrix(m_patternSpaceTransformation); return m_pattern; }
void Image::drawPattern(GraphicsContext* ctxt, const FloatRect& tileRect, const TransformationMatrix& patternTransform, const FloatPoint& phase, CompositeOperator compositeOp, const FloatRect& destRect) { SkBitmapRef* image = this->nativeImageForCurrentFrame(); if (!image) { // If it's too early we won't have an image yet. return; } // in case we get called with an incomplete bitmap const SkBitmap& bitmap = image->bitmap(); if (bitmap.getPixels() == NULL && bitmap.pixelRef() == NULL) { return; } SkRect dstR; android_setrect(&dstR, destRect); if (dstR.isEmpty()) { return; } SkCanvas* canvas = ctxt->platformContext()->mCanvas; SkPaint paint; SkShader* shader = SkShader::CreateBitmapShader(bitmap, SkShader::kRepeat_TileMode, SkShader::kRepeat_TileMode); paint.setShader(shader)->unref(); // now paint is the only owner of shader paint.setPorterDuffXfermode(android_convert_compositeOp(compositeOp)); paint.setFilterBitmap(true); SkMatrix matrix(patternTransform); float scaleX = (float)image->origWidth() / bitmap.width(); float scaleY = (float)image->origHeight() / bitmap.height(); matrix.preScale(SkFloatToScalar(scaleX), SkFloatToScalar(scaleY)); matrix.postTranslate(SkFloatToScalar(phase.x()), SkFloatToScalar(phase.y())); shader->setLocalMatrix(matrix); canvas->drawRect(dstR, paint); #ifdef TRACE_SUBSAMPLED_BITMAPS if (bitmap.width() != image->origWidth() || bitmap.height() != image->origHeight()) { SkDebugf("--- Image::drawPattern [%d %d] orig [%d %d] dst [%g %g]\n", bitmap.width(), bitmap.height(), image->origWidth(), image->origHeight(), SkScalarToFloat(dstR.width()), SkScalarToFloat(dstR.height())); } #endif }
void BitmapImage::checkForSolidColor() { m_checkedForSolidColor = true; m_isSolidColor = false; if (frameCount() == 1) { SkBitmapRef* ref = frameAtIndex(0); if (!ref) { return; // keep solid == false } const SkBitmap& bm = ref->bitmap(); if (bm.width() != 1 || bm.height() != 1) { return; // keep solid == false } SkAutoLockPixels alp(bm); if (!bm.readyToDraw()) { return; // keep solid == false } SkPMColor color; switch (bm.getConfig()) { case SkBitmap::kARGB_8888_Config: color = *bm.getAddr32(0, 0); break; case SkBitmap::kRGB_565_Config: color = SkPixel16ToPixel32(*bm.getAddr16(0, 0)); break; case SkBitmap::kIndex8_Config: { SkColorTable* ctable = bm.getColorTable(); if (!ctable) { return; } color = (*ctable)[*bm.getAddr8(0, 0)]; break; } default: return; // keep solid == false } m_isSolidColor = true; m_solidColor = SkPMColorToWebCoreColor(color); } }
void BitmapImage::draw(GraphicsContext* ctxt, const FloatRect& dstRect, const FloatRect& srcRect, CompositeOperator compositeOp) { startAnimation(); SkBitmapRef* image = this->nativeImageForCurrentFrame(); if (!image) { // If it's too early we won't have an image yet. return; } // in case we get called with an incomplete bitmap const SkBitmap& bitmap = image->bitmap(); if (bitmap.getPixels() == NULL && bitmap.pixelRef() == NULL) { #ifdef TRACE_SKIPPED_BITMAPS SkDebugf("----- skip bitmapimage: [%d %d] pixels %p pixelref %p\n", bitmap.width(), bitmap.height(), bitmap.getPixels(), bitmap.pixelRef()); #endif return; } SkIRect srcR; SkRect dstR; float invScaleX = (float)bitmap.width() / image->origWidth(); float invScaleY = (float)bitmap.height() / image->origHeight(); android_setrect(&dstR, dstRect); android_setrect_scaled(&srcR, srcRect, invScaleX, invScaleY); if (srcR.isEmpty() || dstR.isEmpty()) { #ifdef TRACE_SKIPPED_BITMAPS SkDebugf("----- skip bitmapimage: [%d %d] src-empty %d dst-empty %d\n", bitmap.width(), bitmap.height(), srcR.isEmpty(), dstR.isEmpty()); #endif return; } SkCanvas* canvas = ctxt->platformContext()->mCanvas; SkPaint paint; paint.setFilterBitmap(true); paint.setPorterDuffXfermode(android_convert_compositeOp(compositeOp)); canvas->drawBitmapRect(bitmap, &srcR, dstR, &paint); #ifdef TRACE_SUBSAMPLED_BITMAPS if (bitmap.width() != image->origWidth() || bitmap.height() != image->origHeight()) { SkDebugf("--- BitmapImage::draw [%d %d] orig [%d %d]\n", bitmap.width(), bitmap.height(), image->origWidth(), image->origHeight()); } #endif }
PassRefPtr<Image> ImageBuffer::copyImage() const { ASSERT(context()); SkCanvas* canvas = imageBufferCanvas(this); if (!canvas) return 0; SkDevice* device = canvas->getDevice(); const SkBitmap& orig = device->accessBitmap(false); SkBitmap copy; if (PlatformBridge::canSatisfyMemoryAllocation(orig.getSize())) orig.copyTo(©, orig.config()); SkBitmapRef* ref = new SkBitmapRef(copy); RefPtr<Image> image = BitmapImage::create(ref, 0); ref->unref(); return image; }
void BitmapImage::draw(GraphicsContext* gc, const FloatRect& dstRect, const FloatRect& srcRect, ColorSpace, CompositeOperator compositeOp) { startAnimation(); SkBitmapRef* image = this->nativeImageForCurrentFrame(); if (!image) { // If it's too early we won't have an image yet. return; } // in case we get called with an incomplete bitmap const SkBitmap& bitmap = image->bitmap(); if (bitmap.getPixels() == NULL && bitmap.pixelRef() == NULL) { #ifdef TRACE_SKIPPED_BITMAPS SkDebugf("----- skip bitmapimage: [%d %d] pixels %p pixelref %p\n", bitmap.width(), bitmap.height(), bitmap.getPixels(), bitmap.pixelRef()); #endif return; } SkIRect srcR; SkRect dstR(dstRect); float invScaleX = (float)bitmap.width() / image->origWidth(); float invScaleY = (float)bitmap.height() / image->origHeight(); round_scaled(&srcR, srcRect, invScaleX, invScaleY); if (srcR.isEmpty() || dstR.isEmpty()) { #ifdef TRACE_SKIPPED_BITMAPS SkDebugf("----- skip bitmapimage: [%d %d] src-empty %d dst-empty %d\n", bitmap.width(), bitmap.height(), srcR.isEmpty(), dstR.isEmpty()); #endif return; } gc->platformContext()->drawBitmapRect(bitmap, &srcR, dstR, compositeOp); #ifdef TRACE_SUBSAMPLED_BITMAPS if (bitmap.width() != image->origWidth() || bitmap.height() != image->origHeight()) { SkDebugf("--- BitmapImage::draw [%d %d] orig [%d %d]\n", bitmap.width(), bitmap.height(), image->origWidth(), image->origHeight()); } #endif }
PassRefPtr<Image> ImageBuffer::copyImage() const { ASSERT(context() && context()->platformContext()); #if ENABLE(ACCELERATED_2D_CANVAS) context()->syncSoftwareCanvas(); #endif // Request for canvas bitmap; conversion required. if (context()->platformContext()->isRecording()) context()->platformContext()->convertToNonRecording(); SkCanvas* canvas = context()->platformContext()->mCanvas; SkDevice* device = canvas->getDevice(); const SkBitmap& orig = device->accessBitmap(false); SkBitmap copy; if (PlatformBridge::canSatisfyMemoryAllocation(orig.getSize())) orig.copyTo(©, orig.config()); SkBitmapRef* ref = new SkBitmapRef(copy); RefPtr<Image> image = BitmapImage::create(ref, 0); ref->unref(); return image; }
void Image::drawPattern(GraphicsContext* gc, const FloatRect& srcRect, const AffineTransform& patternTransform, const FloatPoint& phase, ColorSpace, CompositeOperator compositeOp, const FloatRect& destRect) { SkBitmapRef* image = this->nativeImageForCurrentFrame(); if (!image || destRect.isEmpty()) return; // in case we get called with an incomplete bitmap const SkBitmap& origBitmap = image->bitmap(); if (origBitmap.getPixels() == NULL && origBitmap.pixelRef() == NULL) return; SkIRect srcR; // we may have to scale if the image has been subsampled (so save RAM) bool imageIsSubSampled = image->origWidth() != origBitmap.width() || image->origHeight() != origBitmap.height(); float scaleX = 1; float scaleY = 1; if (imageIsSubSampled) { scaleX = (float)image->origWidth() / origBitmap.width(); scaleY = (float)image->origHeight() / origBitmap.height(); round_scaled(&srcR, srcRect, 1 / scaleX, 1 / scaleY); } else round(&srcR, srcRect); // now extract the proper subset of the src image SkBitmap bitmap; if (!origBitmap.extractSubset(&bitmap, srcR)) { SkDebugf("--- Image::drawPattern calling extractSubset failed\n"); return; } SkMatrix matrix(patternTransform); if (imageIsSubSampled) { matrix.preScale(SkFloatToScalar(scaleX), SkFloatToScalar(scaleY)); } // We also need to translate it such that the origin of the pattern is the // origin of the destination rect, which is what WebKit expects. Skia uses // the coordinate system origin as the base for the patter. If WebKit wants // a shifted image, it will shift it from there using the patternTransform. float tx = phase.x() + srcRect.x() * patternTransform.a(); float ty = phase.y() + srcRect.y() * patternTransform.d(); matrix.postTranslate(SkFloatToScalar(tx), SkFloatToScalar(ty)); gc->platformContext()->drawBitmapPattern(bitmap, matrix, compositeOp, destRect); }