DEF_TEST(Picture_BitmapLeak, r) { SkBitmap mut, immut; mut.allocN32Pixels(300, 200); immut.allocN32Pixels(300, 200); immut.setImmutable(); SkASSERT(!mut.isImmutable()); SkASSERT(immut.isImmutable()); // No one can hold a ref on our pixels yet. REPORTER_ASSERT(r, mut.pixelRef()->unique()); REPORTER_ASSERT(r, immut.pixelRef()->unique()); sk_sp<SkPicture> pic; { // we want the recorder to go out of scope before our subsequent checks, so we // place it inside local braces. SkPictureRecorder rec; SkCanvas* canvas = rec.beginRecording(1920, 1200); canvas->drawBitmap(mut, 0, 0); canvas->drawBitmap(immut, 800, 600); pic = rec.finishRecordingAsPicture(); } // The picture shares the immutable pixels but copies the mutable ones. REPORTER_ASSERT(r, mut.pixelRef()->unique()); REPORTER_ASSERT(r, !immut.pixelRef()->unique()); // When the picture goes away, it's just our bitmaps holding the refs. pic = nullptr; REPORTER_ASSERT(r, mut.pixelRef()->unique()); REPORTER_ASSERT(r, immut.pixelRef()->unique()); }
TEST_F(DeferredImageDecoderTest, drawIntoSkPictureProgressive) { RefPtr<SharedBuffer> partialData = SharedBuffer::create(m_data->data(), m_data->size() - 10); // Received only half the file. m_lazyDecoder->setData(*partialData, false); RefPtr<NativeImageSkia> image = m_lazyDecoder->frameBufferAtIndex(0)->asNewNativeImage(); SkPictureRecorder recorder; SkCanvas* tempCanvas = recorder.beginRecording(100, 100, 0, 0); tempCanvas->drawBitmap(image->bitmap(), 0, 0); RefPtr<SkPicture> picture = adoptRef(recorder.endRecording()); m_surface->getCanvas()->drawPicture(picture.get()); // Fully received the file and draw the SkPicture again. m_lazyDecoder->setData(*m_data, true); image = m_lazyDecoder->frameBufferAtIndex(0)->asNewNativeImage(); tempCanvas = recorder.beginRecording(100, 100, 0, 0); tempCanvas->drawBitmap(image->bitmap(), 0, 0); picture = adoptRef(recorder.endRecording()); m_surface->getCanvas()->drawPicture(picture.get()); SkBitmap canvasBitmap; canvasBitmap.allocN32Pixels(100, 100); ASSERT_TRUE(m_surface->getCanvas()->readPixels(&canvasBitmap, 0, 0)); SkAutoLockPixels autoLock(canvasBitmap); EXPECT_EQ(SkColorSetARGB(255, 255, 255, 255), canvasBitmap.getColor(0, 0)); }
/** * Test that for Jpeg files that use the JFIF colorspace, they are * directly embedded into the PDF (without re-encoding) when that * makes sense. */ DEF_TEST(PDFJpegEmbedTest, r) { const char test[] = "PDFJpegEmbedTest"; SkAutoTUnref<SkData> mandrillData( load_resource(r, test, "mandrill_512_q075.jpg")); SkAutoTUnref<SkData> cmykData(load_resource(r, test, "CMYK.jpg")); if (!mandrillData || !cmykData) { return; } SkDynamicMemoryWStream pdf; SkAutoTUnref<SkDocument> document(SkDocument::CreatePDF(&pdf)); SkCanvas* canvas = document->beginPage(642, 1028); canvas->clear(SK_ColorLTGRAY); SkBitmap bm1(bitmap_from_data(mandrillData)); canvas->drawBitmap(bm1, 65.0, 0.0, NULL); SkBitmap bm2(bitmap_from_data(cmykData)); canvas->drawBitmap(bm2, 0.0, 512.0, NULL); canvas->flush(); document->endPage(); document->close(); SkAutoTUnref<SkData> pdfData(pdf.copyToData()); SkASSERT(pdfData); pdf.reset(); REPORTER_ASSERT(r, is_subset_of(mandrillData, pdfData)); // This JPEG uses a nonstandard colorspace - it can not be // embedded into the PDF directly. REPORTER_ASSERT(r, !is_subset_of(cmykData, pdfData)); }
SkBitmap CCRenderSurfaceFilters::apply(const WebKit::WebFilterOperations& filters, unsigned textureId, const FloatSize& size, WebKit::WebGraphicsContext3D* context3D, GrContext* grContext) { if (!context3D || !grContext) return SkBitmap(); WebKit::WebFilterOperations optimizedFilters = optimize(filters); FilterBufferState state(grContext, size, textureId); if (!state.init(optimizedFilters.size())) return SkBitmap(); for (unsigned i = 0; i < optimizedFilters.size(); ++i) { const WebKit::WebFilterOperation& op = optimizedFilters.at(i); SkCanvas* canvas = state.canvas(); switch (op.type()) { case WebKit::WebFilterOperation::FilterTypeColorMatrix: { SkPaint paint; paint.setColorFilter(new SkColorMatrixFilter(op.matrix()))->unref(); canvas->drawBitmap(state.source(), 0, 0, &paint); break; } case WebKit::WebFilterOperation::FilterTypeBlur: { float stdDeviation = op.amount(); SkAutoTUnref<SkImageFilter> filter(new SkBlurImageFilter(stdDeviation, stdDeviation)); SkPaint paint; paint.setImageFilter(filter.get()); canvas->drawSprite(state.source(), 0, 0, &paint); break; } case WebKit::WebFilterOperation::FilterTypeDropShadow: { SkAutoTUnref<SkImageFilter> blurFilter(new SkBlurImageFilter(op.amount(), op.amount())); SkAutoTUnref<SkColorFilter> colorFilter(SkColorFilter::CreateModeFilter(op.dropShadowColor(), SkXfermode::kSrcIn_Mode)); SkPaint paint; paint.setImageFilter(blurFilter.get()); paint.setColorFilter(colorFilter.get()); paint.setXfermodeMode(SkXfermode::kSrcOver_Mode); canvas->saveLayer(0, &paint); canvas->drawBitmap(state.source(), op.dropShadowOffset().x, -op.dropShadowOffset().y); canvas->restore(); canvas->drawBitmap(state.source(), 0, 0); break; } case WebKit::WebFilterOperation::FilterTypeBrightness: case WebKit::WebFilterOperation::FilterTypeContrast: case WebKit::WebFilterOperation::FilterTypeGrayscale: case WebKit::WebFilterOperation::FilterTypeSepia: case WebKit::WebFilterOperation::FilterTypeSaturate: case WebKit::WebFilterOperation::FilterTypeHueRotate: case WebKit::WebFilterOperation::FilterTypeInvert: case WebKit::WebFilterOperation::FilterTypeOpacity: ASSERT_NOT_REACHED(); break; } state.swap(); } context3D->flush(); return state.source(); }
// crbug.com/295895 // Crashing in skia when a pixelref fails in lockPixels // static void test_faulty_pixelref(skiatest::Reporter* reporter) { // need a cache, but don't expect to use it, so the budget is not critical SkAutoTUnref<SkDiscardableMemoryPool> pool( SkDiscardableMemoryPool::Create(10 * 1000, nullptr)); SkBitmap bm; const SkImageInfo info = SkImageInfo::MakeN32Premul(100, 100); bm.setInfo(info); bm.setPixelRef(new FailurePixelRef(info), 0, 0)->unref(); // now our bitmap has a pixelref, but we know it will fail to lock auto surface(SkSurface::MakeRasterN32Premul(200, 200)); SkCanvas* canvas = surface->getCanvas(); const SkFilterQuality levels[] = { kNone_SkFilterQuality, kLow_SkFilterQuality, kMedium_SkFilterQuality, kHigh_SkFilterQuality, }; SkPaint paint; canvas->scale(2, 2); // need a scale, otherwise we may ignore filtering for (size_t i = 0; i < SK_ARRAY_COUNT(levels); ++i) { paint.setFilterQuality(levels[i]); canvas->drawBitmap(bm, 0, 0, &paint); } }
PictureView() { SkImageRef_GlobalPool::SetRAMBudget(16 * 1024); fBitmap = load_bitmap(); fPicture = new SkPicture; SkCanvas* canvas = fPicture->beginRecording(100, 100); SkPaint paint; paint.setAntiAlias(true); canvas->drawBitmap(fBitmap, 0, 0, NULL); drawCircle(canvas, 50, SK_ColorBLACK); fSubPicture = new SkPicture; canvas->drawPicture(*fSubPicture); canvas->translate(SkIntToScalar(50), 0); canvas->drawPicture(*fSubPicture); canvas->translate(0, SkIntToScalar(50)); canvas->drawPicture(*fSubPicture); canvas->translate(SkIntToScalar(-50), 0); canvas->drawPicture(*fSubPicture); // fPicture now has (4) references to us. We can release ours, and just // unref fPicture in our destructor, and it will in turn take care of // the other references to fSubPicture fSubPicture->unref(); }
// crbug.com/295895 // Crashing in skia when a pixelref fails in lockPixels // static void test_faulty_pixelref(skiatest::Reporter* reporter) { // need a cache, but don't expect to use it, so the budget is not critical SkAutoTUnref<SkDiscardableMemoryPool> pool( SkDiscardableMemoryPool::Create(10 * 1000, NULL)); SkBitmap bm; bool success = SkInstallDiscardablePixelRef(SkNEW(FailureImageGenerator), NULL, &bm, pool); REPORTER_ASSERT(reporter, success); // now our bitmap has a pixelref, but we know it will fail to lock SkAutoTUnref<SkSurface> surface(SkSurface::NewRasterN32Premul(200, 200)); SkCanvas* canvas = surface->getCanvas(); const SkFilterQuality levels[] = { kNone_SkFilterQuality, kLow_SkFilterQuality, kMedium_SkFilterQuality, kHigh_SkFilterQuality, }; SkPaint paint; canvas->scale(2, 2); // need a scale, otherwise we may ignore filtering for (size_t i = 0; i < SK_ARRAY_COUNT(levels); ++i) { paint.setFilterQuality(levels[i]); canvas->drawBitmap(bm, 0, 0, &paint); } }
bool FEBlend::platformApplySkia() { // For now, only use the skia implementation for accelerated rendering. if (filter()->renderingMode() != Accelerated) return false; FilterEffect* in = inputEffect(0); FilterEffect* in2 = inputEffect(1); if (!in || !in2) return false; ImageBuffer* resultImage = createImageBufferResult(); if (!resultImage) return false; RefPtr<Image> foreground = in->asImageBuffer()->copyImage(DontCopyBackingStore); RefPtr<Image> background = in2->asImageBuffer()->copyImage(DontCopyBackingStore); SkBitmap foregroundBitmap = foreground->nativeImageForCurrentFrame()->bitmap(); SkBitmap backgroundBitmap = background->nativeImageForCurrentFrame()->bitmap(); SkAutoTUnref<SkImageFilter> backgroundSource(new SkBitmapSource(backgroundBitmap)); SkBlendImageFilter::Mode mode = toSkiaMode(m_mode); SkAutoTUnref<SkImageFilter> blend(new SkBlendImageFilter(mode, backgroundSource)); SkPaint paint; paint.setImageFilter(blend); SkCanvas* canvas = resultImage->context()->platformContext()->canvas(); canvas->drawBitmap(foregroundBitmap, 0, 0, &paint); return true; }
TEST_F(DeferredImageDecoderTest, decodeOnOtherThread) { m_lazyDecoder->setData(*m_data, true); RefPtr<NativeImageSkia> image = m_lazyDecoder->frameBufferAtIndex(0)->asNewNativeImage(); EXPECT_EQ(1, image->bitmap().width()); EXPECT_EQ(1, image->bitmap().height()); EXPECT_FALSE(image->bitmap().isNull()); EXPECT_TRUE(image->bitmap().isImmutable()); SkPictureRecorder recorder; SkCanvas* tempCanvas = recorder.beginRecording(100, 100, 0, 0); tempCanvas->drawBitmap(image->bitmap(), 0, 0); RefPtr<SkPicture> picture = adoptRef(recorder.endRecording()); EXPECT_EQ(0, m_frameBufferRequestCount); // Create a thread to rasterize SkPicture. OwnPtr<WebThread> thread = adoptPtr(Platform::current()->createThread("RasterThread")); thread->postTask(new Task(WTF::bind(&rasterizeMain, m_surface->getCanvas(), picture.get()))); thread.clear(); EXPECT_EQ(0, m_frameBufferRequestCount); SkBitmap canvasBitmap; canvasBitmap.allocN32Pixels(100, 100); ASSERT_TRUE(m_surface->getCanvas()->readPixels(&canvasBitmap, 0, 0)); SkAutoLockPixels autoLock(canvasBitmap); EXPECT_EQ(SkColorSetARGB(255, 255, 255, 255), canvasBitmap.getColor(0, 0)); }
TEST_F(DeferredImageDecoderTest, drawIntoSkPicture) { m_lazyDecoder->setData(*m_data, true); SkBitmap bitmap; EXPECT_TRUE(m_lazyDecoder->createFrameAtIndex(0, &bitmap)); EXPECT_EQ(1, bitmap.width()); EXPECT_EQ(1, bitmap.height()); EXPECT_FALSE(bitmap.isNull()); EXPECT_TRUE(bitmap.isImmutable()); SkPictureRecorder recorder; SkCanvas* tempCanvas = recorder.beginRecording(100, 100, 0, 0); tempCanvas->drawBitmap(bitmap, 0, 0); RefPtr<SkPicture> picture = adoptRef(recorder.endRecording()); EXPECT_EQ(0, m_decodeRequestCount); m_surface->getCanvas()->drawPicture(picture.get()); EXPECT_EQ(0, m_decodeRequestCount); SkBitmap canvasBitmap; canvasBitmap.allocN32Pixels(100, 100); ASSERT_TRUE(m_surface->getCanvas()->readPixels(&canvasBitmap, 0, 0)); SkAutoLockPixels autoLock(canvasBitmap); EXPECT_EQ(SkColorSetARGB(255, 255, 255, 255), canvasBitmap.getColor(0, 0)); }
PictureView() { fBitmap = load_bitmap(); SkPictureRecorder recorder; recorder.beginRecording(100, 100, NULL, 0); fSubPicture = recorder.endRecording(); SkCanvas* canvas = recorder.beginRecording(100, 100, NULL, 0); SkPaint paint; paint.setAntiAlias(true); canvas->drawBitmap(fBitmap, 0, 0, NULL); drawCircle(canvas, 50, SK_ColorBLACK); canvas->drawPicture(fSubPicture); canvas->translate(SkIntToScalar(50), 0); canvas->drawPicture(fSubPicture); canvas->translate(0, SkIntToScalar(50)); canvas->drawPicture(fSubPicture); canvas->translate(SkIntToScalar(-50), 0); canvas->drawPicture(fSubPicture); fPicture = recorder.endRecording(); // fPicture now has (4) references to fSubPicture. We can release our ref, // and just unref fPicture in our destructor, and it will in turn take care of // the other references to fSubPicture fSubPicture->unref(); }
DEF_TEST(DontOptimizeSaveLayerDrawDrawRestore, reporter) { // This test is from crbug.com/344987. // The commands are: // saveLayer with paint that modifies alpha // drawBitmapRect // drawBitmapRect // restore // The bug was that this structure was modified so that: // - The saveLayer and restore were eliminated // - The alpha was only applied to the first drawBitmapRectToRect // This test draws blue and red squares inside a 50% transparent // layer. Both colours should show up muted. // When the bug is present, the red square (the second bitmap) // shows upwith full opacity. SkBitmap blueBM; make_bm(&blueBM, 100, 100, SkColorSetARGB(255, 0, 0, 255), true); SkBitmap redBM; make_bm(&redBM, 100, 100, SkColorSetARGB(255, 255, 0, 0), true); SkPaint semiTransparent; semiTransparent.setAlpha(0x80); SkPictureRecorder recorder; SkCanvas* canvas = recorder.beginRecording(100, 100); canvas->drawARGB(0, 0, 0, 0); canvas->saveLayer(0, &semiTransparent); canvas->drawBitmap(blueBM, 25, 25); canvas->drawBitmap(redBM, 50, 50); canvas->restore(); sk_sp<SkPicture> picture(recorder.finishRecordingAsPicture()); // Now replay the picture back on another canvas // and check a couple of its pixels. SkBitmap replayBM; make_bm(&replayBM, 100, 100, SK_ColorBLACK, false); SkCanvas replayCanvas(replayBM); picture->playback(&replayCanvas); replayCanvas.flush(); // With the bug present, at (55, 55) we would get a fully opaque red // intead of a dark red. REPORTER_ASSERT(reporter, replayBM.getColor(30, 30) == 0xff000080); REPORTER_ASSERT(reporter, replayBM.getColor(55, 55) == 0xff800000); }
static SkData* serialized_picture_from_bitmap(const SkBitmap& bitmap) { SkPicture picture; SkCanvas* canvas = picture.beginRecording(bitmap.width(), bitmap.height()); canvas->drawBitmap(bitmap, 0, 0); SkDynamicMemoryWStream wStream; picture.serialize(&wStream, &encode_bitmap_to_data); return wStream.copyToData(); }
/** * Test that for Jpeg files that use the JFIF colorspace, they are * directly embedded into the PDF (without re-encoding) when that * makes sense. */ DEF_TEST(PDFJpegEmbedTest, r) { const char test[] = "PDFJpegEmbedTest"; SkAutoTUnref<SkData> mandrillData( load_resource(r, test, "mandrill_512_q075.jpg")); SkAutoTUnref<SkData> cmykData(load_resource(r, test, "CMYK.jpg")); if (!mandrillData || !cmykData) { return; } SkDynamicMemoryWStream pdf; SkAutoTUnref<SkDocument> document(SkDocument::CreatePDF(&pdf)); SkCanvas* canvas = document->beginPage(642, 1028); canvas->clear(SK_ColorLTGRAY); SkBitmap bm1(bitmap_from_data(mandrillData)); canvas->drawBitmap(bm1, 65.0, 0.0, NULL); SkBitmap bm2(bitmap_from_data(cmykData)); canvas->drawBitmap(bm2, 0.0, 512.0, NULL); canvas->flush(); document->endPage(); document->close(); SkAutoTUnref<SkData> pdfData(pdf.copyToData()); SkASSERT(pdfData); pdf.reset(); // Test disabled, waiting on resolution to http://skbug.com/3180 // REPORTER_ASSERT(r, is_subset_of(mandrillData, pdfData)); // This JPEG uses a nonstandard colorspace - it can not be // embedded into the PDF directly. REPORTER_ASSERT(r, !is_subset_of(cmykData, pdfData)); // The following is for debugging purposes only. const char* outputPath = getenv("SKIA_TESTS_PDF_JPEG_EMBED_OUTPUT_PATH"); if (outputPath) { SkFILEWStream output(outputPath); if (output.isValid()) { output.write(pdfData->data(), pdfData->size()); } } }
// Main window drawing entry point void MainWindow::draw(SkCanvas& canvas) { // Clear background color //canvas.drawColor(SkColorSetARGB(255, 39, 40, 34)); // Calculate TabBar region SkRect tabCtrlRect = SkRect::MakeLTRB(0, 0, (SkScalar)this->Width, 33.0f); // Draw the TabBar region if needed m_tabCtrl.resize(tabCtrlRect); m_tabCtrl.paint(); canvas.drawBitmap(m_tabCtrl.getBitmap(), m_tabCtrl.getRect().left(), m_tabCtrl.getRect().top()); // Calculate CodeView region in the remaining space SkRect codeEditCtrlRect = SkRect::MakeLTRB(0, 33.0f, (SkScalar)this->Width, (SkScalar)this->Height); // Draw the TabBar region if needed m_codeEditCtrl.resize(codeEditCtrlRect); m_codeEditCtrl.paint(); canvas.drawBitmap(m_codeEditCtrl.getBitmap(), m_codeEditCtrl.getRect().left(), m_codeEditCtrl.getRect().top()); }
static void test_hierarchical(skiatest::Reporter* reporter) { SkBitmap bm; make_bm(&bm, 10, 10, SK_ColorRED, true); SkPictureRecorder recorder; recorder.beginRecording(10, 10); sk_sp<SkPicture> childPlain(recorder.finishRecordingAsPicture()); REPORTER_ASSERT(reporter, !childPlain->willPlayBackBitmaps()); // 0 recorder.beginRecording(10, 10)->drawBitmap(bm, 0, 0); sk_sp<SkPicture> childWithBitmap(recorder.finishRecordingAsPicture()); REPORTER_ASSERT(reporter, childWithBitmap->willPlayBackBitmaps()); // 1 { SkCanvas* canvas = recorder.beginRecording(10, 10); canvas->drawPicture(childPlain); sk_sp<SkPicture> parentPP(recorder.finishRecordingAsPicture()); REPORTER_ASSERT(reporter, !parentPP->willPlayBackBitmaps()); // 0 } { SkCanvas* canvas = recorder.beginRecording(10, 10); canvas->drawPicture(childWithBitmap); sk_sp<SkPicture> parentPWB(recorder.finishRecordingAsPicture()); REPORTER_ASSERT(reporter, parentPWB->willPlayBackBitmaps()); // 1 } { SkCanvas* canvas = recorder.beginRecording(10, 10); canvas->drawBitmap(bm, 0, 0); canvas->drawPicture(childPlain); sk_sp<SkPicture> parentWBP(recorder.finishRecordingAsPicture()); REPORTER_ASSERT(reporter, parentWBP->willPlayBackBitmaps()); // 1 } { SkCanvas* canvas = recorder.beginRecording(10, 10); canvas->drawBitmap(bm, 0, 0); canvas->drawPicture(childWithBitmap); sk_sp<SkPicture> parentWBWB(recorder.finishRecordingAsPicture()); REPORTER_ASSERT(reporter, parentWBWB->willPlayBackBitmaps()); // 2 } }
static SkData* serialized_picture_from_bitmap(const SkBitmap& bitmap) { SkPictureRecorder recorder; SkCanvas* canvas = recorder.beginRecording(SkIntToScalar(bitmap.width()), SkIntToScalar(bitmap.height())); canvas->drawBitmap(bitmap, 0, 0); SkAutoTUnref<SkPicture> picture(recorder.endRecording()); SkDynamicMemoryWStream wStream; sk_tool_utils::PngPixelSerializer serializer; picture->serialize(&wStream, &serializer); return wStream.copyToData(); }
// Only test this is in release mode. We deliberately crash in debug mode, since a valid caller // should never do this. static void test_bad_bitmap() { // This bitmap has a width and height but no pixels. As a result, attempting to record it will // fail. SkBitmap bm; bm.setConfig(SkBitmap::kARGB_8888_Config, 100, 100); SkPicture picture; SkCanvas* recordingCanvas = picture.beginRecording(100, 100); recordingCanvas->drawBitmap(bm, 0, 0); picture.endRecording(); SkCanvas canvas; canvas.drawPicture(picture); }
static SkData* serialized_picture_from_bitmap(const SkBitmap& bitmap) { SkPictureRecorder recorder; SkCanvas* canvas = recorder.beginRecording(SkIntToScalar(bitmap.width()), SkIntToScalar(bitmap.height())); canvas->drawBitmap(bitmap, 0, 0); sk_sp<SkPicture> picture(recorder.finishRecordingAsPicture()); SkDynamicMemoryWStream wStream; SkAutoTUnref<SkPixelSerializer> serializer( SkImageEncoder::CreatePixelSerializer()); picture->serialize(&wStream, serializer); return wStream.copyToData(); }
// Only test this is in release mode. We deliberately crash in debug mode, since a valid caller // should never do this. static void test_bad_bitmap() { // This bitmap has a width and height but no pixels. As a result, attempting to record it will // fail. SkBitmap bm; bm.setInfo(SkImageInfo::MakeN32Premul(100, 100)); SkPictureRecorder recorder; SkCanvas* recordingCanvas = recorder.beginRecording(100, 100); recordingCanvas->drawBitmap(bm, 0, 0); sk_sp<SkPicture> picture(recorder.finishRecordingAsPicture()); SkCanvas canvas; canvas.drawPicture(picture); }
void OsmAnd::MapRasterizer_P::rasterizePolylineIcons( const Context& context, SkCanvas& canvas, const SkPath& path, const MapStyleEvaluationResult& evalResult) { bool ok; QString pathIconName; ok = evalResult.getStringValue(context.env->styleBuiltinValueDefs->id_OUTPUT_PATH_ICON, pathIconName); if (!ok || pathIconName.isEmpty()) return; float pathIconStep = 0.0f; ok = evalResult.getFloatValue(context.env->styleBuiltinValueDefs->id_OUTPUT_PATH_ICON_STEP, pathIconStep); if (!ok || pathIconStep <= 0.0f) return; std::shared_ptr<const SkBitmap> pathIcon; ok = context.env->obtainMapIcon(pathIconName, pathIcon); if (!ok || !pathIcon) return; SkMatrix mIconTransform; mIconTransform.setIdentity(); mIconTransform.setTranslate(-0.5f * pathIcon->width(), -0.5f * pathIcon->height()); mIconTransform.postRotate(90.0f); SkPathMeasure pathMeasure(path, false); const auto length = pathMeasure.getLength(); auto iconOffset = 0.5f * pathIconStep; const auto iconInstancesCount = static_cast<int>((length - iconOffset) / pathIconStep) + 1; if (iconInstancesCount < 1) return; SkMatrix mIconInstanceTransform; for (auto iconInstanceIdx = 0; iconInstanceIdx < iconInstancesCount; iconInstanceIdx++, iconOffset += pathIconStep) { SkMatrix mPinPoint; ok = pathMeasure.getMatrix(iconOffset, &mPinPoint); if (!ok) break; mIconInstanceTransform.setConcat(mPinPoint, mIconTransform); canvas.save(); canvas.concat(mIconInstanceTransform); canvas.drawBitmap(*pathIcon, 0, 0, &_defaultPaint); canvas.restore(); } }
static void movie_draw(JNIEnv* env, jobject movie, jobject canvas, jfloat fx, jfloat fy, jobject jpaint) { NPE_CHECK_RETURN_VOID(env, movie); NPE_CHECK_RETURN_VOID(env, canvas); // its OK for paint to be null SkMovie* m = J2Movie(env, movie); SkCanvas* c = GraphicsJNI::getNativeCanvas(env, canvas); SkScalar sx = SkFloatToScalar(fx); SkScalar sy = SkFloatToScalar(fy); const SkBitmap& b = m->bitmap(); const SkPaint* p = jpaint ? GraphicsJNI::getNativePaint(env, jpaint) : NULL; c->drawBitmap(b, sx, sy, p); }
size_t count_bytes(const SkBitmap& bm, bool useDCT) { SkDynamicMemoryWStream stream; SkAutoTUnref<SkDocument> doc; if (useDCT) { SkAutoTUnref<SkPixelSerializer> serializer(new JPEGSerializer); doc.reset(SkDocument::CreatePDF( &stream, SK_ScalarDefaultRasterDPI, serializer)); } else { doc.reset(SkDocument::CreatePDF(&stream)); } SkCanvas* canvas = doc->beginPage(64, 64); canvas->drawBitmap(bm, 0, 0); doc->endPage(); doc->close(); return stream.bytesWritten(); }
void svg_renderer::update_drawing (const QTransform &transform, const QRectF &rect_to_update, int cache_object_type) { m_cache->lock (); DO_ON_EXIT (m_cache->unlock ()); double cache_zoom_x = m_cache->zoom_x (); double cache_zoom_y = m_cache->zoom_y (); double cur_zoom_x = transform.m11 (); double cur_zoom_y = transform.m22 (); QRectF rect_to_draw = rect_to_update; QTransform real_transform = transform; SkBitmap bitmap; bitmap.setConfig (SkBitmap::kARGB_8888_Config, rect_to_draw.width (), rect_to_draw.height ()); bitmap.allocPixels (); SkBitmapDevice device (bitmap); SkCanvas canvas (&device); if (!are_equal (cache_zoom_x, cur_zoom_x) || !are_equal (cache_zoom_y, cur_zoom_y)) { QTransform scale_transform = QTransform::fromScale (cache_zoom_x / cur_zoom_x, cache_zoom_y / cur_zoom_y); real_transform = real_transform * scale_transform; canvas.setMatrix (qt2skia::matrix (scale_transform.inverted ())); rect_to_draw = scale_transform.mapRect (rect_to_draw); } canvas.drawColor (SK_ColorTRANSPARENT, SkXfermode::kSrc_Mode); pair<render_cache_id, render_cache_id> it_pair = render_cache_id::get_id_for_pixel_rect (real_transform, rect_to_draw, cache_object_type); for (int x = it_pair.first.x (); x <= it_pair.second.x (); x++) for (int y = it_pair.first.y (); y <= it_pair.second.y (); y++) { render_cache_id cur_id (x, y, cache_object_type); SkBitmap bitmap = m_cache->bitmap (cur_id); if (bitmap.empty ()) continue; QRectF pixel_rect = cur_id.pixel_rect (real_transform); canvas.drawBitmap (bitmap, SkFloatToScalar (pixel_rect.x ()), SkFloatToScalar (pixel_rect.y ())); } m_cache->set_current_screen (bitmap, cache_object_type); }
// Ensure that pipe gracefully handles attempting to draw after endRecording is called on the // SkGPipeWriter. static void testDrawingAfterEndRecording(SkCanvas* canvas) { PipeController pc(canvas); SkGPipeWriter writer; SkCanvas* pipeCanvas = writer.startRecording(&pc, SkGPipeWriter::kCrossProcess_Flag); writer.endRecording(); SkBitmap bm; bm.setConfig(SkBitmap::kARGB_8888_Config, 2, 2); bm.allocPixels(); bm.eraseColor(SK_ColorTRANSPARENT); SkShader* shader = SkShader::CreateBitmapShader(bm, SkShader::kClamp_TileMode, SkShader::kClamp_TileMode); SkPaint paint; paint.setShader(shader)->unref(); pipeCanvas->drawPaint(paint); pipeCanvas->drawBitmap(bm, 0, 0); }
DEF_TEST(PDFInvalidBitmap, reporter) { SkDynamicMemoryWStream stream; SkAutoTUnref<SkDocument> document(SkDocument::CreatePDF(&stream)); SkCanvas* canvas = document->beginPage(100, 100); canvas->drawBitmap(SkBitmap(), 0, 0); canvas->drawBitmap(make_invalid_bitmap(SkImageInfo()), 0, 0); canvas->drawBitmap(make_invalid_bitmap(kN32_SkColorType), 0, 0); canvas->drawBitmap(make_invalid_bitmap(kIndex_8_SkColorType), 0, 0); canvas->drawBitmap(make_invalid_bitmap(kARGB_4444_SkColorType), 0, 0); canvas->drawBitmap(make_invalid_bitmap(kRGB_565_SkColorType), 0, 0); canvas->drawBitmap(make_invalid_bitmap(kAlpha_8_SkColorType), 0, 0); // This test passes if it does not crash. }
ECode Movie::Draw( /* [in] */ ICanvas* canvas, /* [in] */ Float x, /* [in] */ Float y, /* [in] */ IPaint* paint) { assert(canvas != NULL); // its OK for paint to be null // NPE_CHECK_RETURN_VOID(env, movie); // NPE_CHECK_RETURN_VOID(env, canvas); // // its OK for paint to be null SkMovie* m = ((SkMovie*)mNativeMovie); SkCanvas* c = GraphicsNative::GetNativeCanvas(canvas); const SkBitmap& b = m->bitmap(); const SkPaint* p = paint ? GraphicsNative::GetNativePaint(paint) : NULL; c->drawBitmap(b, x, y, p); return NOERROR; }
TEST_F(DeferredImageDecoderTest, decodedSize) { m_decodedSize = IntSize(22, 33); m_lazyDecoder->setData(*m_data, true); RefPtr<NativeImageSkia> image = m_lazyDecoder->frameBufferAtIndex(0)->asNewNativeImage(); EXPECT_EQ(m_decodedSize.width(), image->bitmap().width()); EXPECT_EQ(m_decodedSize.height(), image->bitmap().height()); EXPECT_FALSE(image->bitmap().isNull()); EXPECT_TRUE(image->bitmap().isImmutable()); useMockImageDecoderFactory(); // The following code should not fail any assert. SkPictureRecorder recorder; SkCanvas* tempCanvas = recorder.beginRecording(100, 100, 0, 0); tempCanvas->drawBitmap(image->bitmap(), 0, 0); RefPtr<SkPicture> picture = adoptRef(recorder.endRecording()); EXPECT_EQ(0, m_frameBufferRequestCount); m_surface->getCanvas()->drawPicture(picture.get()); EXPECT_EQ(1, m_frameBufferRequestCount); }
TEST_F(DeferredImageDecoderTest, decodedSize) { m_decodedSize = IntSize(22, 33); m_lazyDecoder->setData(*m_data, true); SkBitmap bitmap; EXPECT_TRUE(m_lazyDecoder->createFrameAtIndex(0, &bitmap)); EXPECT_EQ(m_decodedSize.width(), bitmap.width()); EXPECT_EQ(m_decodedSize.height(), bitmap.height()); EXPECT_FALSE(bitmap.isNull()); EXPECT_TRUE(bitmap.isImmutable()); useMockImageDecoderFactory(); // The following code should not fail any assert. SkPictureRecorder recorder; SkCanvas* tempCanvas = recorder.beginRecording(100, 100, 0, 0); tempCanvas->drawBitmap(bitmap, 0, 0); RefPtr<SkPicture> picture = adoptRef(recorder.endRecording()); EXPECT_EQ(0, m_decodeRequestCount); m_surface->getCanvas()->drawPicture(picture.get()); EXPECT_EQ(1, m_decodeRequestCount); }
void BitmapPattern::drawBitmapToCanvas(SkCanvas& canvas, SkPaint& paint) { canvas.drawBitmap(m_tileImage, SkIntToScalar(0), SkIntToScalar(0), &paint); }