SkGLWidget.h revision 0b5bbb0f82e022c8acfbcb6312f0ed18e1ab90ce
1
2/*
3 * Copyright 2012 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#ifndef SKGLWIDGET_H_
11#define SKGLWIDGET_H_
12
13#include <QtOpenGL/QGLWidget>
14#include "SkDebugCanvas.h"
15#include "SkDevice.h"
16#include "SkGpuDevice.h"
17
18#include "GrContext.h"
19#include "gl/GrGLInterface.h"
20#include "gl/GrGLUtil.h"
21#include "GrRenderTarget.h"
22
23class SkGLWidget : public QGLWidget {
24
25public:
26    SkGLWidget();
27
28    ~SkGLWidget();
29
30    void setDebugCanvas(SkDebugCanvas* debugCanvas) {
31        fDebugCanvas = debugCanvas;
32        fIndex = debugCanvas->getSize() - 1;
33        this->updateGL();
34    }
35
36    void drawTo(int index) {
37        fIndex = index;
38        this->updateGL();
39    }
40
41    void setTranslate(SkIPoint translate) {
42        fTransform = translate;
43    }
44
45    void setScale(float scale) {
46        fScaleFactor = scale;
47    }
48
49protected:
50    void initializeGL();
51    void resizeGL(int w, int h);
52    void paintGL();
53
54
55private:
56    const GrGLInterface* fCurIntf;
57    GrContext* fCurContext;
58    SkGpuDevice* fGpuDevice;
59    SkCanvas* fCanvas;
60    SkDebugCanvas* fDebugCanvas;
61    int fIndex;
62    SkIPoint fTransform;
63    float fScaleFactor;
64    GrPlatformRenderTargetDesc getDesc(int w, int h);
65};
66
67#endif /* SKGLWIDGET_H_ */
68