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 | |
| 25 | SkGpuCanvas::SkGpuCanvas(GrContext* context) { |
| 26 | SkASSERT(context); |
| 27 | fContext = context; |
| 28 | fContext->ref(); |
| 29 | } |
| 30 | |
| 31 | SkGpuCanvas::~SkGpuCanvas() { |
| 32 | // call this now, while our override of restore() is in effect |
| 33 | this->restoreToCount(1); |
| 34 | fContext->flush(false); |
| 35 | fContext->unref(); |
| 36 | } |
| 37 | |
| 38 | /////////////////////////////////////////////////////////////////////////////// |
| 39 | |
| 40 | bool SkGpuCanvas::getViewport(SkIPoint* size) const { |
| 41 | if (size) { |
| 42 | SkDevice* device = this->getDevice(); |
| 43 | if (device) { |
| 44 | size->set(device->width(), device->height()); |
| 45 | } else { |
| 46 | size->set(0, 0); |
| 47 | } |
| 48 | } |
| 49 | return true; |
| 50 | } |
| 51 | |
| 52 | SkDevice* SkGpuCanvas::createDevice(SkBitmap::Config config, int width, int height, |
| 53 | bool isOpaque, bool isLayer) { |
| 54 | SkBitmap bm; |
| 55 | bm.setConfig(config, width, height); |
| 56 | bm.setIsOpaque(isOpaque); |
| 57 | return new SkGpuDevice(this, bm, isLayer); |
| 58 | } |
| 59 | |
| 60 | |