Intergrating QML and Skia (gpu backend)









up vote
0
down vote

favorite












I am trying to use skia with qml. I am inheriting from QQuickPaintedItem. I have modified this exanple, http://doc.qt.io/qt-5/qtquick-customitems-painteditem-example.html to use QQuickPaintedItem::FramebufferObject as renderTarget. I am trying to create SkSurface from existing texture from QQuickPaintedItem. I am always getting null. Please let me know If it is possible to use existing texture from qml item and use it for skia rendering.



main.cpp



#include <QGuiApplication>
#include <QQmlApplicationEngine>
#include "textballoon.h"

int main(int argc, char *argv)

QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);

QGuiApplication app(argc, argv);


QQmlApplicationEngine engine;
qmlRegisterType<TextBalloon>("com.sanjay.check", 1, 0, "TextBalloon");
engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
if (engine.rootObjects().isEmpty())
return -1;

return app.exec();



project.pro file



QT += quick
CONFIG += c++11

# The following define makes your compiler emit warnings if you use
# any feature of Qt which as been marked deprecated (the exact warnings
# depend on your compiler). Please consult the documentation of the
# deprecated API in order to know how to port your code away from it.
DEFINES += QT_DEPRECATED_WARNINGS

# You can also make your code fail to compile if you use deprecated APIs.
# In order to do so, uncomment the following line.
# You can also select to disable deprecated APIs only up to a certain version of Qt.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0

SOURCES +=
main.cpp
textballoon.cpp

RESOURCES += qml.qrc

# Additional import path used to resolve QML modules in Qt Creator's code model
QML_IMPORT_PATH =

# Additional import path used to resolve QML modules just for Qt Quick Designer
QML_DESIGNER_IMPORT_PATH =

# Default rules for deployment.
qnx: target.path = /tmp/$$TARGET/bin
else: unix:!android: target.path = /opt/$$TARGET/bin
!isEmpty(target.path): INSTALLS += target

HEADERS +=
textballoon.h

INCLUDEPATH +=
/home/sanju/skia/include/core
/home/sanju/skia/src/core
/home/sanju/skia/include/private
/home/sanju/skia/include/config
#/home/sanju/skia/tools/
/home/sanju/skia/include/gpu
/home/sanju/skia/src/gpu
/home/sanju/skia/src/gpu/gl
#/home/sanju/skia/include/effects
/home/sanju/skia/include/encode
/home/sanju/skia/include/utils

unix:!macx: LIBS += -L$$PWD/../../skia/out/Release/ -lskia

INCLUDEPATH += $$PWD/../../skia/out/Release
DEPENDPATH += $$PWD/../../skia/out/Release


Here is my modified textballoon.cpp file



#include "GrContext.h"
#include "gl/GrGLTypes.h"
//#include "GrGLTexture.h"

#include "textballoon.h"

#include "gl/GrGLInterface.h"
#include "SkData.h"
#include "SkImage.h"
#include "SkStream.h"
#include "SkSurface.h"
//#include "GrGpu.h"
#include "GrBackendSurface.h"
//#include "GrContextPriv.h"
//#include "GrGpu.h"

#include <QtDebug>
//! [0]
TextBalloon::TextBalloon(QQuickItem *parent)
: QQuickPaintedItem(parent)
, rightAligned(false)

setRenderTarget(QQuickPaintedItem::FramebufferObject);
setRightAligned(true);

QObject::connect(this, &QQuickPaintedItem::widthChanged, this, [this]()
// qDebug() << "textureChanged";
this->dirty = true;
);

//! [0]

//! [1]
void TextBalloon::paint(QPainter *painter)

QBrush brush(QColor("#007430"));

painter->setBrush(brush);
painter->setPen(Qt::NoPen);
painter->setRenderHint(QPainter::Antialiasing);

QSizeF itemSize = size();
painter->drawRoundedRect(0, 0, itemSize.width(), itemSize.height() - 10, 10, 10);

if (rightAligned)

const QPointF points[3] =
QPointF(itemSize.width() - 10.0, itemSize.height() - 10.0),
QPointF(itemSize.width() - 20.0, itemSize.height()),
QPointF(itemSize.width() - 30.0, itemSize.height() - 10.0),
;
painter->drawConvexPolygon(points, 3);

else

const QPointF points[3] =
QPointF(10.0, itemSize.height() - 10.0),
QPointF(20.0, itemSize.height()),
QPointF(30.0, itemSize.height() - 10.0),
;
painter->drawConvexPolygon(points, 3);


if(textureProvider())

sk_sp<const GrGLInterface> interface = nullptr;
// Leaving interface as null makes Skia extract pointers to OpenGL functions for the current
// context in a platform-specific way. Alternatively, you may create your own GrGLInterface and
// initialize it however you like to attach to an alternate OpenGL implementation or intercept
// Skia's OpenGL calls.
sk_sp<GrContext> context = GrContext::MakeGL(interface);
if (!context)
SkDebugf("GrContext::MakeGL returned nulln");


// GrGpu* gpu = context->contextPriv().getGpu();

QSGTexture* texture = textureProvider()->texture();
if(texture)

qDebug() << "Texture exist";
QSurfaceFormat format = QSurfaceFormat::defaultFormat();
QSize size = texture->textureSize();
qDebug() << size;


qDebug() << "Texture id " << texture->textureId() << " alpha channel " << texture->hasAlphaChannel()
<< "FORMAT RGB" << format.depthBufferSize() << " sample size " << format.samples();


GrGLTextureInfo info;
info.fID = texture->textureId();
info.fFormat = SkColorType::kUnknown_SkColorType;
GrBackendTexture grTexture(size.width(),
size.height(),
texture->hasMipmaps()? GrMipMapped::kYes : GrMipMapped::kNo,
info);

GrGLFramebufferInfo fboInfo;
fboInfo.fFBOID = texture->textureId();

auto surface = SkSurface::MakeFromBackendTexture(context.get(),
grTexture,
GrSurfaceOrigin::kTopLeft_GrSurfaceOrigin,
0,
SkColorType::kUnknown_SkColorType,
nullptr,
nullptr);

// GrGLFramebufferInfo fboInfo;
// fboInfo.fFBOID = texture->textureId();

// GrBackendRenderTarget backendTarget(size.width(),
// size.height(),
// 0,
// 0,
// fboInfo);
// auto surface = SkSurface::MakeFromBackendRenderTarget(context.get(),
// backendTarget,
// GrSurfaceOrigin::kTopLeft_GrSurfaceOrigin,
// SkColorType::kUnknown_SkColorType,
// nullptr,
// nullptr);
if(surface)

qDebug() << "Surface created";




//! [1]

bool TextBalloon::isRightAligned()

return this->rightAligned;


void TextBalloon::setRightAligned(bool rightAligned)

this->rightAligned = rightAligned;










share|improve this question

























    up vote
    0
    down vote

    favorite












    I am trying to use skia with qml. I am inheriting from QQuickPaintedItem. I have modified this exanple, http://doc.qt.io/qt-5/qtquick-customitems-painteditem-example.html to use QQuickPaintedItem::FramebufferObject as renderTarget. I am trying to create SkSurface from existing texture from QQuickPaintedItem. I am always getting null. Please let me know If it is possible to use existing texture from qml item and use it for skia rendering.



    main.cpp



    #include <QGuiApplication>
    #include <QQmlApplicationEngine>
    #include "textballoon.h"

    int main(int argc, char *argv)

    QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);

    QGuiApplication app(argc, argv);


    QQmlApplicationEngine engine;
    qmlRegisterType<TextBalloon>("com.sanjay.check", 1, 0, "TextBalloon");
    engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
    if (engine.rootObjects().isEmpty())
    return -1;

    return app.exec();



    project.pro file



    QT += quick
    CONFIG += c++11

    # The following define makes your compiler emit warnings if you use
    # any feature of Qt which as been marked deprecated (the exact warnings
    # depend on your compiler). Please consult the documentation of the
    # deprecated API in order to know how to port your code away from it.
    DEFINES += QT_DEPRECATED_WARNINGS

    # You can also make your code fail to compile if you use deprecated APIs.
    # In order to do so, uncomment the following line.
    # You can also select to disable deprecated APIs only up to a certain version of Qt.
    #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0

    SOURCES +=
    main.cpp
    textballoon.cpp

    RESOURCES += qml.qrc

    # Additional import path used to resolve QML modules in Qt Creator's code model
    QML_IMPORT_PATH =

    # Additional import path used to resolve QML modules just for Qt Quick Designer
    QML_DESIGNER_IMPORT_PATH =

    # Default rules for deployment.
    qnx: target.path = /tmp/$$TARGET/bin
    else: unix:!android: target.path = /opt/$$TARGET/bin
    !isEmpty(target.path): INSTALLS += target

    HEADERS +=
    textballoon.h

    INCLUDEPATH +=
    /home/sanju/skia/include/core
    /home/sanju/skia/src/core
    /home/sanju/skia/include/private
    /home/sanju/skia/include/config
    #/home/sanju/skia/tools/
    /home/sanju/skia/include/gpu
    /home/sanju/skia/src/gpu
    /home/sanju/skia/src/gpu/gl
    #/home/sanju/skia/include/effects
    /home/sanju/skia/include/encode
    /home/sanju/skia/include/utils

    unix:!macx: LIBS += -L$$PWD/../../skia/out/Release/ -lskia

    INCLUDEPATH += $$PWD/../../skia/out/Release
    DEPENDPATH += $$PWD/../../skia/out/Release


    Here is my modified textballoon.cpp file



    #include "GrContext.h"
    #include "gl/GrGLTypes.h"
    //#include "GrGLTexture.h"

    #include "textballoon.h"

    #include "gl/GrGLInterface.h"
    #include "SkData.h"
    #include "SkImage.h"
    #include "SkStream.h"
    #include "SkSurface.h"
    //#include "GrGpu.h"
    #include "GrBackendSurface.h"
    //#include "GrContextPriv.h"
    //#include "GrGpu.h"

    #include <QtDebug>
    //! [0]
    TextBalloon::TextBalloon(QQuickItem *parent)
    : QQuickPaintedItem(parent)
    , rightAligned(false)

    setRenderTarget(QQuickPaintedItem::FramebufferObject);
    setRightAligned(true);

    QObject::connect(this, &QQuickPaintedItem::widthChanged, this, [this]()
    // qDebug() << "textureChanged";
    this->dirty = true;
    );

    //! [0]

    //! [1]
    void TextBalloon::paint(QPainter *painter)

    QBrush brush(QColor("#007430"));

    painter->setBrush(brush);
    painter->setPen(Qt::NoPen);
    painter->setRenderHint(QPainter::Antialiasing);

    QSizeF itemSize = size();
    painter->drawRoundedRect(0, 0, itemSize.width(), itemSize.height() - 10, 10, 10);

    if (rightAligned)

    const QPointF points[3] =
    QPointF(itemSize.width() - 10.0, itemSize.height() - 10.0),
    QPointF(itemSize.width() - 20.0, itemSize.height()),
    QPointF(itemSize.width() - 30.0, itemSize.height() - 10.0),
    ;
    painter->drawConvexPolygon(points, 3);

    else

    const QPointF points[3] =
    QPointF(10.0, itemSize.height() - 10.0),
    QPointF(20.0, itemSize.height()),
    QPointF(30.0, itemSize.height() - 10.0),
    ;
    painter->drawConvexPolygon(points, 3);


    if(textureProvider())

    sk_sp<const GrGLInterface> interface = nullptr;
    // Leaving interface as null makes Skia extract pointers to OpenGL functions for the current
    // context in a platform-specific way. Alternatively, you may create your own GrGLInterface and
    // initialize it however you like to attach to an alternate OpenGL implementation or intercept
    // Skia's OpenGL calls.
    sk_sp<GrContext> context = GrContext::MakeGL(interface);
    if (!context)
    SkDebugf("GrContext::MakeGL returned nulln");


    // GrGpu* gpu = context->contextPriv().getGpu();

    QSGTexture* texture = textureProvider()->texture();
    if(texture)

    qDebug() << "Texture exist";
    QSurfaceFormat format = QSurfaceFormat::defaultFormat();
    QSize size = texture->textureSize();
    qDebug() << size;


    qDebug() << "Texture id " << texture->textureId() << " alpha channel " << texture->hasAlphaChannel()
    << "FORMAT RGB" << format.depthBufferSize() << " sample size " << format.samples();


    GrGLTextureInfo info;
    info.fID = texture->textureId();
    info.fFormat = SkColorType::kUnknown_SkColorType;
    GrBackendTexture grTexture(size.width(),
    size.height(),
    texture->hasMipmaps()? GrMipMapped::kYes : GrMipMapped::kNo,
    info);

    GrGLFramebufferInfo fboInfo;
    fboInfo.fFBOID = texture->textureId();

    auto surface = SkSurface::MakeFromBackendTexture(context.get(),
    grTexture,
    GrSurfaceOrigin::kTopLeft_GrSurfaceOrigin,
    0,
    SkColorType::kUnknown_SkColorType,
    nullptr,
    nullptr);

    // GrGLFramebufferInfo fboInfo;
    // fboInfo.fFBOID = texture->textureId();

    // GrBackendRenderTarget backendTarget(size.width(),
    // size.height(),
    // 0,
    // 0,
    // fboInfo);
    // auto surface = SkSurface::MakeFromBackendRenderTarget(context.get(),
    // backendTarget,
    // GrSurfaceOrigin::kTopLeft_GrSurfaceOrigin,
    // SkColorType::kUnknown_SkColorType,
    // nullptr,
    // nullptr);
    if(surface)

    qDebug() << "Surface created";




    //! [1]

    bool TextBalloon::isRightAligned()

    return this->rightAligned;


    void TextBalloon::setRightAligned(bool rightAligned)

    this->rightAligned = rightAligned;










    share|improve this question























      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      I am trying to use skia with qml. I am inheriting from QQuickPaintedItem. I have modified this exanple, http://doc.qt.io/qt-5/qtquick-customitems-painteditem-example.html to use QQuickPaintedItem::FramebufferObject as renderTarget. I am trying to create SkSurface from existing texture from QQuickPaintedItem. I am always getting null. Please let me know If it is possible to use existing texture from qml item and use it for skia rendering.



      main.cpp



      #include <QGuiApplication>
      #include <QQmlApplicationEngine>
      #include "textballoon.h"

      int main(int argc, char *argv)

      QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);

      QGuiApplication app(argc, argv);


      QQmlApplicationEngine engine;
      qmlRegisterType<TextBalloon>("com.sanjay.check", 1, 0, "TextBalloon");
      engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
      if (engine.rootObjects().isEmpty())
      return -1;

      return app.exec();



      project.pro file



      QT += quick
      CONFIG += c++11

      # The following define makes your compiler emit warnings if you use
      # any feature of Qt which as been marked deprecated (the exact warnings
      # depend on your compiler). Please consult the documentation of the
      # deprecated API in order to know how to port your code away from it.
      DEFINES += QT_DEPRECATED_WARNINGS

      # You can also make your code fail to compile if you use deprecated APIs.
      # In order to do so, uncomment the following line.
      # You can also select to disable deprecated APIs only up to a certain version of Qt.
      #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0

      SOURCES +=
      main.cpp
      textballoon.cpp

      RESOURCES += qml.qrc

      # Additional import path used to resolve QML modules in Qt Creator's code model
      QML_IMPORT_PATH =

      # Additional import path used to resolve QML modules just for Qt Quick Designer
      QML_DESIGNER_IMPORT_PATH =

      # Default rules for deployment.
      qnx: target.path = /tmp/$$TARGET/bin
      else: unix:!android: target.path = /opt/$$TARGET/bin
      !isEmpty(target.path): INSTALLS += target

      HEADERS +=
      textballoon.h

      INCLUDEPATH +=
      /home/sanju/skia/include/core
      /home/sanju/skia/src/core
      /home/sanju/skia/include/private
      /home/sanju/skia/include/config
      #/home/sanju/skia/tools/
      /home/sanju/skia/include/gpu
      /home/sanju/skia/src/gpu
      /home/sanju/skia/src/gpu/gl
      #/home/sanju/skia/include/effects
      /home/sanju/skia/include/encode
      /home/sanju/skia/include/utils

      unix:!macx: LIBS += -L$$PWD/../../skia/out/Release/ -lskia

      INCLUDEPATH += $$PWD/../../skia/out/Release
      DEPENDPATH += $$PWD/../../skia/out/Release


      Here is my modified textballoon.cpp file



      #include "GrContext.h"
      #include "gl/GrGLTypes.h"
      //#include "GrGLTexture.h"

      #include "textballoon.h"

      #include "gl/GrGLInterface.h"
      #include "SkData.h"
      #include "SkImage.h"
      #include "SkStream.h"
      #include "SkSurface.h"
      //#include "GrGpu.h"
      #include "GrBackendSurface.h"
      //#include "GrContextPriv.h"
      //#include "GrGpu.h"

      #include <QtDebug>
      //! [0]
      TextBalloon::TextBalloon(QQuickItem *parent)
      : QQuickPaintedItem(parent)
      , rightAligned(false)

      setRenderTarget(QQuickPaintedItem::FramebufferObject);
      setRightAligned(true);

      QObject::connect(this, &QQuickPaintedItem::widthChanged, this, [this]()
      // qDebug() << "textureChanged";
      this->dirty = true;
      );

      //! [0]

      //! [1]
      void TextBalloon::paint(QPainter *painter)

      QBrush brush(QColor("#007430"));

      painter->setBrush(brush);
      painter->setPen(Qt::NoPen);
      painter->setRenderHint(QPainter::Antialiasing);

      QSizeF itemSize = size();
      painter->drawRoundedRect(0, 0, itemSize.width(), itemSize.height() - 10, 10, 10);

      if (rightAligned)

      const QPointF points[3] =
      QPointF(itemSize.width() - 10.0, itemSize.height() - 10.0),
      QPointF(itemSize.width() - 20.0, itemSize.height()),
      QPointF(itemSize.width() - 30.0, itemSize.height() - 10.0),
      ;
      painter->drawConvexPolygon(points, 3);

      else

      const QPointF points[3] =
      QPointF(10.0, itemSize.height() - 10.0),
      QPointF(20.0, itemSize.height()),
      QPointF(30.0, itemSize.height() - 10.0),
      ;
      painter->drawConvexPolygon(points, 3);


      if(textureProvider())

      sk_sp<const GrGLInterface> interface = nullptr;
      // Leaving interface as null makes Skia extract pointers to OpenGL functions for the current
      // context in a platform-specific way. Alternatively, you may create your own GrGLInterface and
      // initialize it however you like to attach to an alternate OpenGL implementation or intercept
      // Skia's OpenGL calls.
      sk_sp<GrContext> context = GrContext::MakeGL(interface);
      if (!context)
      SkDebugf("GrContext::MakeGL returned nulln");


      // GrGpu* gpu = context->contextPriv().getGpu();

      QSGTexture* texture = textureProvider()->texture();
      if(texture)

      qDebug() << "Texture exist";
      QSurfaceFormat format = QSurfaceFormat::defaultFormat();
      QSize size = texture->textureSize();
      qDebug() << size;


      qDebug() << "Texture id " << texture->textureId() << " alpha channel " << texture->hasAlphaChannel()
      << "FORMAT RGB" << format.depthBufferSize() << " sample size " << format.samples();


      GrGLTextureInfo info;
      info.fID = texture->textureId();
      info.fFormat = SkColorType::kUnknown_SkColorType;
      GrBackendTexture grTexture(size.width(),
      size.height(),
      texture->hasMipmaps()? GrMipMapped::kYes : GrMipMapped::kNo,
      info);

      GrGLFramebufferInfo fboInfo;
      fboInfo.fFBOID = texture->textureId();

      auto surface = SkSurface::MakeFromBackendTexture(context.get(),
      grTexture,
      GrSurfaceOrigin::kTopLeft_GrSurfaceOrigin,
      0,
      SkColorType::kUnknown_SkColorType,
      nullptr,
      nullptr);

      // GrGLFramebufferInfo fboInfo;
      // fboInfo.fFBOID = texture->textureId();

      // GrBackendRenderTarget backendTarget(size.width(),
      // size.height(),
      // 0,
      // 0,
      // fboInfo);
      // auto surface = SkSurface::MakeFromBackendRenderTarget(context.get(),
      // backendTarget,
      // GrSurfaceOrigin::kTopLeft_GrSurfaceOrigin,
      // SkColorType::kUnknown_SkColorType,
      // nullptr,
      // nullptr);
      if(surface)

      qDebug() << "Surface created";




      //! [1]

      bool TextBalloon::isRightAligned()

      return this->rightAligned;


      void TextBalloon::setRightAligned(bool rightAligned)

      this->rightAligned = rightAligned;










      share|improve this question













      I am trying to use skia with qml. I am inheriting from QQuickPaintedItem. I have modified this exanple, http://doc.qt.io/qt-5/qtquick-customitems-painteditem-example.html to use QQuickPaintedItem::FramebufferObject as renderTarget. I am trying to create SkSurface from existing texture from QQuickPaintedItem. I am always getting null. Please let me know If it is possible to use existing texture from qml item and use it for skia rendering.



      main.cpp



      #include <QGuiApplication>
      #include <QQmlApplicationEngine>
      #include "textballoon.h"

      int main(int argc, char *argv)

      QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);

      QGuiApplication app(argc, argv);


      QQmlApplicationEngine engine;
      qmlRegisterType<TextBalloon>("com.sanjay.check", 1, 0, "TextBalloon");
      engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
      if (engine.rootObjects().isEmpty())
      return -1;

      return app.exec();



      project.pro file



      QT += quick
      CONFIG += c++11

      # The following define makes your compiler emit warnings if you use
      # any feature of Qt which as been marked deprecated (the exact warnings
      # depend on your compiler). Please consult the documentation of the
      # deprecated API in order to know how to port your code away from it.
      DEFINES += QT_DEPRECATED_WARNINGS

      # You can also make your code fail to compile if you use deprecated APIs.
      # In order to do so, uncomment the following line.
      # You can also select to disable deprecated APIs only up to a certain version of Qt.
      #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0

      SOURCES +=
      main.cpp
      textballoon.cpp

      RESOURCES += qml.qrc

      # Additional import path used to resolve QML modules in Qt Creator's code model
      QML_IMPORT_PATH =

      # Additional import path used to resolve QML modules just for Qt Quick Designer
      QML_DESIGNER_IMPORT_PATH =

      # Default rules for deployment.
      qnx: target.path = /tmp/$$TARGET/bin
      else: unix:!android: target.path = /opt/$$TARGET/bin
      !isEmpty(target.path): INSTALLS += target

      HEADERS +=
      textballoon.h

      INCLUDEPATH +=
      /home/sanju/skia/include/core
      /home/sanju/skia/src/core
      /home/sanju/skia/include/private
      /home/sanju/skia/include/config
      #/home/sanju/skia/tools/
      /home/sanju/skia/include/gpu
      /home/sanju/skia/src/gpu
      /home/sanju/skia/src/gpu/gl
      #/home/sanju/skia/include/effects
      /home/sanju/skia/include/encode
      /home/sanju/skia/include/utils

      unix:!macx: LIBS += -L$$PWD/../../skia/out/Release/ -lskia

      INCLUDEPATH += $$PWD/../../skia/out/Release
      DEPENDPATH += $$PWD/../../skia/out/Release


      Here is my modified textballoon.cpp file



      #include "GrContext.h"
      #include "gl/GrGLTypes.h"
      //#include "GrGLTexture.h"

      #include "textballoon.h"

      #include "gl/GrGLInterface.h"
      #include "SkData.h"
      #include "SkImage.h"
      #include "SkStream.h"
      #include "SkSurface.h"
      //#include "GrGpu.h"
      #include "GrBackendSurface.h"
      //#include "GrContextPriv.h"
      //#include "GrGpu.h"

      #include <QtDebug>
      //! [0]
      TextBalloon::TextBalloon(QQuickItem *parent)
      : QQuickPaintedItem(parent)
      , rightAligned(false)

      setRenderTarget(QQuickPaintedItem::FramebufferObject);
      setRightAligned(true);

      QObject::connect(this, &QQuickPaintedItem::widthChanged, this, [this]()
      // qDebug() << "textureChanged";
      this->dirty = true;
      );

      //! [0]

      //! [1]
      void TextBalloon::paint(QPainter *painter)

      QBrush brush(QColor("#007430"));

      painter->setBrush(brush);
      painter->setPen(Qt::NoPen);
      painter->setRenderHint(QPainter::Antialiasing);

      QSizeF itemSize = size();
      painter->drawRoundedRect(0, 0, itemSize.width(), itemSize.height() - 10, 10, 10);

      if (rightAligned)

      const QPointF points[3] =
      QPointF(itemSize.width() - 10.0, itemSize.height() - 10.0),
      QPointF(itemSize.width() - 20.0, itemSize.height()),
      QPointF(itemSize.width() - 30.0, itemSize.height() - 10.0),
      ;
      painter->drawConvexPolygon(points, 3);

      else

      const QPointF points[3] =
      QPointF(10.0, itemSize.height() - 10.0),
      QPointF(20.0, itemSize.height()),
      QPointF(30.0, itemSize.height() - 10.0),
      ;
      painter->drawConvexPolygon(points, 3);


      if(textureProvider())

      sk_sp<const GrGLInterface> interface = nullptr;
      // Leaving interface as null makes Skia extract pointers to OpenGL functions for the current
      // context in a platform-specific way. Alternatively, you may create your own GrGLInterface and
      // initialize it however you like to attach to an alternate OpenGL implementation or intercept
      // Skia's OpenGL calls.
      sk_sp<GrContext> context = GrContext::MakeGL(interface);
      if (!context)
      SkDebugf("GrContext::MakeGL returned nulln");


      // GrGpu* gpu = context->contextPriv().getGpu();

      QSGTexture* texture = textureProvider()->texture();
      if(texture)

      qDebug() << "Texture exist";
      QSurfaceFormat format = QSurfaceFormat::defaultFormat();
      QSize size = texture->textureSize();
      qDebug() << size;


      qDebug() << "Texture id " << texture->textureId() << " alpha channel " << texture->hasAlphaChannel()
      << "FORMAT RGB" << format.depthBufferSize() << " sample size " << format.samples();


      GrGLTextureInfo info;
      info.fID = texture->textureId();
      info.fFormat = SkColorType::kUnknown_SkColorType;
      GrBackendTexture grTexture(size.width(),
      size.height(),
      texture->hasMipmaps()? GrMipMapped::kYes : GrMipMapped::kNo,
      info);

      GrGLFramebufferInfo fboInfo;
      fboInfo.fFBOID = texture->textureId();

      auto surface = SkSurface::MakeFromBackendTexture(context.get(),
      grTexture,
      GrSurfaceOrigin::kTopLeft_GrSurfaceOrigin,
      0,
      SkColorType::kUnknown_SkColorType,
      nullptr,
      nullptr);

      // GrGLFramebufferInfo fboInfo;
      // fboInfo.fFBOID = texture->textureId();

      // GrBackendRenderTarget backendTarget(size.width(),
      // size.height(),
      // 0,
      // 0,
      // fboInfo);
      // auto surface = SkSurface::MakeFromBackendRenderTarget(context.get(),
      // backendTarget,
      // GrSurfaceOrigin::kTopLeft_GrSurfaceOrigin,
      // SkColorType::kUnknown_SkColorType,
      // nullptr,
      // nullptr);
      if(surface)

      qDebug() << "Surface created";




      //! [1]

      bool TextBalloon::isRightAligned()

      return this->rightAligned;


      void TextBalloon::setRightAligned(bool rightAligned)

      this->rightAligned = rightAligned;







      qt qml skia






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 11 at 14:58









      sanjay

      5581319




      5581319



























          active

          oldest

          votes











          Your Answer






          StackExchange.ifUsing("editor", function ()
          StackExchange.using("externalEditor", function ()
          StackExchange.using("snippets", function ()
          StackExchange.snippets.init();
          );
          );
          , "code-snippets");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "1"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













          draft saved

          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53249966%2fintergrating-qml-and-skia-gpu-backend%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown






























          active

          oldest

          votes













          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes















          draft saved

          draft discarded
















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.





          Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


          Please pay close attention to the following guidance:


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53249966%2fintergrating-qml-and-skia-gpu-backend%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Top Tejano songwriter Luis Silva dead of heart attack at 64

          ReactJS Fetched API data displays live - need Data displayed static

          政党