chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 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 | |
chudy@google.com | 607357f | 2012-08-07 16:12:23 +0000 | [diff] [blame] | 9 | #include "SkDebugger.h" |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 10 | |
chudy@google.com | 607357f | 2012-08-07 16:12:23 +0000 | [diff] [blame] | 11 | SkDebugger::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 | |
| 20 | SkDebugger::~SkDebugger() { |
| 21 | // Need to inherit from SkRef object in order for following to work |
| 22 | SkSafeUnref(fDebugCanvas); |
| 23 | SkSafeUnref(fPicture); |
| 24 | } |
| 25 | |
| 26 | void 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 | |
| 37 | SkPicture* 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.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 44 | } |