blob: caa361e2d85a27b6954f0994f9aee076baca78bf [file] [log] [blame]
chudy@google.com902ebe52012-06-29 14:21:22 +00001
2/*
3 * Copyright 2012 Google Inc.
4 *
5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file.
7 */
8
chudy@google.com607357f2012-08-07 16:12:23 +00009#include "SkDebugger.h"
chudy@google.com902ebe52012-06-29 14:21:22 +000010
chudy@google.com607357f2012-08-07 16:12:23 +000011SkDebugger::SkDebugger() {
12 // Create this some other dynamic way?
13 fDebugCanvas = new SkDebugCanvas(100, 100);
14 fPicture = NULL;
15 fPictureWidth = 0;
16 fPictureHeight = 0;
17 fIndex = 0;
18}
19
20SkDebugger::~SkDebugger() {
21 // Need to inherit from SkRef object in order for following to work
22 SkSafeUnref(fDebugCanvas);
23 SkSafeUnref(fPicture);
24}
25
26void SkDebugger::loadPicture(SkPicture* picture) {
27 fPictureWidth = picture->width();
28 fPictureHeight = picture->height();
29 delete fDebugCanvas;
30 fDebugCanvas = new SkDebugCanvas(fPictureWidth, fPictureHeight);
31 fDebugCanvas->setBounds(fPictureWidth, fPictureHeight);
32 picture->draw(fDebugCanvas);
33 fIndex = fDebugCanvas->getSize() - 1;
34 SkRefCnt_SafeAssign(fPicture, picture);
35}
36
robertphillips@google.com25bc2f82013-01-22 18:03:56 +000037SkPicture* SkDebugger::copyPicture() {
38 // We can't just call clone here since we want to removed the "deleted"
39 // commands. Playing back will strip those out.
40 SkPicture* newPicture = new SkPicture;
41 SkCanvas* canvas = newPicture->beginRecording(fPictureWidth, fPictureHeight);
chudy@google.com607357f2012-08-07 16:12:23 +000042 fDebugCanvas->draw(canvas);
robertphillips@google.com25bc2f82013-01-22 18:03:56 +000043 newPicture->endRecording();
44 return newPicture;
chudy@google.com902ebe52012-06-29 14:21:22 +000045}