void SkDebugCanvas::drawTo(SkCanvas* canvas, int index) { int counter = 0; SkASSERT(!fCommandVector.isEmpty()); SkASSERT(index < fCommandVector.count()); int i; // This only works assuming the canvas and device are the same ones that // were previously drawn into because they need to preserve all saves // and restores. if (fIndex < index) { i = fIndex + 1; } else { for (int j = 0; j < fOutstandingSaveCount; j++) { canvas->restore(); } i = 0; canvas->clear(SK_ColorTRANSPARENT); canvas->resetMatrix(); SkRect rect = SkRect::MakeWH(SkIntToScalar(fWidth), SkIntToScalar(fHeight)); canvas->clipRect(rect, SkRegion::kReplace_Op ); applyUserTransform(canvas); fOutstandingSaveCount = 0; } for (; i <= index; i++) { if (i == index && fFilter) { SkPaint p; p.setColor(0xAAFFFFFF); canvas->save(); canvas->resetMatrix(); SkRect mask; mask.set(SkIntToScalar(0), SkIntToScalar(0), SkIntToScalar(fWidth), SkIntToScalar(fHeight)); canvas->clipRect(mask, SkRegion::kReplace_Op, false); canvas->drawRectCoords(SkIntToScalar(0), SkIntToScalar(0), SkIntToScalar(fWidth), SkIntToScalar(fHeight), p); canvas->restore(); } if (fCommandVector[i]->isVisible()) { fCommandVector[i]->execute(canvas); fCommandVector[i]->trackSaveState(&fOutstandingSaveCount); } } fMatrix = canvas->getTotalMatrix(); fClip = canvas->getTotalClip().getBounds(); fIndex = index; }
int SkDebugCanvas::getCommandAtPoint(int x, int y, int index) { SkBitmap bitmap; bitmap.allocPixels(SkImageInfo::MakeN32Premul(1, 1)); SkCanvas canvas(bitmap); canvas.translate(SkIntToScalar(-x), SkIntToScalar(-y)); applyUserTransform(&canvas); int layer = 0; SkColor prev = bitmap.getColor(0,0); for (int i = 0; i < index; i++) { if (fCommandVector[i]->isVisible()) { fCommandVector[i]->execute(&canvas); } if (prev != bitmap.getColor(0,0)) { layer = i; } prev = bitmap.getColor(0,0); } return layer; }