epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 1 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 2 | /* |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 3 | * Copyright 2010 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. |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 7 | */ |
| 8 | |
| 9 | |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 10 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 11 | #include "GrContext.h" |
| 12 | |
| 13 | #include "SkGpuCanvas.h" |
| 14 | #include "SkGpuDevice.h" |
| 15 | |
| 16 | /////////////////////////////////////////////////////////////////////////////// |
| 17 | |
mike@reedtribe.org | ea4ac97 | 2011-04-26 11:48:33 +0000 | [diff] [blame] | 18 | SkGpuCanvas::SkGpuCanvas(GrContext* context, GrRenderTarget* renderTarget) { |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 19 | SkASSERT(context); |
| 20 | fContext = context; |
| 21 | fContext->ref(); |
reed@google.com | cde9211 | 2011-07-06 20:00:52 +0000 | [diff] [blame] | 22 | |
| 23 | this->setDevice(new SkGpuDevice(context, renderTarget))->unref(); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 24 | } |
| 25 | |
| 26 | SkGpuCanvas::~SkGpuCanvas() { |
| 27 | // call this now, while our override of restore() is in effect |
| 28 | this->restoreToCount(1); |
| 29 | fContext->flush(false); |
| 30 | fContext->unref(); |
| 31 | } |
| 32 | |
| 33 | /////////////////////////////////////////////////////////////////////////////// |
| 34 | |
| 35 | bool SkGpuCanvas::getViewport(SkIPoint* size) const { |
| 36 | if (size) { |
| 37 | SkDevice* device = this->getDevice(); |
| 38 | if (device) { |
| 39 | size->set(device->width(), device->height()); |
| 40 | } else { |
| 41 | size->set(0, 0); |
| 42 | } |
| 43 | } |
| 44 | return true; |
| 45 | } |
| 46 | |