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))); } }
static void draw_raster(SkBenchmark* bench, SkColorType colorType) { SkBitmap bitmap; SetupBitmap(colorType, bench, &bitmap); SkCanvas canvas(bitmap); bench->preDraw(); bench->draw(1, &canvas); bench->postDraw(); }
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))); } }
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))); } }
void CpuTask::draw() { SkBitmap bitmap; SetupBitmap(fConfig, fGM.get(), &bitmap); SkCanvas canvas(bitmap); canvas.concat(fGM->getInitialTransform()); fGM->draw(&canvas); canvas.flush(); #define SPAWN(ChildTask, ...) this->spawnChild(SkNEW_ARGS(ChildTask, (*this, __VA_ARGS__))) SPAWN(ExpectationsTask, fExpectations, bitmap); SPAWN(PipeTask, fGMFactory(NULL), bitmap, false, false); SPAWN(PipeTask, fGMFactory(NULL), bitmap, true, false); SPAWN(PipeTask, fGMFactory(NULL), bitmap, true, true); SPAWN(ReplayTask, fGMFactory(NULL), bitmap, false); SPAWN(ReplayTask, fGMFactory(NULL), bitmap, true); SPAWN(SerializeTask, fGMFactory(NULL), bitmap); SPAWN(TileGridTask, fGMFactory(NULL), bitmap, SkISize::Make(16,16)); SPAWN(WriteTask, bitmap); #undef SPAWN }
void vtElevLayer::DrawLayerBitmap(wxDC *pDC, vtScaledView *pView) { if (!m_pGrid) return; // If we have grid data, but we don't yet have a bitmap to render it, then allocate if (m_pGrid->HasData() && m_pBitmap == NULL) SetupBitmap(pDC); if (m_pBitmap == NULL || !m_bBitmapRendered) { DrawLayerOutline(pDC, pView); return; } int iColumns, iRows; m_pGrid->GetDimensions(iColumns, iRows); DRECT screenrect = pView->WorldToCanvasD(m_pGrid->GetAreaExtents()); DRECT destRect = screenrect; wxRect srcRect(0, 0, m_ImageSize.x, m_ImageSize.y); double destRectW = (destRect.right - destRect.left); double destRectH = (destRect.bottom - destRect.top); double ratio_x = (float) srcRect.GetWidth() / destRectW; double ratio_y = (float) srcRect.GetHeight() / destRectH; #if 0 //clip stuff, so we only blit what we need int client_width, client_height; pView->GetClientSize(&client_width, &client_height); //get client window size if ((destRect.x + destRect.GetWidth() < 0) || (destRect.y + destRect.GetHeight() < 0) || (destRect.x > client_width) || (destRect.y > client_height)) //image completely off screen, return return; int diff; // clip left diff = 0 - destRect.x; if (diff > 0) { destRect.x += diff; srcRect.x += (long)(diff * ratio_x); } // clip top diff = 0 - destRect.y; if (diff > 0) { destRect.y += diff; srcRect.y += (long)(diff * ratio_y); } // clip right diff = destRect.x + destRect.GetWidth() - client_width; if (diff > 0) { destRect.width -= diff; srcRect.width -= (long)(diff * ratio_x); } // clip bottom diff = destRect.y + destRect.GetHeight() - client_height; if (diff > 0) { destRect.height -= diff; srcRect.height -= (long)(diff * ratio_y); } #endif bool bDrawNormal = true; #if WIN32 ::SetStretchBltMode((HDC) (pDC->GetHDC()), HALFTONE); if (!m_bHasMask) { // VTLOG("DrawBM %d, %d wh %d %d\n", (int) destRect.left, (int) destRect.top, // (int) destRectW, (int) destRectH); // Using StretchBlit is much faster and has less scaling/roundoff // problems than using the wx method DrawBitmap. However, GDI // won't stretch and mask at the same time! wxDC2 *pDC2 = (wxDC2 *) pDC; pDC2->StretchBlit(*m_pBitmap->m_pBitmap, destRect.left, destRect.top, destRectW, destRectH, srcRect.x, srcRect.y, srcRect.width, srcRect.height); bDrawNormal = false; } #endif if (bDrawNormal) { bool bUseDrawBitmap; #if wxCHECK_VERSION(2, 9, 0) bUseDrawBitmap = false; #else bUseDrawBitmap = true; // Older wx doesn't have StretchBlit #endif if (ratio_x > 1.0 && ratio_y > 1.0) bUseDrawBitmap = true; if (bUseDrawBitmap) { // Scale and draw the bitmap // Must use SetUserScale since wxWidgets doesn't provide StretchBlt? double scale_x = 1.0/ratio_x; double scale_y = 1.0/ratio_y; pDC->SetUserScale(scale_x, scale_y); // On Windows, this does a BitBlt (or MaskBlt if there is a mask) pDC->DrawBitmap(*m_pBitmap->m_pBitmap, (int) (destRect.left/scale_x), (int) (destRect.top/scale_y), m_bHasMask); // restore pDC->SetUserScale(1.0, 1.0); } #if wxCHECK_VERSION(2, 9, 0) else { // Create a memory DC; seems like a lot of overhead, but it also seems fast enough. wxMemoryDC temp_dc; temp_dc.SelectObject(*(m_pBitmap->m_pBitmap)); // Using StretchBlit seems to cause strange dark colors when zoomed out, but // that's better than the horizontal offset problems on zoomed-in that // resulted from using SetUserScale/DrawBitmap. pDC->StretchBlit(destRect.left, destRect.top, destRectW, destRectH, &temp_dc, srcRect.x, srcRect.y, srcRect.width, srcRect.height, wxCOPY, m_bHasMask); } #endif } }