Changeset 106620 in webkit
- Timestamp:
- Feb 2, 2012 8:00:29 PM (12 years ago)
- Location:
- trunk/Source
- Files:
-
- 2 added
- 2 deleted
- 19 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r106618 r106620 1 2012-02-02 No'am Rosenthal <noam.rosenthal@nokia.com> 2 3 [Qt][Texmap] Refactor TextureMapper API to use ImageBuffers when possible. 4 https://bugs.webkit.org/show_bug.cgi?id=77148 5 6 Reviewed by Martin Robinson. 7 8 Removed TextureMapperQt, and instead created a TextureMapperImageBuffer class, 9 which responds to an "Software" mode of TextureMapper, instead of creating subclasses 10 of TextureMapper directly. This allows using the software fallback of TextureMapper by any 11 sort. 12 13 To make the ImageBuffer backend easier, content updates to BitmapTexture can now use either 14 an image, or a raw data pointer. The raw data pointer is provided for performance reasons, 15 as converting data to/from Image references in Qt generates unnecessary deep copies of the 16 image data. 17 18 Also, functions that use TransformationMatrix were added to GraphicsContext, to allow for 19 3D transforms in cross platform code. 20 After this patch everything renders the same. An additional bug report was created to allow 21 ImageBuffer shallow image copies: https://bugs.webkit.org/show_bug.cgi?id=77689 22 23 Covered extensively by existing tests, no behavioral changes. 24 25 * Target.pri: 26 * platform/graphics/GraphicsContext.cpp: 27 * platform/graphics/GraphicsContext.h: 28 (WebCore): 29 (GraphicsContext): 30 * platform/graphics/cairo/TextureMapperCairo.cpp: 31 * platform/graphics/opengl/TextureMapperGL.cpp: 32 (TextureMapperGLData): 33 (BitmapTextureGL): 34 (WebCore::BitmapTextureGL::BitmapTextureGL): 35 (WebCore::TextureMapperGL::beginPainting): 36 (WebCore::BitmapTextureGL::reset): 37 (WebCore): 38 (WebCore::swizzleBGRAToRGBA): 39 (WebCore::BitmapTextureGL::updateContents): 40 (WebCore::BitmapTextureGL::destroy): 41 (WebCore::TextureMapperGL::bindSurface): 42 (WebCore::TextureMapper::platformCreateAccelerated): 43 * platform/graphics/opengl/TextureMapperGL.h: 44 (TextureMapperGL): 45 (WebCore::TextureMapperGL::accelerationMode): 46 (WebCore): 47 * platform/graphics/qt/GraphicsContext3DQt.cpp: 48 (WebCore::GraphicsContext3DPrivate::paintToTextureMapper): 49 * platform/graphics/qt/GraphicsContextQt.cpp: 50 (WebCore): 51 (WebCore::GraphicsContext::get3DTransform): 52 (WebCore::GraphicsContext::concat3DTransform): 53 (WebCore::GraphicsContext::set3DTransform): 54 * platform/graphics/qt/TextureMapperQt.cpp: Removed. 55 * platform/graphics/qt/TextureMapperQt.h: Removed. 56 * platform/graphics/texmap/TextureMapper.cpp: 57 (WebCore): 58 (BitmapTextureImageBuffer): 59 (TextureMapperImageBuffer): 60 * platform/graphics/texmap/TextureMapper.h: 61 (WebCore::BitmapTexture::BitmapTexture): 62 (BitmapTexture): 63 (WebCore::BitmapTexture::bpp): 64 (WebCore::BitmapTexture::isOpaque): 65 (WebCore::TextureMapper::setGraphicsContext): 66 (WebCore::TextureMapper::graphicsContext): 67 (TextureMapper): 68 (WebCore::TextureMapper::TextureMapper): 69 (WebCore::TextureMapper::platformCreateAccelerated): 70 * platform/graphics/texmap/TextureMapperNode.cpp: 71 (WebCore::TextureMapperNode::renderContent): 72 (WebCore::TextureMapperNode::setContentsTileBackBuffer): 73 * platform/graphics/texmap/TextureMapperNode.h: 74 (TextureMapperNode): 75 1 76 2012-02-02 Adam Barth <abarth@webkit.org> 2 77 -
trunk/Source/WebCore/GNUmakefile.list.am
r106615 r106620 5734 5734 Source/WebCore/platform/graphics/texmap/TextureMapperAnimation.cpp \ 5735 5735 Source/WebCore/platform/graphics/texmap/TextureMapperAnimation.h \ 5736 Source/WebCore/platform/graphics/texmap/TextureMapperNode.cpp \ 5737 Source/WebCore/platform/graphics/texmap/TextureMapperNode.h \ 5738 Source/WebCore/platform/graphics/texmap/TextureMapperPlatformLayer.h 5736 Source/WebCore/platform/graphics/texmap/TextureMapperImageBuffer.cpp \ 5737 Source/WebCore/platform/graphics/texmap/TextureMapperImageBuffer.h \ 5738 Source/WebCore/platform/graphics/texmap/TextureMapperNode.cpp \ 5739 Source/WebCore/platform/graphics/texmap/TextureMapperNode.h \ 5740 Source/WebCore/platform/graphics/texmap/TextureMapperPlatformLayer.h 5739 5741 webcoregtk_sources += \ 5740 5742 Source/WebCore/platform/graphics/cairo/TextureMapperCairo.cpp \ … … 5754 5756 Source/WebCore/platform/graphics/texmap/TextureMapperAnimation.cpp \ 5755 5757 Source/WebCore/platform/graphics/texmap/TextureMapperAnimation.h \ 5756 Source/WebCore/platform/graphics/texmap/TextureMapperNode.cpp \ 5757 Source/WebCore/platform/graphics/texmap/TextureMapperNode.h \ 5758 Source/WebCore/platform/graphics/texmap/TextureMapperImageBuffer.cpp \ 5759 Source/WebCore/platform/graphics/texmap/TextureMapperImageBuffer.h \ 5760 Source/WebCore/platform/graphics/texmap/TextureMapperNode.cpp \ 5761 Source/WebCore/platform/graphics/texmap/TextureMapperNode.h \ 5758 5762 Source/WebCore/platform/graphics/texmap/TextureMapperPlatformLayer.h 5759 5763 webcoregtk_sources += \ -
trunk/Source/WebCore/Target.pri
r106373 r106620 3940 3940 contains(CONFIG, texmap) { 3941 3941 HEADERS += \ 3942 platform/graphics/qt/TextureMapperQt.h \3943 3942 platform/graphics/texmap/GraphicsLayerTextureMapper.h \ 3944 3943 platform/graphics/texmap/LayerTransform.h \ 3945 3944 platform/graphics/texmap/TextureMapper.h \ 3946 3945 platform/graphics/texmap/TextureMapperAnimation.h \ 3946 platform/graphics/texmap/TextureMapperImageBuffer.h \ 3947 3947 platform/graphics/texmap/TextureMapperNode.h \ 3948 3948 platform/graphics/texmap/TextureMapperPlatformLayer.h 3949 3949 3950 3950 SOURCES += \ 3951 platform/graphics/qt/TextureMapperQt.cpp \3952 3951 platform/graphics/texmap/LayerTransform.cpp \ 3953 3952 platform/graphics/texmap/TextureMapper.cpp \ 3954 3953 platform/graphics/texmap/TextureMapperAnimation.cpp \ 3954 platform/graphics/texmap/TextureMapperImageBuffer.cpp \ 3955 3955 platform/graphics/texmap/TextureMapperNode.cpp \ 3956 3956 platform/graphics/texmap/GraphicsLayerTextureMapper.cpp … … 3960 3960 SOURCES += platform/graphics/opengl/TextureMapperGL.cpp 3961 3961 CONFIG += opengl-shims 3962 DEFINES += WTF_USE_TEXTURE_MAPPER_GL 3962 3963 } 3963 3964 } else { -
trunk/Source/WebCore/WebCore.gypi
r106373 r106620 3581 3581 'platform/graphics/texmap/TextureMapperAnimation.cpp', 3582 3582 'platform/graphics/texmap/TextureMapperAnimation.h', 3583 'platform/graphics/texmap/TextureMapperImageBuffer.cpp', 3584 'platform/graphics/texmap/TextureMapperImageBuffer.h', 3583 3585 'platform/graphics/texmap/TextureMapperNode.cpp', 3584 3586 'platform/graphics/texmap/TextureMapperNode.h', -
trunk/Source/WebCore/platform/graphics/GraphicsContext.h
r98406 r106620 125 125 class GraphicsContext3D; 126 126 class TextRun; 127 class TransformationMatrix; 127 128 128 129 enum TextDrawingMode { … … 410 411 AffineTransform getCTM() const; 411 412 413 #if ENABLE(3D_RENDERING) && USE(TEXTURE_MAPPER) 414 // This is needed when using accelerated-compositing in software mode, like in TextureMapper. 415 void concat3DTransform(const TransformationMatrix&); 416 void set3DTransform(const TransformationMatrix&); 417 TransformationMatrix get3DTransform() const; 418 #endif 412 419 // Create an image buffer compatible with this context, with suitable resolution 413 420 // for drawing into the buffer and then into this context. -
trunk/Source/WebCore/platform/graphics/cairo/TextureMapperCairo.cpp
r101548 r106620 116 116 } 117 117 118 PassOwnPtr<TextureMapper> TextureMapper::create(GraphicsContext* context)119 {120 return adoptPtr(new TextureMapperCairo);121 }122 123 118 PassRefPtr<BitmapTexture> TextureMapperCairo::createTexture() 124 119 { -
trunk/Source/WebCore/platform/graphics/opengl/TextureMapperGL.cpp
r106524 r106620 266 266 }; 267 267 268 struct DirectlyCompositedImageRepository {269 struct Entry {270 GLuint texture;271 int refCount;272 };273 typedef HashMap<ImageUID, Entry> ImageTextureMap;274 ImageTextureMap imageToTexture;275 276 GLuint findOrCreate(ImageUID image, bool& found)277 {278 ImageTextureMap::iterator it = imageToTexture.find(image);279 found = false;280 if (it != imageToTexture.end()) {281 it->second.refCount++;282 found = true;283 return it->second.texture;284 }285 Entry entry;286 GL_CMD(glGenTextures(1, &entry.texture));287 entry.refCount = 1;288 imageToTexture.add(image, entry);289 return entry.texture;290 }291 292 bool deref(ImageUID image)293 {294 HashMap<ImageUID, Entry>::iterator it = imageToTexture.find(image);295 if (it != imageToTexture.end()) {296 if (it->second.refCount < 2) {297 imageToTexture.remove(it);298 return false;299 }300 }301 return true;302 }303 304 DirectlyCompositedImageRepository()305 {306 }307 308 ~DirectlyCompositedImageRepository()309 {310 for (ImageTextureMap::iterator it = imageToTexture.begin(); it != imageToTexture.end(); ++it) {311 GLuint texture = it->second.texture;312 if (texture)313 GL_CMD(glDeleteTextures(1, &texture));314 }315 316 }317 } directlyCompositedImages;318 319 268 SharedGLData& sharedGLData() const 320 269 { … … 333 282 GLint previousProgram; 334 283 GLint previousScissorState; 284 GLint viewport[4]; 335 285 RefPtr<SharedGLData> m_sharedGLData; 336 286 }; … … 343 293 virtual void reset(const IntSize&, bool opaque); 344 294 void bind(); 345 virtual PlatformGraphicsContext* beginPaint(const IntRect& dirtyRect);346 virtual void endPaint();347 virtual void setContentsToImage(Image*);348 295 ~BitmapTextureGL() { destroy(); } 349 296 virtual uint32_t id() const { return m_id; } 350 inline bool isOpaque() const { return m_opaque; }351 297 inline FloatSize relativeSize() const { return m_relativeSize; } 352 298 void setTextureMapper(TextureMapperGL* texmap) { m_textureMapper = texmap; } 353 354 void updateContents(PixelFormat, const IntRect&, void*); 355 void updateRawContents(const IntRect&, const void*); 356 void pack() 357 { 358 // This is currently a stub. 359 if (isPacked()) 360 return; 361 m_isPacked = true; 362 } 363 364 void unpack() 365 { 366 // This is currently a stub. 367 if (!isPacked()) 368 return; 369 m_isPacked = false; 370 } 371 372 bool isPacked() const 373 { 374 return m_isPacked; 375 } 299 void updateContents(Image*, const IntRect&, const IntRect&, PixelFormat); 300 void updateContents(const void*, const IntRect&); 376 301 377 302 private: 378 303 GLuint m_id; 379 ImageUID m_imageUID;380 304 FloatSize m_relativeSize; 381 bool m_opaque;382 305 IntSize m_textureSize; 383 OwnPtr<BGRA32PremultimpliedBuffer> m_buffer;384 306 IntRect m_dirtyRect; 385 307 GLuint m_fbo; … … 387 309 IntSize m_actualSize; 388 310 bool m_surfaceNeedsReset; 389 bool m_isPacked;390 311 TextureMapperGL* m_textureMapper; 391 312 BitmapTextureGL() 392 313 : m_id(0) 393 , m_imageUID(0)394 , m_opaque(false)395 314 , m_fbo(0) 396 315 , m_rbo(0) … … 545 464 glClearStencil(0); 546 465 glClear(GL_STENCIL_BUFFER_BIT); 466 glGetIntegerv(GL_VIEWPORT, data().viewport); 547 467 bindSurface(0); 548 468 } … … 664 584 { 665 585 BitmapTexture::reset(newSize, opaque); 666 m_imageUID = 0;667 586 IntSize newTextureSize = nextPowerOfTwo(newSize); 668 587 bool justCreated = false; … … 683 602 m_actualSize = newSize; 684 603 m_relativeSize = FloatSize(float(newSize.width()) / m_textureSize.width(), float(newSize.height()) / m_textureSize.height()); 685 m_opaque = opaque;686 604 m_surfaceNeedsReset = true; 687 605 } 688 606 689 PlatformGraphicsContext* BitmapTextureGL::beginPaint(const IntRect& dirtyRect) 690 { 691 m_buffer = BGRA32PremultimpliedBuffer::create(); 692 m_dirtyRect = dirtyRect; 693 return m_buffer->beginPaint(dirtyRect, m_opaque); 694 } 695 696 void BitmapTextureGL::endPaint() 697 { 698 if (!m_buffer) 699 return; 700 m_buffer->endPaint(); 701 updateContents(BGRAFormat, m_dirtyRect, m_buffer->data()); 702 GL_CMD(glBindTexture(GL_TEXTURE_2D, m_id)) 703 m_buffer.clear(); 704 } 705 706 #ifdef TEXMAP_OPENGL_ES_2 607 707 608 static void swizzleBGRAToRGBA(uint32_t* data, const IntSize& size) 708 609 { … … 715 616 } 716 617 } 717 #endif 718 719 void BitmapTextureGL::updateContents(PixelFormat pixelFormat, const IntRect& rect, void* bits) 618 619 void BitmapTextureGL::updateContents(const void* data, const IntRect& targetRect) 720 620 { 721 621 GL_CMD(glBindTexture(GL_TEXTURE_2D, m_id)) 722 #ifdef TEXMAP_OPENGL_ES_2 723 bool shouldSwizzle = false; 724 #endif 725 726 GLint glFormat = GL_RGBA; 727 switch (pixelFormat) { 728 case RGBAFormat: 729 glFormat = GL_RGBA; 730 break; 731 case RGBFormat: 732 glFormat = GL_RGB; 733 break; 734 case BGRAFormat: 735 #ifdef TEXMAP_OPENGL_ES_2 736 shouldSwizzle = true; 737 glFormat = GL_RGBA; 738 #else 739 glFormat = GL_BGRA; 740 #endif 741 break; 742 case BGRFormat: 743 #ifdef TEXMAP_OPENGL_ES_2 744 shouldSwizzle = true; 745 glFormat = GL_RGB; 746 #else 747 glFormat = GL_BGR; 748 #endif 749 break; 750 } 751 752 #ifdef TEXMAP_OPENGL_ES_2 753 if (shouldSwizzle) 754 swizzleBGRAToRGBA(static_cast<uint32_t*>(bits), rect.size()); 755 #endif 756 GL_CMD(glTexSubImage2D(GL_TEXTURE_2D, 0, rect.x(), rect.y(), rect.width(), rect.height(), glFormat, GL_UNSIGNED_BYTE, bits)) 757 } 758 759 void BitmapTextureGL::updateRawContents(const IntRect& rect, const void* bits) 760 { 622 GL_CMD(glTexSubImage2D(GL_TEXTURE_2D, 0, targetRect.x(), targetRect.y(), targetRect.width(), targetRect.height(), GL_RGBA, GL_UNSIGNED_BYTE, data)) 623 } 624 625 void BitmapTextureGL::updateContents(Image* image, const IntRect& targetRect, const IntRect& sourceRect, BitmapTexture::PixelFormat format) 626 { 627 if (!image) 628 return; 761 629 GL_CMD(glBindTexture(GL_TEXTURE_2D, m_id)) 762 630 GLuint glFormat = isOpaque() ? GL_RGB : GL_RGBA; 763 GL_CMD(glTexSubImage2D(GL_TEXTURE_2D, 0, rect.x(), rect.y(), rect.width(), rect.height(), glFormat, GL_UNSIGNED_BYTE, bits)) 764 } 765 766 void BitmapTextureGL::setContentsToImage(Image* image) 767 { 768 ImageUID uid = image ? uidForImage(image) : 0; 769 if (!image || !uid) { 770 if (m_imageUID) 771 destroy(); 772 return; 773 } 774 775 if (uid == m_imageUID) 776 return; 777 bool found = false; 778 GLuint newTextureID = m_textureMapper->data().directlyCompositedImages.findOrCreate(uid, found); 779 if (newTextureID != m_id) { 780 m_imageUID = uid; 781 destroy(); 782 m_id = newTextureID; 783 reset(image->size(), false); 784 if (!found) { 785 GraphicsContext context(beginPaint(IntRect(0, 0, m_textureSize.width(), m_textureSize.height()))); 786 context.drawImage(image, ColorSpaceDeviceRGB, IntPoint(0, 0), CompositeCopy); 787 endPaint(); 788 } 789 } 631 NativeImagePtr frameImage = image->nativeImageForCurrentFrame(); 632 if (!frameImage) 633 return; 634 635 #if PLATFORM(QT) 636 QImage qtImage = frameImage->toImage(); 637 if (IntSize(qtImage.size()) != sourceRect.size()) 638 qtImage = qtImage.copy(sourceRect); 639 if (format == BGRAFormat || format == BGRFormat) 640 swizzleBGRAToRGBA(reinterpret_cast<uint32_t*>(qtImage.bits()), qtImage.size()); 641 GL_CMD(glTexSubImage2D(GL_TEXTURE_2D, 0, targetRect.x(), targetRect.y(), targetRect.width(), targetRect.height(), glFormat, GL_UNSIGNED_BYTE, qtImage.constBits())) 642 #endif 790 643 } 791 644 … … 838 691 void BitmapTextureGL::destroy() 839 692 { 840 if (m_id && (!m_imageUID || !m_textureMapper->data().directlyCompositedImages.deref(m_imageUID)))693 if (m_id) 841 694 GL_CMD(glDeleteTextures(1, &m_id)) 842 695 … … 873 726 874 727 if (!surface) { 728 IntSize viewportSize(data().viewport[2], data().viewport[3]); 875 729 GL_CMD(glBindFramebuffer(GL_FRAMEBUFFER, 0)) 876 data().projectionMatrix = createProjectionMatrix(viewportSize (), true).multiply(transform());730 data().projectionMatrix = createProjectionMatrix(viewportSize, true); 877 731 GL_CMD(glStencilFunc(data().sharedGLData().stencilIndex > 1 ? GL_EQUAL : GL_ALWAYS, data().sharedGLData().stencilIndex - 1, data().sharedGLData().stencilIndex - 1)) 878 732 GL_CMD(glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP)) 879 GL_CMD(glViewport(0, 0, viewportSize ().width(), viewportSize().height()))880 data().sharedGLData().clipStack.append(IntRect( IntPoint::zero(), viewportSize()));733 GL_CMD(glViewport(0, 0, viewportSize.width(), viewportSize.height())) 734 data().sharedGLData().clipStack.append(IntRect(data().viewport[0], data().viewport[1], data().viewport[2], data().viewport[3])); 881 735 return; 882 736 } … … 986 840 } 987 841 842 PassOwnPtr<TextureMapper> TextureMapper::platformCreateAccelerated() 843 { 844 return TextureMapperGL::create(); 845 } 846 988 847 }; -
trunk/Source/WebCore/platform/graphics/opengl/TextureMapperGL.h
r106524 r106620 44 44 virtual void bindSurface(BitmapTexture* surface); 45 45 virtual void beginClip(const TransformationMatrix&, const FloatRect&); 46 virtual void beginPainting(); 47 virtual void endPainting(); 46 48 virtual void endClip(); 47 virtual bool allowSurfaceForRoot() const { return false; }48 49 virtual PassRefPtr<BitmapTexture> createTexture(); 49 50 virtual const char* type() const; 50 51 static PassOwnPtr<TextureMapperGL> create() { return adoptPtr(new TextureMapperGL); } 51 void beginPainting();52 void endPainting();53 52 void setGraphicsContext(GraphicsContext* context) { m_context = context; } 54 53 GraphicsContext* graphicsContext() { return m_context; } 55 54 virtual bool isOpenGLBacked() const { return true; } 55 void platformUpdateContents(NativeImagePtr, const IntRect&, const IntRect&, BitmapTexture::PixelFormat); 56 virtual AccelerationMode accelerationMode() const { return OpenGLMode; } 56 57 57 58 private: … … 65 66 66 67 // An offscreen buffer to be rendered by software. 67 class BGRA32PremultimpliedBuffer {68 WTF_MAKE_FAST_ALLOCATED;69 public:70 virtual ~BGRA32PremultimpliedBuffer() { }71 virtual PlatformGraphicsContext* beginPaint(const IntRect& dirtyRect, bool opaque) = 0;72 virtual void endPaint() = 0;73 virtual void* data() = 0;74 static PassOwnPtr<BGRA32PremultimpliedBuffer> create();75 };76 77 68 static inline int nextPowerOfTwo(int num) 78 69 { -
trunk/Source/WebCore/platform/graphics/qt/GraphicsContext3DQt.cpp
r106320 r106620 147 147 blitMultisampleFramebufferAndRestoreContext(); 148 148 149 if (textureMapper-> isOpenGLBacked()) {149 if (textureMapper->accelerationMode() == TextureMapper::OpenGLMode) { 150 150 TextureMapperGL* texmapGL = static_cast<TextureMapperGL*>(textureMapper); 151 151 texmapGL->drawTexture(m_context->m_texture, !m_context->m_attrs.alpha, FloatSize(1, 1), targetRect, matrix, opacity, mask, true /* flip */); -
trunk/Source/WebCore/platform/graphics/qt/GraphicsContextQt.cpp
r97557 r106620 1336 1336 } 1337 1337 1338 #if ENABLE(3D_RENDERING) && USE(TEXTURE_MAPPER) 1339 TransformationMatrix GraphicsContext::get3DTransform() const 1340 { 1341 if (paintingDisabled()) 1342 return TransformationMatrix(); 1343 1344 return platformContext()->combinedTransform(); 1345 } 1346 1347 void GraphicsContext::concat3DTransform(const TransformationMatrix& transform) 1348 { 1349 if (paintingDisabled()) 1350 return; 1351 1352 m_data->p()->setWorldTransform(transform, true); 1353 } 1354 1355 void GraphicsContext::set3DTransform(const TransformationMatrix& transform) 1356 { 1357 if (paintingDisabled()) 1358 return; 1359 1360 m_data->p()->setWorldTransform(transform, false); 1361 } 1362 #endif 1363 1338 1364 void GraphicsContext::setURLForRect(const KURL&, const IntRect&) 1339 1365 { -
trunk/Source/WebCore/platform/graphics/texmap/TextureMapper.cpp
r105467 r106620 20 20 #include "config.h" 21 21 #include "TextureMapper.h" 22 23 #include "TextureMapperImageBuffer.h" 22 24 23 25 #if USE(ACCELERATED_COMPOSITING) && USE(TEXTURE_MAPPER) … … 72 74 } 73 75 76 77 PassOwnPtr<TextureMapper> TextureMapper::create(AccelerationMode mode) 78 { 79 if (mode == SoftwareMode) 80 return TextureMapperImageBuffer::create(); 81 return platformCreateAccelerated(); 82 } 83 74 84 } 75 85 #endif -
trunk/Source/WebCore/platform/graphics/texmap/TextureMapper.h
r105737 r106620 48 48 public: 49 49 enum PixelFormat { BGRAFormat, RGBAFormat, BGRFormat, RGBFormat }; 50 BitmapTexture() : m_lockCount(0) {} 50 BitmapTexture() 51 : m_isOpaque(true) 52 { 53 } 54 51 55 virtual ~BitmapTexture() { } 52 56 virtual void destroy() { } 53 57 54 virtual bool allowOfflineTextureUpload() const { return false; }55 58 virtual IntSize size() const = 0; 59 virtual void updateContents(Image*, const IntRect&, const IntRect&, BitmapTexture::PixelFormat) = 0; 60 virtual void updateContents(const void*, const IntRect&) = 0; 61 virtual bool isValid() const = 0; 62 56 63 virtual int bpp() const { return 32; } 57 virtual bool isValid() const = 0;58 64 virtual void reset(const IntSize& size, bool opaque = false) 59 65 { … … 62 68 } 63 69 64 virtual void pack() { }65 virtual void unpack() { }66 virtual bool isPacked() const { return false; }67 68 virtual PlatformGraphicsContext* beginPaint(const IntRect& dirtyRect) = 0;69 virtual void endPaint() = 0;70 71 // For performance reasons, BitmapTexture might modify the bits directly (swizzle).72 // Thus, this method is only recommended for buffer update, such as used by WebKit2.73 virtual void updateContents(PixelFormat, const IntRect&, void* bits) = 0;74 virtual void updateRawContents(const IntRect&, const void* bits) { }75 virtual PlatformGraphicsContext* beginPaintMedia()76 {77 return beginPaint(IntRect(0, 0, size().width(), size().height()));78 }79 virtual void setContentsToImage(Image*) = 0;80 virtual bool save(const String&) { return false; }81 82 inline void lock() { ++m_lockCount; }83 inline void unlock() { --m_lockCount; }84 inline bool isLocked() { return m_lockCount; }85 70 inline IntSize contentSize() const { return m_contentSize; } 86 71 inline int numberOfBytes() const { return size().width() * size().height() * bpp() >> 3; } 72 inline bool isOpaque() const { return m_isOpaque; } 87 73 88 74 protected: 89 int m_lockCount;90 75 IntSize m_contentSize; 91 76 bool m_isOpaque; … … 98 83 99 84 public: 100 static PassOwnPtr<TextureMapper> create(GraphicsContext* graphicsContext = 0); 85 enum AccelerationMode { SoftwareMode, OpenGLMode }; 86 static PassOwnPtr<TextureMapper> create(AccelerationMode newMode = SoftwareMode); 101 87 virtual ~TextureMapper() { } 102 88 … … 105 91 // makes a surface the target for the following drawTexture calls. 106 92 virtual void bindSurface(BitmapTexture* surface) = 0; 107 virtual void setGraphicsContext(GraphicsContext* ) = 0;108 virtual GraphicsContext* graphicsContext() = 0;93 virtual void setGraphicsContext(GraphicsContext* context) { m_context = context; } 94 virtual GraphicsContext* graphicsContext() { return m_context; } 109 95 virtual void beginClip(const TransformationMatrix&, const FloatRect&) = 0; 110 96 virtual void endClip() = 0; 111 virtual bool allowSurfaceForRoot() const = 0;112 97 virtual PassRefPtr<BitmapTexture> createTexture() = 0; 113 IntSize viewportSize() const { return m_viewportSize; }114 void setViewportSize(const IntSize& s) { m_viewportSize = s; }115 98 116 99 void setImageInterpolationQuality(InterpolationQuality quality) { m_interpolationQuality = quality; } … … 119 102 InterpolationQuality imageInterpolationQuality() const { return m_interpolationQuality; } 120 103 TextDrawingModeFlags textDrawingMode() const { return m_textDrawingMode; } 121 virtual bool allowPartialUpdates() const { return false; } 122 virtual bool isOpenGLBacked() const { return false; } 123 124 void setTransform(const TransformationMatrix& matrix) { m_transform = matrix; } 125 TransformationMatrix transform() const { return m_transform; } 104 virtual AccelerationMode accelerationMode() const = 0; 126 105 127 106 virtual void beginPainting() { } … … 130 109 // A surface is released implicitly when dereferenced. 131 110 virtual PassRefPtr<BitmapTexture> acquireTextureFromPool(const IntSize&); 132 133 111 134 112 protected: … … 139 117 140 118 private: 119 #if USE(TEXTURE_MAPPER_GL) 120 static PassOwnPtr<TextureMapper> platformCreateAccelerated(); 121 #else 122 static PassOwnPtr<TextureMapper> platformCreateAccelerated() 123 { 124 return 0; 125 } 126 #endif 141 127 InterpolationQuality m_interpolationQuality; 142 128 TextDrawingModeFlags m_textDrawingMode; 143 TransformationMatrix m_transform;144 IntSize m_viewportSize;145 129 Vector<RefPtr<BitmapTexture> > m_texturePool; 130 GraphicsContext* m_context; 146 131 }; 147 132 148 } ;133 } 149 134 150 135 #endif -
trunk/Source/WebCore/platform/graphics/texmap/TextureMapperNode.cpp
r105925 r106620 24 24 25 25 #include "GraphicsLayerTextureMapper.h" 26 #include "ImageBuffer.h" 26 27 #include "MathExtras.h" 27 28 … … 157 158 return; 158 159 159 // FIXME: Add directly composited images. 160 FloatRect dirtyRect = m_currentContent.needsDisplay ? entireRect() : m_currentContent.needsDisplayRect; 160 IntRect dirtyRect = enclosingIntRect(m_currentContent.needsDisplay ? entireRect() : m_currentContent.needsDisplayRect); 161 161 162 162 for (size_t tileIndex = 0; tileIndex < m_ownedTiles.size(); ++tileIndex) { 163 163 OwnedTile& tile = m_ownedTiles[tileIndex]; 164 FloatRect rect = dirtyRect;165 164 if (!tile.texture) 166 165 tile.texture = textureMapper->createTexture(); … … 170 169 if (tile.needsReset || texture->contentSize() != tileSize || !texture->isValid()) { 171 170 tile.needsReset = false; 172 texture->reset(tileSize, m_currentContent.contentType == DirectImageContentType ? false : m_state.contentsOpaque); 173 rect = tile.rect; 174 } 175 176 IntRect contentRect = enclosingIntRect(tile.rect); 177 contentRect.intersect(enclosingIntRect(rect)); 178 if (contentRect.isEmpty()) 171 texture->reset(tileSize, m_state.contentsOpaque); 172 dirtyRect.unite(enclosingIntRect(tile.rect)); 173 } 174 } 175 176 if (dirtyRect.isEmpty()) 177 return; 178 179 // Paint the entire dirty rect into an image buffer. This ensures we only paint once. 180 OwnPtr<ImageBuffer> imageBuffer = ImageBuffer::create(dirtyRect.size()); 181 GraphicsContext* context = imageBuffer->context(); 182 context->setImageInterpolationQuality(textureMapper->imageInterpolationQuality()); 183 context->setTextDrawingMode(textureMapper->textDrawingMode()); 184 context->translate(-dirtyRect.x(), -dirtyRect.y()); 185 layer->paintGraphicsLayerContents(*context, dirtyRect); 186 if (m_currentContent.contentType == DirectImageContentType) 187 context->drawImage(m_currentContent.image.get(), ColorSpaceDeviceRGB, m_state.contentsRect); 188 189 // FIXME: Implement ImageBuffer::DontCopyBackingStore in Qt/GTK ports, and then change this. 190 // See https://bugs.webkit.org/show_bug.cgi?id=77689 191 RefPtr<Image> image = imageBuffer->copyImage(CopyBackingStore); 192 193 // Divide the image to tiles. 194 for (size_t tileIndex = 0; tileIndex < m_ownedTiles.size(); ++tileIndex) { 195 OwnedTile& tile = m_ownedTiles[tileIndex]; 196 IntRect targetRect = enclosingIntRect(tile.rect); 197 targetRect.intersect(dirtyRect); 198 if (targetRect.isEmpty()) 179 199 continue; 180 181 FloatRect contentRectInTileCoordinates = contentRect; 182 FloatPoint offset(-tile.rect.x(), -tile.rect.y()); 183 contentRectInTileCoordinates.move(offset.x(), offset.y()); 184 185 { 186 GraphicsContext context(texture->beginPaint(enclosingIntRect(contentRectInTileCoordinates))); 187 context.setImageInterpolationQuality(textureMapper->imageInterpolationQuality()); 188 context.setTextDrawingMode(textureMapper->textDrawingMode()); 189 context.translate(offset.x(), offset.y()); 190 FloatRect scaledContentRect(contentRect); 191 if (m_currentContent.contentType == DirectImageContentType) 192 context.drawImage(m_currentContent.image.get(), ColorSpaceDeviceRGB, IntPoint(0, 0)); 193 else 194 layer->paintGraphicsLayerContents(context, enclosingIntRect(scaledContentRect)); 195 texture->endPaint(); 196 } 200 IntRect sourceRect = targetRect; 201 202 // Normalize sourceRect to the buffer's coordinates. 203 sourceRect.move(-dirtyRect.x(), -dirtyRect.y()); 204 205 // Normalize targetRect to the texture's coordinqates. 206 targetRect.move(-tile.rect.x(), -tile.rect.y()); 207 tile.texture->updateContents(image.get(), targetRect, sourceRect, BitmapTexture::RGBAFormat); 197 208 } 198 209 … … 482 493 } 483 494 484 void TextureMapperNode::setContentsTileBackBuffer(int id, const IntRect& sourceRect, const IntRect& targetRect, const void* bits)495 void TextureMapperNode::setContentsTileBackBuffer(int id, const IntRect& sourceRect, const IntRect& targetRect, const void* data) 485 496 { 486 497 ASSERT(m_textureMapper); … … 499 510 tile.backBuffer.texture = m_textureMapper->createTexture(); 500 511 tile.backBuffer.texture->reset(sourceRect.size(), false); 501 tile.backBuffer.texture->update RawContents(sourceRect, bits);512 tile.backBuffer.texture->updateContents(data, sourceRect); 502 513 tile.isBackBufferUpdated = true; 503 514 } -
trunk/Source/WebCore/platform/graphics/texmap/TextureMapperNode.h
r105925 r106620 149 149 int createContentsTile(float scale); 150 150 void removeContentsTile(int id); 151 void setContentsTileBackBuffer(int id, const IntRect& sourceRect, const IntRect& targetRect, const void* bits);151 void setContentsTileBackBuffer(int id, const IntRect& sourceRect, const IntRect& targetRect, const void*); 152 152 void setTileBackBufferTextureForDirectlyCompositedImage(int id, const IntRect& sourceRect, const FloatRect& targetRect, BitmapTexture*); 153 153 void clearAllDirectlyCompositedImageTiles(); -
trunk/Source/WebKit/qt/Api/qwebframe.cpp
r102763 r106620 337 337 textureMapper->setImageInterpolationQuality(context->imageInterpolationQuality()); 338 338 textureMapper->setTextDrawingMode(context->textDrawingMode()); 339 textureMapper->setViewportSize(frame->view()->frameRect().size());340 339 QPainter* painter = context->platformContext(); 341 340 const QTransform transform = painter->worldTransform(); -
trunk/Source/WebKit/qt/ChangeLog
r106515 r106620 1 2012-02-02 No'am Rosenthal <noam.rosenthal@nokia.com> 2 3 [Qt][Texmap] Refactor TextureMapper API to use ImageBuffers when possible. 4 https://bugs.webkit.org/show_bug.cgi?id=77148 5 6 Reviewed by Martin Robinson. 7 8 Use TextureMapper::create instead of creating TextureMapperGL/TextureMapperQt directly. 9 10 * Api/qwebframe.cpp: 11 (QWebFramePrivate::renderCompositedLayers): 12 * WebCoreSupport/PageClientQt.cpp: 13 (WebCore::PageClientQWidget::setRootGraphicsLayer): 14 (WebCore::PageClientQGraphicsWidget::setRootGraphicsLayer): 15 1 16 2012-02-01 Caio Marcelo de Oliveira Filho <caio.oliveira@openbossa.org> 2 17 -
trunk/Source/WebKit/qt/WebCoreSupport/PageClientQt.cpp
r100410 r106620 29 29 30 30 #if USE(ACCELERATED_COMPOSITING) && USE(TEXTURE_MAPPER) 31 #include "TextureMapper Qt.h"31 #include "TextureMapper.h" 32 32 #include "texmap/TextureMapperNode.h" 33 34 #if USE(TEXTURE_MAPPER_GL)35 #include "opengl/TextureMapperGL.h"36 #endif37 33 #endif 38 34 … … 77 73 if (layer) { 78 74 textureMapperNodeClient = adoptPtr(new TextureMapperNodeClientQt(page->mainFrame(), layer)); 79 textureMapperNodeClient->setTextureMapper( adoptPtr(new TextureMapperQt));75 textureMapperNodeClient->setTextureMapper(TextureMapper::create()); 80 76 textureMapperNodeClient->syncRootLayer(); 81 77 return; … … 268 264 QGraphicsView* graphicsView = view->scene()->views()[0]; 269 265 if (graphicsView && graphicsView->viewport() && graphicsView->viewport()->inherits("QGLWidget")) { 270 textureMapperNodeClient->setTextureMapper(TextureMapper GL::create());266 textureMapperNodeClient->setTextureMapper(TextureMapper::create(TextureMapper::OpenGLMode)); 271 267 return; 272 268 } 273 269 #endif 274 textureMapperNodeClient->setTextureMapper(TextureMapper Qt::create());270 textureMapperNodeClient->setTextureMapper(TextureMapper::create()); 275 271 return; 276 272 } -
trunk/Source/WebKit2/ChangeLog
r106592 r106620 1 2012-02-02 No'am Rosenthal <noam.rosenthal@nokia.com> 2 3 [Qt][Texmap] Refactor TextureMapper API to use ImageBuffers when possible. 4 https://bugs.webkit.org/show_bug.cgi?id=77148 5 6 Reviewed by Martin Robinson. 7 8 Use TextureMapper::create instead of creating TextureMapperGL/TextureMapperQt directly. 9 Remove calls to unused API. 10 11 * UIProcess/qt/LayerTreeHostProxyQt.cpp: 12 (WebKit::LayerTreeHostProxy::paintToCurrentGLContext): 13 (WebKit::LayerTreeHostProxy::paintToGraphicsContext): 14 (WebKit::LayerTreeHostProxy::createImage): 15 (WebKit::LayerTreeHostProxy::ensureRootLayer): 16 1 17 2012-02-02 Jon Lee <jonlee@apple.com> 2 18 -
trunk/Source/WebKit2/UIProcess/qt/LayerTreeHostProxyQt.cpp
r106524 r106620 27 27 #include "MessageID.h" 28 28 #include "ShareableBitmap.h" 29 #include "TextureMapperGL.h" 30 #include "TextureMapperQt.h" 29 #include "TextureMapper.h" 31 30 #include "UpdateInfo.h" 32 31 #include "WebCoreArgumentCoders.h" … … 172 171 { 173 172 if (!m_textureMapper) 174 m_textureMapper = TextureMapper GL::create();175 ASSERT( dynamic_cast<TextureMapperGL*>(m_textureMapper.get()));173 m_textureMapper = TextureMapper::create(TextureMapper::OpenGLMode); 174 ASSERT(m_textureMapper->accelerationMode() == TextureMapper::OpenGLMode); 176 175 177 176 syncRemoteContent(); … … 185 184 return; 186 185 187 GLint viewport[4];188 glGetIntegerv(GL_VIEWPORT, viewport);189 m_textureMapper->setViewportSize(IntSize(viewport[2], viewport[3]));190 186 node->setTextureMapper(m_textureMapper.get()); 191 187 m_textureMapper->beginPainting(); … … 212 208 { 213 209 if (!m_textureMapper) 214 m_textureMapper = TextureMapperQt::create(); 215 ASSERT(dynamic_cast<TextureMapperQt*>(m_textureMapper.get())); 216 210 m_textureMapper = TextureMapper::create(); 211 ASSERT(m_textureMapper->accelerationMode() == TextureMapper::SoftwareMode); 217 212 syncRemoteContent(); 218 213 TextureMapperNode* node = toTextureMapperNode(rootLayer()); … … 411 406 RefPtr<BitmapTexture> texture = m_textureMapper->createTexture(); 412 407 texture->reset(rect.size(), !imageHasAlpha); 413 texture->update RawContents(IntRect(IntPoint::zero(), rect.size()), subImage.constBits());408 texture->updateContents(subImage.constBits(), IntRect(IntPoint::zero(), rect.size())); 414 409 tiledImage.add(rect.location(), texture); 415 410 } … … 474 469 m_rootLayer->setSize(FloatSize(1.0, 1.0)); 475 470 if (!m_textureMapper) 476 m_textureMapper = TextureMapper GL::create();471 m_textureMapper = TextureMapper::create(TextureMapper::OpenGLMode); 477 472 toTextureMapperNode(m_rootLayer.get())->setTextureMapper(m_textureMapper.get()); 478 473 }
Note: See TracChangeset
for help on using the changeset viewer.