void QuiltTask::draw() { SkAutoTUnref<SkPicture> recorded(RecordPicture(fGM.get())); SkBitmap full; SetupBitmap(fReference.colorType(), fGM.get(), &full); SkCanvas fullCanvas(full); SkBitmap tile; tile.allocPixels(SkImageInfo::Make(FLAGS_quiltTile, FLAGS_quiltTile, fReference.colorType(), kPremul_SkAlphaType)); SkCanvas tileCanvas(tile); for (int y = 0; y < tiles_needed(full.height(), tile.height()); y++) { for (int x = 0; x < tiles_needed(full.width(), tile.width()); x++) { SkAutoCanvasRestore ar(&tileCanvas, true/*also save now*/); const SkScalar xOffset = SkIntToScalar(x * tile.width()), yOffset = SkIntToScalar(y * tile.height()); SkMatrix matrix = tileCanvas.getTotalMatrix(); matrix.postTranslate(-xOffset, -yOffset); tileCanvas.setMatrix(matrix); recorded->draw(&tileCanvas); tileCanvas.flush(); fullCanvas.drawBitmap(tile, xOffset, yOffset, NULL); } } if (!BitmapsEqual(full, fReference)) { this->fail(); this->spawnChild(SkNEW_ARGS(WriteTask, (*this, full))); } }
void ReplayTask::draw() { const uint32_t flags = fUseRTree ? SkPicture::kOptimizeForClippedPlayback_RecordingFlag : 0; SkAutoTUnref<SkPicture> recorded(RecordPicture(fGM.get(), flags)); SkBitmap bitmap; SetupBitmap(fReference.colorType(), fGM.get(), &bitmap); DrawPicture(recorded, &bitmap); if (!BitmapsEqual(bitmap, fReference)) { this->fail(); this->spawnChild(SkNEW_ARGS(WriteTask, (*this, bitmap))); } }
bool WriteTask::Expectations::check(const Task& task, SkBitmap bitmap) const { if (!FLAGS_writePath.isEmpty() && 0 == strcmp(FLAGS_writePath[0], fRoot)) { SkDebugf("We seem to be reading and writing %s concurrently. This won't work.\n", fRoot); return false; } const SkString path = path_to_expected_image(fRoot, task); SkBitmap expected; if (!PngAndRaw::Decode(path.c_str(), bitmap.info(), &expected)) { return false; } return BitmapsEqual(expected, bitmap); }
void SerializeTask::draw() { SkPicture recorded; RecordPicture(fGM.get(), &recorded); SkDynamicMemoryWStream wStream; recorded.serialize(&wStream, &trivial_bitmap_encoder); SkAutoTUnref<SkStream> rStream(wStream.detachAsStream()); SkAutoTUnref<SkPicture> reconstructed(SkPicture::CreateFromStream(rStream)); SkBitmap bitmap; SetupBitmap(fReference.config(), fGM.get(), &bitmap); DrawPicture(reconstructed, &bitmap); if (!BitmapsEqual(bitmap, fReference)) { this->fail(); this->spawnChild(SkNEW_ARGS(WriteTask, (*this, bitmap))); } }
void TileGridTask::draw() { const SkTileGridPicture::TileGridInfo info = { fTileSize, SkISize::Make(0,0), // Overlap between adjacent tiles. SkIPoint::Make(0,0), // Offset. }; const SkISize size = fGM->getISize(); SkTileGridPicture recorded(size.width(), size.height(), info); RecordPicture(fGM.get(), &recorded, SkPicture::kUsePathBoundsForClip_RecordingFlag); SkBitmap full; SetupBitmap(fReference.colorType(), fGM.get(), &full); SkCanvas fullCanvas(full); SkBitmap tile; tile.allocPixels(SkImageInfo::Make(fTileSize.width(), fTileSize.height(), fReference.colorType(), kPremul_SkAlphaType)); SkCanvas tileCanvas(tile); SkPaint paint; paint.setXfermodeMode(SkXfermode::kSrc_Mode); for (int y = 0; y < tiles_needed(full.height(), tile.height()); y++) { for (int x = 0; x < tiles_needed(full.width(), tile.width()); x++) { SkAutoCanvasRestore ar(&tileCanvas, true/*also save now*/); const SkScalar xOffset = SkIntToScalar(x * tile.width()), yOffset = SkIntToScalar(y * tile.height()); SkMatrix matrix = tileCanvas.getTotalMatrix(); matrix.postTranslate(-xOffset, -yOffset); tileCanvas.setMatrix(matrix); recorded.draw(&tileCanvas); tileCanvas.flush(); fullCanvas.drawBitmap(tile, xOffset, yOffset, &paint); } } if (!BitmapsEqual(full, fReference)) { this->fail(); this->spawnChild(SkNEW_ARGS(WriteTask, (*this, full))); } }
void PipeTask::draw() { SkBitmap bitmap; SetupBitmap(fReference.config(), fGM.get(), &bitmap); SkCanvas canvas(bitmap); PipeController pipeController(&canvas, &SkImageDecoder::DecodeMemory); SkGPipeWriter writer; SkCanvas* pipeCanvas = writer.startRecording(&pipeController, fFlags, bitmap.width(), bitmap.height()); pipeCanvas->concat(fGM->getInitialTransform()); fGM->draw(pipeCanvas); writer.endRecording(); if (!BitmapsEqual(bitmap, fReference)) { this->fail(); this->spawnChild(SkNEW_ARGS(WriteTask, (*this, bitmap))); } }