|
Lines 27-36
a/Source/WebCore/platform/graphics/qt/GraphicsContext3DQt.cpp_sec1
|
| 27 |
#include "HTMLCanvasElement.h" |
27 |
#include "HTMLCanvasElement.h" |
| 28 |
#include "HostWindow.h" |
28 |
#include "HostWindow.h" |
| 29 |
#include "ImageBuffer.h" |
29 |
#include "ImageBuffer.h" |
|
|
30 |
#include "ImageData.h" |
| 30 |
#include "NotImplemented.h" |
31 |
#include "NotImplemented.h" |
| 31 |
#include "QWebPageClient.h" |
32 |
#include "PageClientQt.h" |
|
|
33 |
#include "qwebpage.h" |
| 32 |
#include <QAbstractScrollArea> |
34 |
#include <QAbstractScrollArea> |
|
|
35 |
#include <QGraphicsObject> |
| 33 |
#include <QGLContext> |
36 |
#include <QGLContext> |
|
|
37 |
#include <QStyleOptionGraphicsItem> |
| 34 |
#include <wtf/UnusedParam.h> |
38 |
#include <wtf/UnusedParam.h> |
| 35 |
#include <wtf/text/CString.h> |
39 |
#include <wtf/text/CString.h> |
| 36 |
|
40 |
|
|
Lines 145-157
typedef void (APIENTRY* glVertexAttrib4fType) (GLuint, const GLfloat, const GLfl
a/Source/WebCore/platform/graphics/qt/GraphicsContext3DQt.cpp_sec2
|
| 145 |
typedef void (APIENTRY* glVertexAttrib4fvType) (GLuint, const GLfloat*); |
149 |
typedef void (APIENTRY* glVertexAttrib4fvType) (GLuint, const GLfloat*); |
| 146 |
typedef void (APIENTRY* glVertexAttribPointerType) (GLuint, GLint, GLenum, GLboolean, GLsizei, const GLvoid*); |
150 |
typedef void (APIENTRY* glVertexAttribPointerType) (GLuint, GLint, GLenum, GLboolean, GLsizei, const GLvoid*); |
| 147 |
|
151 |
|
| 148 |
class GraphicsContext3DInternal { |
152 |
class GraphicsContext3DInternal : public QGraphicsObject { |
| 149 |
public: |
153 |
public: |
| 150 |
GraphicsContext3DInternal(GraphicsContext3D::Attributes attrs, HostWindow* hostWindow); |
154 |
GraphicsContext3DInternal(GraphicsContext3D::Attributes attrs, HostWindow* hostWindow); |
| 151 |
~GraphicsContext3DInternal(); |
155 |
~GraphicsContext3DInternal(); |
| 152 |
|
156 |
|
| 153 |
bool isContextValid() { return m_contextValid; } |
157 |
bool isContextValid() { return m_contextValid; } |
| 154 |
QGLWidget* getOwnerGLWidget(QWebPageClient* webPageClient); |
158 |
QGLWidget* getOwnerGLWidget(QWebPageClient* webPageClient); |
|
|
159 |
void paint(QPainter*, const QStyleOptionGraphicsItem*, QWidget*); |
| 160 |
QRectF boundingRect() const; |
| 155 |
|
161 |
|
| 156 |
glActiveTextureType activeTexture; |
162 |
glActiveTextureType activeTexture; |
| 157 |
glAttachShaderType attachShader; |
163 |
glAttachShaderType attachShader; |
|
Lines 247-252
public:
a/Source/WebCore/platform/graphics/qt/GraphicsContext3DQt.cpp_sec3
|
| 247 |
GraphicsContext3D::Attributes m_attrs; |
253 |
GraphicsContext3D::Attributes m_attrs; |
| 248 |
HostWindow* m_hostWindow; |
254 |
HostWindow* m_hostWindow; |
| 249 |
QGLWidget* m_glWidget; |
255 |
QGLWidget* m_glWidget; |
|
|
256 |
QGLWidget* m_ownerGLWidget; |
| 257 |
QRectF m_boundingRect; |
| 250 |
GLuint m_texture; |
258 |
GLuint m_texture; |
| 251 |
GLuint m_mainFbo; |
259 |
GLuint m_mainFbo; |
| 252 |
GLuint m_currentFbo; |
260 |
GLuint m_currentFbo; |
|
Lines 281-297
GraphicsContext3DInternal::GraphicsContext3DInternal(GraphicsContext3D::Attribut
a/Source/WebCore/platform/graphics/qt/GraphicsContext3DQt.cpp_sec4
|
| 281 |
: m_attrs(attrs) |
289 |
: m_attrs(attrs) |
| 282 |
, m_hostWindow(hostWindow) |
290 |
, m_hostWindow(hostWindow) |
| 283 |
, m_glWidget(0) |
291 |
, m_glWidget(0) |
|
|
292 |
, m_ownerGLWidget(0) |
| 284 |
, m_texture(0) |
293 |
, m_texture(0) |
| 285 |
, m_mainFbo(0) |
294 |
, m_mainFbo(0) |
| 286 |
, m_currentFbo(0) |
295 |
, m_currentFbo(0) |
| 287 |
, m_depthBuffer(0) |
296 |
, m_depthBuffer(0) |
| 288 |
, m_contextValid(true) |
297 |
, m_contextValid(true) |
| 289 |
{ |
298 |
{ |
| 290 |
QWebPageClient* webPageClient = hostWindow->platformPageClient(); |
299 |
PageClientQWidget* webPageClient |
| 291 |
QGLWidget* ownerGLWidget = getOwnerGLWidget(webPageClient); |
300 |
= static_cast<PageClientQWidget*>(hostWindow->platformPageClient()); |
| 292 |
|
301 |
|
| 293 |
if (ownerGLWidget) |
302 |
#if USE(ACCELERATED_COMPOSITING) |
| 294 |
m_glWidget = new QGLWidget(0, ownerGLWidget); |
303 |
if (webPageClient->page->settings()->testAttribute(QWebSettings::AcceleratedCompositingEnabled)) { |
|
|
304 |
QAbstractScrollArea* scrollArea = qobject_cast<QAbstractScrollArea*>(webPageClient->ownerWidget()); |
| 305 |
if (scrollArea) |
| 306 |
m_ownerGLWidget = qobject_cast<QGLWidget*>(scrollArea->viewport()); |
| 307 |
} |
| 308 |
#endif |
| 309 |
|
| 310 |
if (m_ownerGLWidget) |
| 311 |
m_glWidget = new QGLWidget(0, m_ownerGLWidget); |
| 295 |
else { |
312 |
else { |
| 296 |
QGLFormat format; |
313 |
QGLFormat format; |
| 297 |
format.setDepth(true); |
314 |
format.setDepth(true); |
|
Lines 454-467
GraphicsContext3DInternal::~GraphicsContext3DInternal()
a/Source/WebCore/platform/graphics/qt/GraphicsContext3DQt.cpp_sec5
|
| 454 |
m_glWidget = 0; |
471 |
m_glWidget = 0; |
| 455 |
} |
472 |
} |
| 456 |
|
473 |
|
| 457 |
QGLWidget* GraphicsContext3DInternal::getOwnerGLWidget(QWebPageClient* webPageClient) |
474 |
void GraphicsContext3DInternal::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget) |
| 458 |
{ |
475 |
{ |
| 459 |
QAbstractScrollArea* scrollArea = qobject_cast<QAbstractScrollArea*>(webPageClient->ownerWidget()); |
476 |
Q_UNUSED(widget); |
| 460 |
|
477 |
|
| 461 |
if (scrollArea) |
478 |
QRectF rect = option ? option->rect : boundingRect(); |
| 462 |
return qobject_cast<QGLWidget*>(scrollArea->viewport()); |
|
|
| 463 |
|
479 |
|
| 464 |
return 0; |
480 |
#if QT_VERSION >= QT_VERSION_CHECK(4, 7, 0) |
|
|
481 |
// Use direct texture mapping if WebGL canvas has a shared OpenGL context |
| 482 |
// with browsers OpenGL context. |
| 483 |
if (m_ownerGLWidget) { |
| 484 |
m_ownerGLWidget->drawTexture(rect, m_texture); |
| 485 |
return; |
| 486 |
} |
| 487 |
#endif |
| 488 |
|
| 489 |
// Alternatively read pixels to a memory buffer. |
| 490 |
m_glWidget->makeCurrent(); |
| 491 |
bindFramebuffer(GraphicsContext3D::FRAMEBUFFER, m_mainFbo); |
| 492 |
glReadPixels(/* x */ 0, /* y */ 0, rect.width(), rect.height(), GraphicsContext3D::RGBA, GraphicsContext3D::UNSIGNED_BYTE, m_pixels.bits()); |
| 493 |
painter->drawImage(/* x */ 0, /* y */ 0, m_pixels.rgbSwapped().transformed(QMatrix().rotate(180))); |
| 494 |
bindFramebuffer(GraphicsContext3D::FRAMEBUFFER, m_currentFbo); |
| 495 |
} |
| 496 |
|
| 497 |
QRectF GraphicsContext3DInternal::boundingRect() const |
| 498 |
{ |
| 499 |
return m_boundingRect; |
| 465 |
} |
500 |
} |
| 466 |
|
501 |
|
| 467 |
void* GraphicsContext3DInternal::getProcAddress(const String& proc) |
502 |
void* GraphicsContext3DInternal::getProcAddress(const String& proc) |
|
Lines 511-516
Platform3DObject GraphicsContext3D::platformTexture() const
a/Source/WebCore/platform/graphics/qt/GraphicsContext3DQt.cpp_sec6
|
| 511 |
return m_internal->m_texture; |
546 |
return m_internal->m_texture; |
| 512 |
} |
547 |
} |
| 513 |
|
548 |
|
|
|
549 |
PlatformLayer* GraphicsContext3D::platformLayer() const |
| 550 |
{ |
| 551 |
return m_internal.get(); |
| 552 |
} |
| 553 |
|
| 514 |
void GraphicsContext3D::makeContextCurrent() |
554 |
void GraphicsContext3D::makeContextCurrent() |
| 515 |
{ |
555 |
{ |
| 516 |
m_internal->m_glWidget->makeCurrent(); |
556 |
m_internal->m_glWidget->makeCurrent(); |
|
Lines 522-528
void GraphicsContext3D::paintRenderingResultsToCanvas(CanvasRenderingContext* co
a/Source/WebCore/platform/graphics/qt/GraphicsContext3DQt.cpp_sec7
|
| 522 |
HTMLCanvasElement* canvas = context->canvas(); |
562 |
HTMLCanvasElement* canvas = context->canvas(); |
| 523 |
ImageBuffer* imageBuffer = canvas->buffer(); |
563 |
ImageBuffer* imageBuffer = canvas->buffer(); |
| 524 |
QPainter* painter = imageBuffer->context()->platformContext(); |
564 |
QPainter* painter = imageBuffer->context()->platformContext(); |
| 525 |
paint(painter, QRect(QPoint(0, 0), QSize(m_currentWidth, m_currentHeight))); |
565 |
m_internal->paint(painter, 0, 0); |
| 526 |
} |
566 |
} |
| 527 |
|
567 |
|
| 528 |
PassRefPtr<ImageData> GraphicsContext3D::paintRenderingResultsToImageData() |
568 |
PassRefPtr<ImageData> GraphicsContext3D::paintRenderingResultsToImageData() |
|
Lines 532-554
PassRefPtr<ImageData> GraphicsContext3D::paintRenderingResultsToImageData()
a/Source/WebCore/platform/graphics/qt/GraphicsContext3DQt.cpp_sec8
|
| 532 |
return 0; |
572 |
return 0; |
| 533 |
} |
573 |
} |
| 534 |
|
574 |
|
| 535 |
void GraphicsContext3D::paint(QPainter* painter, const QRect& rect) const |
|
|
| 536 |
{ |
| 537 |
#if QT_VERSION >= QT_VERSION_CHECK(4, 7, 0) |
| 538 |
QWebPageClient* webPageClient = m_internal->m_hostWindow->platformPageClient(); |
| 539 |
QGLWidget* ownerGLWidget = m_internal->getOwnerGLWidget(webPageClient); |
| 540 |
if (ownerGLWidget) { |
| 541 |
ownerGLWidget->drawTexture(rect, m_internal->m_texture); |
| 542 |
return; |
| 543 |
} |
| 544 |
#endif |
| 545 |
m_internal->m_glWidget->makeCurrent(); |
| 546 |
m_internal->bindFramebuffer(GraphicsContext3D::FRAMEBUFFER, m_internal->m_mainFbo); |
| 547 |
glReadPixels(/* x */ 0, /* y */ 0, m_currentWidth, m_currentHeight, GraphicsContext3D::RGBA, GraphicsContext3D::UNSIGNED_BYTE, m_internal->m_pixels.bits()); |
| 548 |
painter->drawImage(/* x */ 0, /* y */ 0, m_internal->m_pixels.rgbSwapped().transformed(QMatrix().rotate(180))); |
| 549 |
m_internal->bindFramebuffer(GraphicsContext3D::FRAMEBUFFER, m_internal->m_currentFbo); |
| 550 |
} |
| 551 |
|
| 552 |
void GraphicsContext3D::reshape(int width, int height) |
575 |
void GraphicsContext3D::reshape(int width, int height) |
| 553 |
{ |
576 |
{ |
| 554 |
if (((width == m_currentWidth) && (height == m_currentHeight)) || (!m_internal)) |
577 |
if (((width == m_currentWidth) && (height == m_currentHeight)) || (!m_internal)) |
|
Lines 557-562
void GraphicsContext3D::reshape(int width, int height)
a/Source/WebCore/platform/graphics/qt/GraphicsContext3DQt.cpp_sec9
|
| 557 |
m_currentWidth = width; |
580 |
m_currentWidth = width; |
| 558 |
m_currentHeight = height; |
581 |
m_currentHeight = height; |
| 559 |
|
582 |
|
|
|
583 |
m_internal->m_boundingRect = QRectF(QPointF(0, 0), QSizeF(width, height)); |
| 560 |
m_internal->m_pixels = QImage(m_currentWidth, m_currentHeight, QImage::Format_ARGB32); |
584 |
m_internal->m_pixels = QImage(m_currentWidth, m_currentHeight, QImage::Format_ARGB32); |
| 561 |
|
585 |
|
| 562 |
m_internal->m_glWidget->makeCurrent(); |
586 |
m_internal->m_glWidget->makeCurrent(); |