aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/gpu/SkGpuCanvas.cpp
blob: fa573354c0cfcdad76dd223f977a0d2856fe5f1d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46

/*
 * Copyright 2010 Google Inc.
 *
 * Use of this source code is governed by a BSD-style license that can be
 * found in the LICENSE file.
 */



#include "GrContext.h"

#include "SkGpuCanvas.h"
#include "SkGpuDevice.h"

///////////////////////////////////////////////////////////////////////////////

SkGpuCanvas::SkGpuCanvas(GrContext* context, GrRenderTarget* renderTarget) {
    SkASSERT(context);
    fContext = context;
    fContext->ref();

    this->setDevice(new SkGpuDevice(context, renderTarget))->unref();
}

SkGpuCanvas::~SkGpuCanvas() {
    // call this now, while our override of restore() is in effect
    this->restoreToCount(1);
    fContext->flush(false);
    fContext->unref();
}

///////////////////////////////////////////////////////////////////////////////

bool SkGpuCanvas::getViewport(SkIPoint* size) const {
    if (size) {
        SkDevice* device = this->getDevice();
        if (device) {
            size->set(device->width(), device->height());
        } else {
            size->set(0, 0);
        }
    }
    return true;
}