Skip to content

Commit

Permalink
Refactor Canvas rendering paths.
Browse files Browse the repository at this point in the history
Refactor Canvas rendering paths to enable different drawing contexts.

Change-Id: If0e00a14baa673fca6b999a787b4e89885bb1e51
Reviewed-by: Yunqiao Yin <charles.yin@nokia.com>
  • Loading branch information
Justin McPherson authored and Qt by Nokia committed Feb 10, 2012
1 parent b06f7aa commit 66f740c
Show file tree
Hide file tree
Showing 26 changed files with 1,102 additions and 439 deletions.
2 changes: 1 addition & 1 deletion examples/declarative/canvas/bezierCurve/bezierCurve.qml
Expand Up @@ -65,7 +65,7 @@ Item {
property real rotate : rotateCtrl.value
smooth:true
renderTarget:Canvas.Image
renderInThread:false
renderStrategy: Canvas.Immediate


Behavior on scaleX { SpringAnimation { spring: 2; damping: 0.2; loops:Animation.Infinite } }
Expand Down
2 changes: 1 addition & 1 deletion examples/declarative/canvas/clip/clip.qml
Expand Up @@ -66,7 +66,7 @@ Item {
property string imagefile:"../contents/qt-logo.png"
smooth:true
renderTarget:Canvas.Image
renderInThread:false
renderStrategy: Canvas.Immediate
Component.onCompleted:loadImage(canvas.imagefile);

onAlphaChanged:requestPaint();
Expand Down
14 changes: 7 additions & 7 deletions examples/declarative/canvas/pixels/pixels.qml
Expand Up @@ -56,7 +56,7 @@ Item {
height:360
smooth:true
renderTarget:Canvas.FramebufferObject
renderInThread:false
renderStrategy: Canvas.Cooperative
property string image :"../contents/qt-logo.png"
Component.onCompleted:loadImage(image);
onImageLoaded:requestPaint();
Expand All @@ -66,12 +66,12 @@ Item {
if (canvas.isImageLoaded(image)) {
var pixels = ctx.createImageData(image);
//pixels.mirror();
pixels.filter(Canvas.GrayScale);
//pixels.filter(Canvas.Threshold, 100); //default 127
//pixels.filter(Canvas.Blur, 20); //default 10
//pixels.filter(Canvas.Opaque);
//pixels.filter(Canvas.Invert);
//pixels.filter(Canvas.Convolute, [0,-1,0,
pixels.filter(ctx.GrayScale);
//pixels.filter(ctx.Threshold, 100); //default 127
//pixels.filter(ctx.Blur, 20); //default 10
//pixels.filter(ctx.Opaque);
//pixels.filter(ctx.Invert);
//pixels.filter(ctx.Convolute, [0,-1,0,
// -1,5,-1,
// 0,-1,0]);
//ctx.putImageData(pixels, 0, 0, canvas.width, canvas.height);
Expand Down
Expand Up @@ -65,7 +65,7 @@ Item {
property real rotate : rotateCtrl.value
smooth:true
renderTarget:Canvas.Image
renderInThread:false
renderStrategy: Canvas.Immediate

onLineWidthChanged:requestPaint();
onFillChanged:requestPaint();
Expand Down
2 changes: 1 addition & 1 deletion examples/declarative/canvas/roundedrect/roundedrect.qml
Expand Up @@ -55,7 +55,7 @@ Item {
height:360
smooth:true
renderTarget:Canvas.Image
renderInThread:false
renderStrategy: Canvas.Immediate

property int radius: rCtrl.value
property int rectx: rxCtrl.value
Expand Down
2 changes: 1 addition & 1 deletion examples/declarative/canvas/smile/smile.qml
Expand Up @@ -56,7 +56,7 @@ Item {
height:360
smooth:true
renderTarget:Canvas.Image
renderInThread:false
renderStrategy: Canvas.Immediate

property string strokeStyle:"green"
property string fillStyle:"yellow"
Expand Down
2 changes: 1 addition & 1 deletion examples/declarative/canvas/squircle/squircle.qml
Expand Up @@ -61,7 +61,7 @@ Item {
height:360
smooth:true
renderTarget:Canvas.Image
renderInThread:false
renderStrategy: Canvas.Immediate

property string strokeStyle:"blue"
property string fillStyle:"steelblue"
Expand Down
2 changes: 1 addition & 1 deletion examples/declarative/canvas/stockchart/stock.qml
Expand Up @@ -337,8 +337,8 @@ Rectangle {
anchors.bottom : view.top
width:container.width;
opacity:0
renderInThread:false
renderTarget: Canvas.Image
renderStrategy: Canvas.Immediate
property bool running:false
property int frames:first
property int mouseX:0;
Expand Down
2 changes: 1 addition & 1 deletion examples/declarative/canvas/tiger/tiger.qml
Expand Up @@ -57,7 +57,7 @@ Item {
height:360
smooth:true
renderTarget:Canvas.FramebufferObject
renderInThread:false
renderStrategy: Canvas.Cooperative
property string strokeStyle:"steelblue"
property string fillStyle:"yellow"
property bool fill:true
Expand Down
2 changes: 1 addition & 1 deletion examples/declarative/canvas/twitterfriends/twitter.qml
Expand Up @@ -98,7 +98,7 @@ Rectangle {
anchors.bottom : parent.bottom
smooth:true
renderTarget:Canvas.Image
renderInThread:false
renderStrategy: Canvas.Immediate

property bool layoutChanged:true
property string twitterName:""
Expand Down
6 changes: 4 additions & 2 deletions src/quick/items/context2d/context2d.pri
@@ -1,15 +1,17 @@
SOURCES += \
$$PWD/qquickcanvasitem.cpp \
$$PWD/qquickcanvascontext.cpp \
$$PWD/qquickcontext2d.cpp \
$$PWD/qquickcontext2dnode.cpp \
$$PWD/qquickcanvasitemnode.cpp \
$$PWD/qquickcontext2dtile.cpp \
$$PWD/qquickcontext2dtexture.cpp \
$$PWD/qquickcontext2dcommandbuffer.cpp \

HEADERS += \
$$PWD/qquickcanvasitem_p.h \
$$PWD/qquickcanvascontext_p.h \
$$PWD/qquickcontext2d_p.h \
$$PWD/qquickcontext2dnode_p.h \
$$PWD/qquickcanvasitemnode_p.h \
$$PWD/qquickcontext2dtile_p.h \
$$PWD/qquickcontext2dtexture_p.h \
$$PWD/qquickcontext2dcommandbuffer_p.h \
Expand Down
75 changes: 75 additions & 0 deletions src/quick/items/context2d/qquickcanvascontext.cpp
@@ -0,0 +1,75 @@
/****************************************************************************
**
** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/
**
** This file is part of the QtDeclarative module of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
** GNU Lesser General Public License Usage
** This file may be used under the terms of the GNU Lesser General Public
** License version 2.1 as published by the Free Software Foundation and
** appearing in the file LICENSE.LGPL included in the packaging of this
** file. Please review the following information to ensure the GNU Lesser
** General Public License version 2.1 requirements will be met:
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU General
** Public License version 3.0 as published by the Free Software Foundation
** and appearing in the file LICENSE.GPL included in the packaging of this
** file. Please review the following information to ensure the GNU General
** Public License version 3.0 requirements will be met:
** http://www.gnu.org/copyleft/gpl.html.
**
** Other Usage
** Alternatively, this file may be used in accordance with the terms and
** conditions contained in a signed written agreement between you and Nokia.
**
**
**
**
**
**
** $QT_END_LICENSE$
**
****************************************************************************/

#include <private/qquickcanvascontext_p.h>


QT_BEGIN_NAMESPACE

QQuickCanvasContext::QQuickCanvasContext(QObject *parent)
: QObject(parent)
{
}

QQuickCanvasContext::~QQuickCanvasContext()
{
}

void QQuickCanvasContext::prepare(const QSize& canvasSize, const QSize& tileSize, const QRect& canvasWindow, const QRect& dirtyRect, bool smooth)
{
Q_UNUSED(canvasSize);
Q_UNUSED(tileSize);
Q_UNUSED(canvasWindow);
Q_UNUSED(dirtyRect);
Q_UNUSED(smooth);
}

void QQuickCanvasContext::flush()
{
}

void QQuickCanvasContext::sync()
{
}

QT_END_NAMESPACE


93 changes: 93 additions & 0 deletions src/quick/items/context2d/qquickcanvascontext_p.h
@@ -0,0 +1,93 @@
/****************************************************************************
**
** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/
**
** This file is part of the QtDeclarative module of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
** GNU Lesser General Public License Usage
** This file may be used under the terms of the GNU Lesser General Public
** License version 2.1 as published by the Free Software Foundation and
** appearing in the file LICENSE.LGPL included in the packaging of this
** file. Please review the following information to ensure the GNU Lesser
** General Public License version 2.1 requirements will be met:
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU General
** Public License version 3.0 as published by the Free Software Foundation
** and appearing in the file LICENSE.GPL included in the packaging of this
** file. Please review the following information to ensure the GNU General
** Public License version 3.0 requirements will be met:
** http://www.gnu.org/copyleft/gpl.html.
**
** Other Usage
** Alternatively, this file may be used in accordance with the terms and
** conditions contained in a signed written agreement between you and Nokia.
**
**
**
**
**
**
** $QT_END_LICENSE$
**
****************************************************************************/

#ifndef QQUICKCANVASCONTEXT_P_H
#define QQUICKCANVASCONTEXT_P_H

#include <QtQuick/qquickitem.h>
#include <private/qv8engine_p.h>


QT_BEGIN_HEADER

QT_BEGIN_NAMESPACE

class QQuickCanvasItem;
class QSGDynamicTexture;

class QQuickCanvasContextPrivate;
class QQuickCanvasContext : public QObject
{
Q_OBJECT

public:
QQuickCanvasContext(QObject *parent = 0);
~QQuickCanvasContext();

virtual QStringList contextNames() const = 0;

// Init (ignore options if necessary)
virtual void init(QQuickCanvasItem *canvasItem, const QVariantMap &args) = 0;

virtual void prepare(const QSize& canvasSize, const QSize& tileSize, const QRect& canvasWindow, const QRect& dirtyRect, bool smooth);

// Indicate this is a good time to begin composition
virtual void flush();

// Cause render (if necessary) to surface via execution unit
virtual void sync();

virtual void setV8Engine(QV8Engine *engine) = 0;
virtual v8::Handle<v8::Object> v8value() const = 0;

virtual QSGDynamicTexture *texture() const = 0;

virtual QImage toImage(const QRectF& bounds) = 0;

Q_SIGNALS:
void textureChanged();
};

QT_END_NAMESPACE

QT_END_HEADER

#endif //QQUICKCANVASCONTEXT_P_H

0 comments on commit 66f740c

Please sign in to comment.