diff options
author | Ben Murdoch <benm@google.com> | 2010-07-22 15:37:06 +0100 |
---|---|---|
committer | Ben Murdoch <benm@google.com> | 2010-07-27 10:20:25 +0100 |
commit | 967717af5423377c967781471ee106e2bb4e11c8 (patch) | |
tree | 1e701dc0a12f7f07cce1df4a7681717de77a211b /WebCore/platform/graphics/mac | |
parent | dcc30a9fca45f634b1d3a12b276d3a0ccce99fc3 (diff) | |
download | external_webkit-967717af5423377c967781471ee106e2bb4e11c8.zip external_webkit-967717af5423377c967781471ee106e2bb4e11c8.tar.gz external_webkit-967717af5423377c967781471ee106e2bb4e11c8.tar.bz2 |
Merge WebKit at r63859 : Initial merge by git.
Change-Id: Ie8096c63ec7c991c9a9cba8bdd9c3b74a3b8ed62
Diffstat (limited to 'WebCore/platform/graphics/mac')
-rw-r--r-- | WebCore/platform/graphics/mac/ComplexTextController.cpp | 18 | ||||
-rw-r--r-- | WebCore/platform/graphics/mac/GraphicsContext3DMac.mm | 87 | ||||
-rw-r--r-- | WebCore/platform/graphics/mac/GraphicsLayerCA.h | 1 | ||||
-rw-r--r-- | WebCore/platform/graphics/mac/GraphicsLayerCA.mm | 8 | ||||
-rw-r--r-- | WebCore/platform/graphics/mac/WebLayer.h | 8 | ||||
-rw-r--r-- | WebCore/platform/graphics/mac/WebLayer.mm | 51 | ||||
-rw-r--r-- | WebCore/platform/graphics/mac/WebTiledLayer.mm | 22 |
7 files changed, 141 insertions, 54 deletions
diff --git a/WebCore/platform/graphics/mac/ComplexTextController.cpp b/WebCore/platform/graphics/mac/ComplexTextController.cpp index 61c9a59..da381f2 100644 --- a/WebCore/platform/graphics/mac/ComplexTextController.cpp +++ b/WebCore/platform/graphics/mac/ComplexTextController.cpp @@ -431,6 +431,7 @@ void ComplexTextController::advance(unsigned offset, GlyphBuffer* glyphBuffer) void ComplexTextController::adjustGlyphsAndAdvances() { + CGFloat widthSinceLastRounding = 0; size_t runCount = m_complexTextRuns.size(); for (size_t r = 0; r < runCount; ++r) { ComplexTextRun& complexTextRun = *m_complexTextRuns[r]; @@ -473,8 +474,8 @@ void ComplexTextController::adjustGlyphsAndAdvances() CGSize advance = treatAsSpace ? CGSizeMake(fontData->spaceWidth(), advances[i].height) : advances[i]; if (ch == '\t' && m_run.allowTabs()) { - float tabWidth = m_font.tabWidth(); - advance.width = tabWidth - fmodf(m_run.xPos() + m_totalWidth, tabWidth); + float tabWidth = m_font.tabWidth(*fontData); + advance.width = tabWidth - fmodf(m_run.xPos() + m_totalWidth + widthSinceLastRounding, tabWidth); } else if (ch == zeroWidthSpace || Font::treatAsZeroWidthSpace(ch) && !treatAsSpace) { advance.width = 0; glyph = fontData->spaceGlyph(); @@ -532,21 +533,23 @@ void ComplexTextController::adjustGlyphsAndAdvances() // Check to see if the next character is a "rounding hack character", if so, adjust the // width so that the total run width will be on an integer boundary. if (m_run.applyWordRounding() && !lastGlyph && Font::isRoundingHackCharacter(nextCh) || m_run.applyRunRounding() && lastGlyph) { - CGFloat totalWidth = m_totalWidth + advance.width; - CGFloat extraWidth = ceilCGFloat(totalWidth) - totalWidth; + CGFloat totalWidth = widthSinceLastRounding + advance.width; + widthSinceLastRounding = ceilCGFloat(totalWidth); + CGFloat extraWidth = widthSinceLastRounding - totalWidth; if (m_run.ltr()) advance.width += extraWidth; else { - m_totalWidth += extraWidth; if (m_lastRoundingGlyph) m_adjustedAdvances[m_lastRoundingGlyph - 1].width += extraWidth; else m_finalRoundingWidth = extraWidth; m_lastRoundingGlyph = m_adjustedAdvances.size() + 1; } - } + m_totalWidth += widthSinceLastRounding; + widthSinceLastRounding = 0; + } else + widthSinceLastRounding += advance.width; - m_totalWidth += advance.width; advance.height *= -1; m_adjustedAdvances.append(advance); m_adjustedGlyphs.append(glyph); @@ -565,6 +568,7 @@ void ComplexTextController::adjustGlyphsAndAdvances() if (!isMonotonic) complexTextRun.setIsNonMonotonic(); } + m_totalWidth += widthSinceLastRounding; } } // namespace WebCore diff --git a/WebCore/platform/graphics/mac/GraphicsContext3DMac.mm b/WebCore/platform/graphics/mac/GraphicsContext3DMac.mm index 961ec45..30c3b8e 100644 --- a/WebCore/platform/graphics/mac/GraphicsContext3DMac.mm +++ b/WebCore/platform/graphics/mac/GraphicsContext3DMac.mm @@ -34,14 +34,18 @@ #include "ImageBuffer.h" #include "NotImplemented.h" #include "WebGLActiveInfo.h" +#include "ArrayBuffer.h" #include "ArrayBufferView.h" #include "WebGLBuffer.h" #include "Float32Array.h" #include "WebGLFramebuffer.h" +#include "GraphicsContext.h" +#include "HTMLCanvasElement.h" #include "Int32Array.h" #include "WebGLLayer.h" #include "WebGLProgram.h" #include "WebGLRenderbuffer.h" +#include "WebGLRenderingContext.h" #include "WebGLShader.h" #include "WebGLTexture.h" #include "Uint8Array.h" @@ -236,6 +240,54 @@ void GraphicsContext3D::makeContextCurrent() CGLSetCurrentContext(m_contextObj); } +void GraphicsContext3D::paintRenderingResultsToCanvas(WebGLRenderingContext* context) +{ + HTMLCanvasElement* canvas = context->canvas(); + ImageBuffer* imageBuffer = canvas->buffer(); + + int rowBytes = m_currentWidth * 4; + int totalBytes = rowBytes * m_currentHeight; + + OwnArrayPtr<unsigned char> pixels(new unsigned char[totalBytes]); + if (!pixels) + return; + + CGLSetCurrentContext(m_contextObj); + + bool mustRestoreFBO = false; + if (m_attrs.antialias) { + ::glBindFramebufferEXT(GL_READ_FRAMEBUFFER_EXT, m_multisampleFBO); + ::glBindFramebufferEXT(GL_DRAW_FRAMEBUFFER_EXT, m_fbo); + ::glBlitFramebufferEXT(0, 0, m_currentWidth, m_currentHeight, 0, 0, m_currentWidth, m_currentHeight, GL_COLOR_BUFFER_BIT, GL_LINEAR); + ::glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, m_fbo); + mustRestoreFBO = true; + } else { + if (m_boundFBO != m_fbo) { + mustRestoreFBO = true; + ::glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, m_fbo); + } + } + + GLint packAlignment = 4; + bool mustRestorePackAlignment = false; + ::glGetIntegerv(GL_PACK_ALIGNMENT, &packAlignment); + if (packAlignment > 4) { + ::glPixelStorei(GL_PACK_ALIGNMENT, 4); + mustRestorePackAlignment = true; + } + + ::glReadPixels(0, 0, m_currentWidth, m_currentHeight, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, pixels.get()); + + if (mustRestorePackAlignment) + ::glPixelStorei(GL_PACK_ALIGNMENT, packAlignment); + + if (mustRestoreFBO) + ::glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, m_boundFBO); + + paintToCanvas(pixels.get(), m_currentWidth, m_currentHeight, + canvas->width(), canvas->height(), imageBuffer->context()->platformContext()); +} + void GraphicsContext3D::beginPaint(WebGLRenderingContext* context) { UNUSED_PARAM(context); @@ -494,6 +546,16 @@ void GraphicsContext3D::bufferData(unsigned long target, int size, unsigned long ensureContext(m_contextObj); ::glBufferData(target, size, 0, usage); } + +void GraphicsContext3D::bufferData(unsigned long target, ArrayBuffer* array, unsigned long usage) +{ + if (!array || !array->byteLength()) + return; + + ensureContext(m_contextObj); + ::glBufferData(target, array->byteLength(), array->data(), usage); +} + void GraphicsContext3D::bufferData(unsigned long target, ArrayBufferView* array, unsigned long usage) { if (!array || !array->length()) @@ -503,6 +565,15 @@ void GraphicsContext3D::bufferData(unsigned long target, ArrayBufferView* array, ::glBufferData(target, array->byteLength(), array->baseAddress(), usage); } +void GraphicsContext3D::bufferSubData(unsigned long target, long offset, ArrayBuffer* array) +{ + if (!array || !array->byteLength()) + return; + + ensureContext(m_contextObj); + ::glBufferSubData(target, offset, array->byteLength(), array->data()); +} + void GraphicsContext3D::bufferSubData(unsigned long target, long offset, ArrayBufferView* array) { if (!array || !array->length()) @@ -1216,6 +1287,10 @@ void GraphicsContext3D::getIntegerv(unsigned long pname, int* value) // Need to emulate IMPLEMENTATION_COLOR_READ_FORMAT/TYPE for GL. Any valid // combination should work, but GL_RGB/GL_UNSIGNED_BYTE might be the most // useful for desktop WebGL users. + // Need to emulate MAX_FRAGMENT/VERTEX_UNIFORM_VECTORS and MAX_VARYING_VECTORS + // because desktop GL's corresponding queries return the number of components + // whereas GLES2 return the number of vectors (each vector has 4 components). + // Therefore, the value returned by desktop GL needs to be divided by 4. ensureContext(m_contextObj); switch (pname) { case IMPLEMENTATION_COLOR_READ_FORMAT: @@ -1224,6 +1299,18 @@ void GraphicsContext3D::getIntegerv(unsigned long pname, int* value) case IMPLEMENTATION_COLOR_READ_TYPE: *value = GL_UNSIGNED_BYTE; break; + case MAX_FRAGMENT_UNIFORM_VECTORS: + ::glGetIntegerv(GL_MAX_FRAGMENT_UNIFORM_COMPONENTS, value); + *value /= 4; + break; + case MAX_VERTEX_UNIFORM_VECTORS: + ::glGetIntegerv(GL_MAX_VERTEX_UNIFORM_COMPONENTS, value); + *value /= 4; + break; + case MAX_VARYING_VECTORS: + ::glGetIntegerv(GL_MAX_VARYING_FLOATS, value); + *value /= 4; + break; default: ::glGetIntegerv(pname, value); } diff --git a/WebCore/platform/graphics/mac/GraphicsLayerCA.h b/WebCore/platform/graphics/mac/GraphicsLayerCA.h index 7d78dee..80c822c 100644 --- a/WebCore/platform/graphics/mac/GraphicsLayerCA.h +++ b/WebCore/platform/graphics/mac/GraphicsLayerCA.h @@ -106,6 +106,7 @@ public: #if ENABLE(3D_CANVAS) virtual void setContentsToWebGL(PlatformLayer*); #endif + virtual bool hasContentsLayer() const { return m_contentsLayer; } virtual PlatformLayer* platformLayer() const; diff --git a/WebCore/platform/graphics/mac/GraphicsLayerCA.mm b/WebCore/platform/graphics/mac/GraphicsLayerCA.mm index 43b3f3e..9f1ac83 100644 --- a/WebCore/platform/graphics/mac/GraphicsLayerCA.mm +++ b/WebCore/platform/graphics/mac/GraphicsLayerCA.mm @@ -1057,11 +1057,11 @@ void GraphicsLayerCA::updateSublayerList() void GraphicsLayerCA::updateLayerPosition() { - // FIXME: if constrained the size, the position will be wrong. Fixing this is not trivial. + FloatSize usedSize = m_usingTiledLayer ? constrainedSize() : m_size; // Position is offset on the layer by the layer anchor point. - CGPoint posPoint = CGPointMake(m_position.x() + m_anchorPoint.x() * m_size.width(), - m_position.y() + m_anchorPoint.y() * m_size.height()); + CGPoint posPoint = CGPointMake(m_position.x() + m_anchorPoint.x() * usedSize.width(), + m_position.y() + m_anchorPoint.y() * usedSize.height()); [primaryLayer() setPosition:posPoint]; @@ -2271,8 +2271,6 @@ void GraphicsLayerCA::updateContentsTransform() contentsTransform = CGAffineTransformTranslate(contentsTransform, 0, -[m_layer.get() bounds].size.height); [m_layer.get() setContentsTransform:contentsTransform]; } -#else - ASSERT(contentsOrientation() == CompositingCoordinatesTopDown); #endif } diff --git a/WebCore/platform/graphics/mac/WebLayer.h b/WebCore/platform/graphics/mac/WebLayer.h index af53ae6..3a91f04 100644 --- a/WebCore/platform/graphics/mac/WebLayer.h +++ b/WebCore/platform/graphics/mac/WebLayer.h @@ -53,12 +53,12 @@ namespace WebCore { { WebCore::GraphicsLayer* m_layerOwner; } - -// Class method allows us to share implementation across TiledLayerMac and WebLayer -+ (void)drawContents:(WebCore::GraphicsLayer*)layerContents ofLayer:(CALayer*)layer intoContext:(CGContextRef)context; - @end +// Functions allows us to share implementation across WebTiledLayer and WebLayer +void drawLayerContents(CGContextRef, CALayer *, WebCore::GraphicsLayer*); +void setLayerNeedsDisplayInRect(CALayer *, WebCore::GraphicsLayer*, CGRect); + #endif // USE(ACCELERATED_COMPOSITING) #endif // WebLayer_h diff --git a/WebCore/platform/graphics/mac/WebLayer.mm b/WebCore/platform/graphics/mac/WebLayer.mm index 0c9925e..9bb8212 100644 --- a/WebCore/platform/graphics/mac/WebLayer.mm +++ b/WebCore/platform/graphics/mac/WebLayer.mm @@ -31,6 +31,7 @@ #import "GraphicsContext.h" #import "GraphicsLayer.h" +#import <objc/objc-runtime.h> #import <QuartzCore/QuartzCore.h> #import <wtf/UnusedParam.h> @@ -38,7 +39,7 @@ using namespace WebCore; @implementation WebLayer -+ (void)drawContents:(WebCore::GraphicsLayer*)layerContents ofLayer:(CALayer*)layer intoContext:(CGContextRef)context +void drawLayerContents(CGContextRef context, CALayer *layer, WebCore::GraphicsLayer* layerContents) { if (!layerContents) return; @@ -110,6 +111,34 @@ using namespace WebCore; CGContextRestoreGState(context); } +void setLayerNeedsDisplayInRect(CALayer *layer, WebCore::GraphicsLayer* layerContents, CGRect rect) +{ + if (layerContents && layerContents->client() && layerContents->drawsContent()) { + struct objc_super layerSuper = { layer, class_getSuperclass(object_getClass(layer)) }; +#if defined(BUILDING_ON_LEOPARD) + rect = CGRectApplyAffineTransform(rect, [layer contentsTransform]); +#else + if (layerContents->contentsOrientation() == WebCore::GraphicsLayer::CompositingCoordinatesBottomUp) + rect.origin.y = [layer bounds].size.height - rect.origin.y - rect.size.height; +#endif + objc_msgSendSuper(&layerSuper, @selector(setNeedsDisplayInRect:), rect); + +#ifndef NDEBUG + if (layerContents->showRepaintCounter()) { + CGRect bounds = [layer bounds]; + CGRect indicatorRect = CGRectMake(bounds.origin.x, bounds.origin.y, 46, 25); +#if defined(BUILDING_ON_LEOPARD) + indicatorRect = CGRectApplyAffineTransform(indicatorRect, [layer contentsTransform]); +#else + if (layerContents->contentsOrientation() == WebCore::GraphicsLayer::CompositingCoordinatesBottomUp) + indicatorRect.origin.y = [layer bounds].size.height - indicatorRect.origin.y - indicatorRect.size.height; +#endif + objc_msgSendSuper(&layerSuper, @selector(setNeedsDisplayInRect:), indicatorRect); + } +#endif + } +} + // Disable default animations - (id<CAAction>)actionForKey:(NSString *)key { @@ -134,23 +163,7 @@ using namespace WebCore; - (void)setNeedsDisplayInRect:(CGRect)dirtyRect { - if (m_layerOwner && m_layerOwner->client() && m_layerOwner->drawsContent()) { -#if defined(BUILDING_ON_LEOPARD) - dirtyRect = CGRectApplyAffineTransform(dirtyRect, [self contentsTransform]); -#endif - [super setNeedsDisplayInRect:dirtyRect]; - -#ifndef NDEBUG - if (m_layerOwner->showRepaintCounter()) { - CGRect bounds = [self bounds]; - CGRect indicatorRect = CGRectMake(bounds.origin.x, bounds.origin.y, 46, 25); -#if defined(BUILDING_ON_LEOPARD) - indicatorRect = CGRectApplyAffineTransform(indicatorRect, [self contentsTransform]); -#endif - [super setNeedsDisplayInRect:indicatorRect]; - } -#endif - } + setLayerNeedsDisplayInRect(self, m_layerOwner, dirtyRect); } - (void)display @@ -162,7 +175,7 @@ using namespace WebCore; - (void)drawInContext:(CGContextRef)context { - [WebLayer drawContents:m_layerOwner ofLayer:self intoContext:context]; + drawLayerContents(context, self, m_layerOwner); } @end // implementation WebLayer diff --git a/WebCore/platform/graphics/mac/WebTiledLayer.mm b/WebCore/platform/graphics/mac/WebTiledLayer.mm index 97ba233..72128ad 100644 --- a/WebCore/platform/graphics/mac/WebTiledLayer.mm +++ b/WebCore/platform/graphics/mac/WebTiledLayer.mm @@ -73,23 +73,7 @@ using namespace WebCore; - (void)setNeedsDisplayInRect:(CGRect)dirtyRect { - if (m_layerOwner && m_layerOwner->client() && m_layerOwner->drawsContent()) { -#if defined(BUILDING_ON_LEOPARD) - dirtyRect = CGRectApplyAffineTransform(dirtyRect, [self contentsTransform]); -#endif - [super setNeedsDisplayInRect:dirtyRect]; - -#ifndef NDEBUG - if (m_layerOwner->showRepaintCounter()) { - CGRect bounds = [self bounds]; - CGRect indicatorRect = CGRectMake(bounds.origin.x, bounds.origin.y, 46, 25); -#if defined(BUILDING_ON_LEOPARD) - indicatorRect = CGRectApplyAffineTransform(indicatorRect, [self contentsTransform]); -#endif - [super setNeedsDisplayInRect:indicatorRect]; - } -#endif - } + setLayerNeedsDisplayInRect(self, m_layerOwner, dirtyRect); } - (void)display @@ -99,9 +83,9 @@ using namespace WebCore; m_layerOwner->didDisplay(self); } -- (void)drawInContext:(CGContextRef)ctx +- (void)drawInContext:(CGContextRef)context { - [WebLayer drawContents:m_layerOwner ofLayer:self intoContext:ctx]; + drawLayerContents(context, self, m_layerOwner); } @end // implementation WebTiledLayer |