#include <QtGui/qpainterpath.h>
#include <QtCore/qstring.h>
#include <QtCore/qstack.h>
+#include <QtCore/qqueue.h>
#include <private/qv8engine_p.h>
-
+#include <QtCore/QWaitCondition>
//#define QQUICKCONTEXT2D_DEBUG //enable this for just DEBUG purpose!
class QQuickContext2DTexture;
class QQuickPixmap;
class QSGTexture;
+class QQuickWindowManager;
+class QSurface;
+class QOpenGLContext;
-class QLockedCommandBuffer {
-public:
- QLockedCommandBuffer(QQuickContext2DCommandBuffer *b);
- ~QLockedCommandBuffer();
- QQuickContext2DCommandBuffer* operator->() const;
-private:
- QQuickContext2DCommandBuffer *m_buffer;
-};
-
-class Q_QUICK_EXPORT QQuickContext2D : public QQuickCanvasContext
+class QQuickContext2D : public QQuickCanvasContext
{
public:
+ Q_DISABLE_COPY(QQuickContext2D)
+
enum TextBaseLineType { Alphabetic=0, Top, Middle, Bottom, Hanging};
enum TextAlignType { Start=0, End, Left, Right, Center};
enum PaintCommand {
FillText,
StrokeText,
DrawImage,
+ DrawPixmap,
GetImageData
};
, fillPatternRepeatY(false)
, strokePatternRepeatX(false)
, strokePatternRepeatY(false)
+ , invertibleCTM(true)
, fillRule(Qt::WindingFill)
, globalAlpha(1.0)
, lineWidth(1)
bool fillPatternRepeatY:1;
bool strokePatternRepeatX:1;
bool strokePatternRepeatY:1;
+ bool invertibleCTM:1;
Qt::FillRule fillRule;
qreal globalAlpha;
qreal lineWidth;
void prepare(const QSize& canvasSize, const QSize& tileSize, const QRect& canvasWindow, const QRect& dirtyRect, bool smooth);
void flush();
void sync();
+ QThread *thread() const {return m_thread;}
QSGDynamicTexture *texture() const;
QImage toImage(const QRectF& bounds);
void setV8Engine(QV8Engine *eng);
QQuickCanvasItem* canvas() const { return m_canvas; }
- QLockedCommandBuffer buffer() const { return m_buffer; }
+ QQuickContext2DCommandBuffer* buffer() const { return m_buffer; }
+ QQuickContext2DCommandBuffer* nextBuffer();
+
bool bufferValid() const { return m_buffer != 0; }
void popState();
void pushState();
void reset();
- // path API
+ void fill();
+ void clip();
+ void stroke();
+ void fillRect(qreal x, qreal y, qreal w, qreal h);
+ void strokeRect(qreal x, qreal y, qreal w, qreal h);
+ void clearRect(qreal x, qreal y, qreal w, qreal h);
+ void drawText(const QString& text, qreal x, qreal y, bool fill);
+
+ //Transform APIs
+ void scale(qreal x, qreal y);
+ void rotate(qreal angle);
+ void shear(qreal h, qreal v);
+ void translate(qreal x, qreal y);
+ void transform(qreal a, qreal b, qreal c, qreal d, qreal e, qreal f);
+ void setTransform(qreal a, qreal b, qreal c, qreal d, qreal e, qreal f);
+
+ // Path APIs
void beginPath();
void closePath();
void moveTo(qreal x, qreal y);
void text(const QString& str, qreal x, qreal y);
void arc(qreal x, qreal y, qreal radius,
qreal startAngle, qreal endAngle,
- bool anticlockwise, bool transform=true);
+ bool anticlockwise);
void addArcTo(const QPointF& p1, const QPointF& p2, float radius);
bool isPointInPath(qreal x, qreal y) const;
QPainterPath createTextGlyphs(qreal x, qreal y, const QString& text);
- QImage createImage(const QUrl& url);
+ QQmlRefPointer<QQuickCanvasPixmap> createPixmap(const QUrl& url);
+
+ QOpenGLContext *glContext() { return m_glContext; }
+ QSurface *surface() { return m_surface; }
+ void setGrabbedImage(const QImage& grab);
State state;
QStack<QQuickContext2D::State> m_stateStack;
v8::Local<v8::Value> m_strokeStyle;
v8::Handle<v8::Value> m_v8path;
QV8Engine *m_v8engine;
+ QQuickWindowManager *m_windowManager;
+ QSurface *m_surface;
+ QOpenGLContext *m_glContext;
v8::Persistent<v8::Object> m_v8value;
QQuickContext2DTexture *m_texture;
QQuickCanvasItem::RenderTarget m_renderTarget;
QQuickCanvasItem::RenderStrategy m_renderStrategy;
+ QQueue<QQuickContext2DCommandBuffer*> m_bufferQueue;
+ QThread *m_thread;
+ QImage m_grabbedImage;
+ bool m_grabbed:1;
+
+ QMutex m_mutex;
};