blob: 7934c736c0f5045fc3c274f0d24f958d4c1e3454 [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
37SkPicture* SkDebugger::makePicture() {
38 SkSafeUnref(fPicture);
39 fPicture = new SkPicture();
40 SkCanvas* canvas = fPicture->beginRecording(fPictureWidth, fPictureHeight);
41 fDebugCanvas->draw(canvas);
42 fPicture->endRecording();
43 return fPicture;
chudy@google.com902ebe52012-06-29 14:21:22 +000044}