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