SkDebugger.cpp revision 25bc2f86c2b94ee1f0921d90e6629d8cb22f69b7
1
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
9#include "SkDebugger.h"
10
11SkDebugger::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
37SkPicture* 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);
42    fDebugCanvas->draw(canvas);
43    newPicture->endRecording();
44    return newPicture;
45}
46