1
2/*
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.
7 */
8
9
10
11#include "GrContext.h"
12
13#include "SkGpuCanvas.h"
14#include "SkGpuDevice.h"
15
16///////////////////////////////////////////////////////////////////////////////
17
18SkGpuCanvas::SkGpuCanvas(GrContext* context, GrRenderTarget* renderTarget) {
19    SkASSERT(context);
20    fContext = context;
21    fContext->ref();
22
23    this->setDevice(new SkGpuDevice(context, renderTarget))->unref();
24}
25
26SkGpuCanvas::~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
35bool 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
47