reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1 | /* |
| 2 | Copyright 2010 Google Inc. |
| 3 | |
| 4 | Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | you may not use this file except in compliance with the License. |
| 6 | You may obtain a copy of the License at |
| 7 | |
| 8 | http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | |
| 10 | Unless required by applicable law or agreed to in writing, software |
| 11 | distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | See the License for the specific language governing permissions and |
| 14 | limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | |
| 18 | #include "GrContext.h" |
| 19 | |
| 20 | #include "SkGpuCanvas.h" |
| 21 | #include "SkGpuDevice.h" |
reed@google.com | 7b201d2 | 2011-01-11 18:59:23 +0000 | [diff] [blame] | 22 | #include "SkGpuDeviceFactory.h" |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 23 | |
| 24 | /////////////////////////////////////////////////////////////////////////////// |
| 25 | |
mike@reedtribe.org | ea4ac97 | 2011-04-26 11:48:33 +0000 | [diff] [blame] | 26 | SkGpuCanvas::SkGpuCanvas(GrContext* context, GrRenderTarget* renderTarget) { |
| 27 | SkDeviceFactory* factory = SkNEW_ARGS(SkGpuDeviceFactory, |
| 28 | (context, renderTarget)); |
| 29 | this->setDeviceFactory(factory)->unref(); |
reed@google.com | 7b201d2 | 2011-01-11 18:59:23 +0000 | [diff] [blame] | 30 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 31 | SkASSERT(context); |
| 32 | fContext = context; |
| 33 | fContext->ref(); |
| 34 | } |
| 35 | |
| 36 | SkGpuCanvas::~SkGpuCanvas() { |
| 37 | // call this now, while our override of restore() is in effect |
| 38 | this->restoreToCount(1); |
| 39 | fContext->flush(false); |
| 40 | fContext->unref(); |
| 41 | } |
| 42 | |
| 43 | /////////////////////////////////////////////////////////////////////////////// |
| 44 | |
| 45 | bool SkGpuCanvas::getViewport(SkIPoint* size) const { |
| 46 | if (size) { |
| 47 | SkDevice* device = this->getDevice(); |
| 48 | if (device) { |
| 49 | size->set(device->width(), device->height()); |
| 50 | } else { |
| 51 | size->set(0, 0); |
| 52 | } |
| 53 | } |
| 54 | return true; |
| 55 | } |
| 56 | |