summaryrefslogtreecommitdiffstats
path: root/WebCore/platform/graphics
diff options
context:
space:
mode:
Diffstat (limited to 'WebCore/platform/graphics')
-rw-r--r--WebCore/platform/graphics/GraphicsContext.h8
-rw-r--r--WebCore/platform/graphics/GraphicsContext3D.cpp5
-rw-r--r--WebCore/platform/graphics/GraphicsContext3D.h15
-rw-r--r--WebCore/platform/graphics/ImageSource.cpp5
-rw-r--r--WebCore/platform/graphics/ImageSource.h3
-rw-r--r--WebCore/platform/graphics/MediaPlayer.cpp67
-rw-r--r--WebCore/platform/graphics/cairo/FontCairo.cpp8
-rw-r--r--WebCore/platform/graphics/cairo/GraphicsContextCairo.cpp43
-rw-r--r--WebCore/platform/graphics/cairo/GraphicsContextPlatformPrivateCairo.h1
-rw-r--r--WebCore/platform/graphics/cairo/ImageBufferCairo.cpp15
-rw-r--r--WebCore/platform/graphics/cairo/ImageCairo.cpp14
-rw-r--r--WebCore/platform/graphics/cairo/PlatformRefPtrCairo.cpp (renamed from WebCore/platform/graphics/cairo/GRefPtrCairo.cpp)10
-rw-r--r--WebCore/platform/graphics/cairo/PlatformRefPtrCairo.h (renamed from WebCore/platform/graphics/cairo/GRefPtrCairo.h)14
-rw-r--r--WebCore/platform/graphics/cg/ImageSourceCG.cpp4
-rw-r--r--WebCore/platform/graphics/chromium/CanvasLayerChromium.cpp76
-rw-r--r--WebCore/platform/graphics/chromium/CanvasLayerChromium.h27
-rw-r--r--WebCore/platform/graphics/chromium/ContentLayerChromium.cpp301
-rw-r--r--WebCore/platform/graphics/chromium/ContentLayerChromium.h90
-rw-r--r--WebCore/platform/graphics/chromium/GLES2Canvas.cpp66
-rw-r--r--WebCore/platform/graphics/chromium/GLES2Canvas.h2
-rw-r--r--WebCore/platform/graphics/chromium/GraphicsLayerChromium.cpp6
-rw-r--r--WebCore/platform/graphics/chromium/ImageLayerChromium.cpp19
-rw-r--r--WebCore/platform/graphics/chromium/ImageLayerChromium.h8
-rw-r--r--WebCore/platform/graphics/chromium/LayerChromium.cpp331
-rw-r--r--WebCore/platform/graphics/chromium/LayerChromium.h125
-rw-r--r--WebCore/platform/graphics/chromium/LayerRendererChromium.cpp664
-rw-r--r--WebCore/platform/graphics/chromium/LayerRendererChromium.h91
-rwxr-xr-xWebCore/platform/graphics/chromium/TilingData.cpp16
-rw-r--r--WebCore/platform/graphics/chromium/VideoFrameChromium.h (renamed from WebCore/platform/graphics/chromium/TransformLayerChromium.cpp)59
-rw-r--r--WebCore/platform/graphics/chromium/VideoFrameProvider.h (renamed from WebCore/platform/graphics/chromium/TransformLayerChromium.h)32
-rw-r--r--WebCore/platform/graphics/chromium/VideoLayerChromium.cpp28
-rw-r--r--WebCore/platform/graphics/chromium/VideoLayerChromium.h15
-rw-r--r--WebCore/platform/graphics/filters/FEComposite.cpp2
-rw-r--r--WebCore/platform/graphics/filters/FEGaussianBlur.cpp6
-rw-r--r--WebCore/platform/graphics/filters/FEGaussianBlur.h2
-rw-r--r--WebCore/platform/graphics/gstreamer/GStreamerGWorld.cpp164
-rw-r--r--WebCore/platform/graphics/gstreamer/GStreamerGWorld.h24
-rw-r--r--WebCore/platform/graphics/gstreamer/MediaPlayerPrivateGStreamer.cpp3
-rw-r--r--WebCore/platform/graphics/gstreamer/PlatformVideoWindow.h54
-rw-r--r--WebCore/platform/graphics/gstreamer/PlatformVideoWindowGtk.cpp60
-rw-r--r--WebCore/platform/graphics/gtk/ImageBufferGtk.cpp2
-rw-r--r--WebCore/platform/graphics/mac/FontCustomPlatformData.cpp2
-rw-r--r--WebCore/platform/graphics/mac/FontPlatformDataMac.mm18
-rw-r--r--WebCore/platform/graphics/mac/GraphicsContext3DMac.mm42
-rw-r--r--WebCore/platform/graphics/mac/GraphicsLayerCA.mm15
-rw-r--r--WebCore/platform/graphics/qt/ContextShadow.cpp162
-rw-r--r--WebCore/platform/graphics/qt/ContextShadow.h33
-rw-r--r--WebCore/platform/graphics/qt/FontQt.cpp82
-rw-r--r--WebCore/platform/graphics/qt/GradientQt.cpp25
-rw-r--r--WebCore/platform/graphics/qt/GraphicsContext3DQt.cpp110
-rw-r--r--WebCore/platform/graphics/qt/GraphicsContextQt.cpp105
-rw-r--r--WebCore/platform/graphics/qt/GraphicsLayerQt.h3
-rw-r--r--WebCore/platform/graphics/qt/ImageBufferQt.cpp12
-rw-r--r--WebCore/platform/graphics/qt/ImageDecoderQt.cpp20
-rw-r--r--WebCore/platform/graphics/qt/ImageDecoderQt.h2
-rw-r--r--WebCore/platform/graphics/qt/TransparencyLayer.h2
-rw-r--r--WebCore/platform/graphics/skia/BitmapImageSingleFrameSkia.h11
-rw-r--r--WebCore/platform/graphics/skia/GraphicsContext3DSkia.cpp32
-rw-r--r--WebCore/platform/graphics/skia/GraphicsContextSkia.cpp4
-rw-r--r--WebCore/platform/graphics/skia/ImageBufferSkia.cpp13
-rw-r--r--WebCore/platform/graphics/skia/ImageSkia.cpp21
-rw-r--r--WebCore/platform/graphics/skia/NativeImageSkia.cpp8
-rw-r--r--WebCore/platform/graphics/skia/NativeImageSkia.h5
-rw-r--r--WebCore/platform/graphics/skia/PlatformContextSkia.cpp8
-rw-r--r--WebCore/platform/graphics/win/FontCustomPlatformDataCairo.cpp8
-rw-r--r--WebCore/platform/graphics/win/FontCustomPlatformDataCairo.h9
-rw-r--r--WebCore/platform/graphics/win/WKCACFLayer.cpp30
-rw-r--r--WebCore/platform/graphics/win/WKCACFLayer.h23
-rwxr-xr-xWebCore/platform/graphics/win/WebTiledLayer.cpp20
-rw-r--r--WebCore/platform/graphics/win/WebTiledLayer.h4
70 files changed, 2136 insertions, 1178 deletions
diff --git a/WebCore/platform/graphics/GraphicsContext.h b/WebCore/platform/graphics/GraphicsContext.h
index c48f91a..1056d81 100644
--- a/WebCore/platform/graphics/GraphicsContext.h
+++ b/WebCore/platform/graphics/GraphicsContext.h
@@ -48,6 +48,9 @@ class SurfaceOpenVG;
typedef class WebCore::SurfaceOpenVG PlatformGraphicsContext;
#elif PLATFORM(QT)
#include <QPainter>
+namespace WebCore {
+class ContextShadow;
+}
typedef QPainter PlatformGraphicsContext;
#elif PLATFORM(WX)
class wxGCDC;
@@ -329,8 +332,8 @@ namespace WebCore {
void setAlpha(float);
#if PLATFORM(CAIRO)
float getAlpha();
- void createPlatformShadow(PassOwnPtr<ImageBuffer> buffer, const Color& shadowColor, const FloatRect& shadowRect, float kernelSize);
- static void calculateShadowBufferDimensions(IntSize& shadowBufferSize, FloatRect& shadowRect, float& kernelSize, const FloatRect& sourceRect, const FloatSize& shadowSize, float shadowBlur);
+ void createPlatformShadow(PassOwnPtr<ImageBuffer> buffer, const Color& shadowColor, const FloatRect& shadowRect, float radius);
+ static void calculateShadowBufferDimensions(IntSize& shadowBufferSize, FloatRect& shadowRect, float& radius, const FloatRect& sourceRect, const FloatSize& shadowSize, float shadowBlur);
#endif
void setCompositeOperation(CompositeOperator);
@@ -431,6 +434,7 @@ namespace WebCore {
void pushTransparencyLayerInternal(const QRect &rect, qreal opacity, QPixmap& alphaMask);
QPen pen();
static QPainter::CompositionMode toQtCompositionMode(CompositeOperator op);
+ ContextShadow* contextShadow();
#endif
#if PLATFORM(GTK)
diff --git a/WebCore/platform/graphics/GraphicsContext3D.cpp b/WebCore/platform/graphics/GraphicsContext3D.cpp
index 51c4cd5..170bb84 100644
--- a/WebCore/platform/graphics/GraphicsContext3D.cpp
+++ b/WebCore/platform/graphics/GraphicsContext3D.cpp
@@ -144,7 +144,7 @@ bool GraphicsContext3D::extractTextureData(unsigned int width, unsigned int heig
unsigned int format, unsigned int type,
unsigned int unpackAlignment,
bool flipY, bool premultiplyAlpha,
- ArrayBufferView* pixels,
+ const void* pixels,
Vector<uint8_t>& data)
{
// Assumes format, type, etc. have already been validated.
@@ -193,7 +193,7 @@ bool GraphicsContext3D::extractTextureData(unsigned int width, unsigned int heig
unsigned long bytesPerPixel = componentsPerPixel * bytesPerComponent;
data.resize(width * height * bytesPerPixel);
- if (!packPixels(static_cast<uint8_t*>(pixels->baseAddress()),
+ if (!packPixels(static_cast<const uint8_t*>(pixels),
sourceDataFormat,
width, height, unpackAlignment,
format, type,
@@ -424,6 +424,7 @@ void packRGBA8ToRGBA8Premultiply(const uint8_t* source, uint8_t* destination)
destination[0] = sourceR;
destination[1] = sourceG;
destination[2] = sourceB;
+ destination[3] = source[3];
}
// FIXME: this routine is lossy and must be removed.
diff --git a/WebCore/platform/graphics/GraphicsContext3D.h b/WebCore/platform/graphics/GraphicsContext3D.h
index 25d1d06..b583813 100644
--- a/WebCore/platform/graphics/GraphicsContext3D.h
+++ b/WebCore/platform/graphics/GraphicsContext3D.h
@@ -77,15 +77,10 @@ const Platform3DObject NullPlatform3DObject = 0;
#endif
namespace WebCore {
-class ArrayBuffer;
-class ArrayBufferView;
class CanvasRenderingContext;
-class Float32Array;
class HostWindow;
class Image;
class ImageData;
-class Int32Array;
-class Uint8Array;
class WebGLActiveInfo;
struct ActiveInfo {
@@ -468,6 +463,8 @@ public:
int sizeInBytes(int type);
bool isGLES2Compliant() const;
+ bool isGLES2NPOTStrict() const;
+ bool isErrorGeneratedOnOutOfBoundsAccesses() const;
//----------------------------------------------------------------------
// Helpers for texture uploading and pixel readback.
@@ -512,7 +509,7 @@ public:
unsigned int format, unsigned int type,
unsigned int unpackAlignment,
bool flipY, bool premultiplyAlpha,
- ArrayBufferView* pixels,
+ const void* pixels,
Vector<uint8_t>& data);
// Flips the given image data vertically, in-place.
@@ -556,10 +553,8 @@ public:
void blendFuncSeparate(unsigned long srcRGB, unsigned long dstRGB, unsigned long srcAlpha, unsigned long dstAlpha);
void bufferData(unsigned long target, int size, unsigned long usage);
- void bufferData(unsigned long target, ArrayBuffer* data, unsigned long usage);
- void bufferData(unsigned long target, ArrayBufferView* data, unsigned long usage);
- void bufferSubData(unsigned long target, long offset, ArrayBuffer* data);
- void bufferSubData(unsigned long target, long offset, ArrayBufferView* data);
+ void bufferData(unsigned long target, int size, const void* data, unsigned long usage);
+ void bufferSubData(unsigned long target, long offset, int size, const void* data);
unsigned long checkFramebufferStatus(unsigned long target);
void clear(unsigned long mask);
diff --git a/WebCore/platform/graphics/ImageSource.cpp b/WebCore/platform/graphics/ImageSource.cpp
index 7f6d323..c6d97fe 100644
--- a/WebCore/platform/graphics/ImageSource.cpp
+++ b/WebCore/platform/graphics/ImageSource.cpp
@@ -41,8 +41,9 @@ namespace WebCore {
unsigned ImageSource::s_maxPixelsPerDecodedImage = 1024 * 1024;
#endif
-ImageSource::ImageSource()
+ImageSource::ImageSource(bool premultiplyAlpha)
: m_decoder(0)
+ , m_premultiplyAlpha(premultiplyAlpha)
{
}
@@ -77,7 +78,7 @@ void ImageSource::setData(SharedBuffer* data, bool allDataReceived)
// If insufficient bytes are available to determine the image type, no decoder plugin will be
// made.
if (!m_decoder) {
- m_decoder = static_cast<NativeImageSourcePtr>(ImageDecoder::create(*data));
+ m_decoder = static_cast<NativeImageSourcePtr>(ImageDecoder::create(*data, m_premultiplyAlpha));
#if ENABLE(IMAGE_DECODER_DOWN_SAMPLING)
if (m_decoder && s_maxPixelsPerDecodedImage)
m_decoder->setMaxNumPixels(s_maxPixelsPerDecodedImage);
diff --git a/WebCore/platform/graphics/ImageSource.h b/WebCore/platform/graphics/ImageSource.h
index 014c136..189f0f5 100644
--- a/WebCore/platform/graphics/ImageSource.h
+++ b/WebCore/platform/graphics/ImageSource.h
@@ -133,7 +133,7 @@ const int cAnimationNone = -2;
class ImageSource : public Noncopyable {
public:
- ImageSource();
+ ImageSource(bool premultiplyAlpha = true);
~ImageSource();
// Tells the ImageSource that the Image no longer cares about decoded frame
@@ -201,6 +201,7 @@ private:
protected:
#endif
NativeImageSourcePtr m_decoder;
+ bool m_premultiplyAlpha;
#if ENABLE(IMAGE_DECODER_DOWN_SAMPLING)
static unsigned s_maxPixelsPerDecodedImage;
#endif
diff --git a/WebCore/platform/graphics/MediaPlayer.cpp b/WebCore/platform/graphics/MediaPlayer.cpp
index e72987a..87060a4 100644
--- a/WebCore/platform/graphics/MediaPlayer.cpp
+++ b/WebCore/platform/graphics/MediaPlayer.cpp
@@ -194,6 +194,24 @@ static void addMediaEngine(CreateMediaEnginePlayer constructor, MediaEngineSuppo
installedMediaEngines().append(new MediaPlayerFactory(constructor, getSupportedTypes, supportsType));
}
+static const AtomicString& applicationOctetStream()
+{
+ DEFINE_STATIC_LOCAL(const AtomicString, applicationOctetStream, ("application/octet-stream"));
+ return applicationOctetStream;
+}
+
+static const AtomicString& textPlain()
+{
+ DEFINE_STATIC_LOCAL(const AtomicString, textPlain, ("text/plain"));
+ return textPlain;
+}
+
+static const AtomicString& codecs()
+{
+ DEFINE_STATIC_LOCAL(const AtomicString, codecs, ("codecs"));
+ return codecs;
+}
+
static MediaPlayerFactory* chooseBestEngineForTypeAndCodecs(const String& type, const String& codecs)
{
Vector<MediaPlayerFactory*>& engines = installedMediaEngines();
@@ -201,6 +219,14 @@ static MediaPlayerFactory* chooseBestEngineForTypeAndCodecs(const String& type,
if (engines.isEmpty())
return 0;
+ // 4.8.10.3 MIME types - In the absence of a specification to the contrary, the MIME type "application/octet-stream"
+ // when used with parameters, e.g. "application/octet-stream;codecs=theora", is a type that the user agent knows
+ // it cannot render.
+ if (type == applicationOctetStream()) {
+ if (!codecs.isEmpty())
+ return 0;
+ }
+
MediaPlayerFactory* engine = 0;
MediaPlayer::SupportsType supported = MediaPlayer::IsNotSupported;
@@ -252,11 +278,11 @@ MediaPlayer::~MediaPlayer()
void MediaPlayer::load(const String& url, const ContentType& contentType)
{
- String type = contentType.type();
- String codecs = contentType.parameter("codecs");
+ String type = contentType.type().lower();
+ String typeCodecs = contentType.parameter(codecs());
- // if we don't know the MIME type, see if the extension can help
- if (type.isEmpty() || type == "application/octet-stream" || type == "text/plain") {
+ // If the MIME type is unhelpful, see if the type registry has a match for the file extension.
+ if (type.isEmpty() || type == applicationOctetStream() || type == textPlain()) {
size_t pos = url.reverseFind('.');
if (pos != notFound) {
String extension = url.substring(pos + 1);
@@ -268,14 +294,17 @@ void MediaPlayer::load(const String& url, const ContentType& contentType)
MediaPlayerFactory* engine = 0;
if (!type.isEmpty())
- engine = chooseBestEngineForTypeAndCodecs(type, codecs);
+ engine = chooseBestEngineForTypeAndCodecs(type, typeCodecs);
- // if we didn't find an engine that claims the MIME type, just use the first engine
- if (!engine && !installedMediaEngines().isEmpty())
+ // If we didn't find an engine and no MIME type is specified, just use the first engine.
+ if (!engine && type.isEmpty() && !installedMediaEngines().isEmpty())
engine = installedMediaEngines()[0];
- // don't delete and recreate the player unless it comes from a different engine
- if (engine && m_currentMediaEngine != engine) {
+ // Don't delete and recreate the player unless it comes from a different engine
+ if (!engine) {
+ m_currentMediaEngine = engine;
+ m_private.clear();
+ } else if (m_currentMediaEngine != engine) {
m_currentMediaEngine = engine;
m_private.clear();
m_private.set(engine->constructor(this));
@@ -532,14 +561,26 @@ void MediaPlayer::paintCurrentFrameInContext(GraphicsContext* p, const IntRect&
MediaPlayer::SupportsType MediaPlayer::supportsType(ContentType contentType)
{
- String type = contentType.type();
- String codecs = contentType.parameter("codecs");
- MediaPlayerFactory* engine = chooseBestEngineForTypeAndCodecs(type, codecs);
+ String type = contentType.type().lower();
+ String typeCodecs = contentType.parameter(codecs());
+
+ // 4.8.10.3 MIME types - In the absence of a specification to the contrary, the MIME type "application/octet-stream"
+ // when used with parameters, e.g. "application/octet-stream;codecs=theora", is a type that the user agent knows
+ // it cannot render.
+ if (type == applicationOctetStream()) {
+ if (!typeCodecs.isEmpty())
+ return IsNotSupported;
+
+ // The MIME type "application/octet-stream" with no parameters is never a type that the user agent knows it
+ // cannot render.
+ return MayBeSupported;
+ }
+ MediaPlayerFactory* engine = chooseBestEngineForTypeAndCodecs(type, typeCodecs);
if (!engine)
return IsNotSupported;
- return engine->supportsTypeAndCodecs(type, codecs);
+ return engine->supportsTypeAndCodecs(type, typeCodecs);
}
void MediaPlayer::getSupportedTypes(HashSet<String>& types)
diff --git a/WebCore/platform/graphics/cairo/FontCairo.cpp b/WebCore/platform/graphics/cairo/FontCairo.cpp
index 9217a81..f6d8f3d 100644
--- a/WebCore/platform/graphics/cairo/FontCairo.cpp
+++ b/WebCore/platform/graphics/cairo/FontCairo.cpp
@@ -94,15 +94,15 @@ void Font::drawGlyphs(GraphicsContext* context, const SimpleFontData* font, cons
FloatRect rect(FloatPoint(), FloatSize(extents.width, extents.height));
IntSize shadowBufferSize;
FloatRect shadowRect;
- float kernelSize = 0.f;
- GraphicsContext::calculateShadowBufferDimensions(shadowBufferSize, shadowRect, kernelSize, rect, shadowSize, shadowBlur);
+ float radius = 0;
+ context->calculateShadowBufferDimensions(shadowBufferSize, shadowRect, radius, rect, shadowSize, shadowBlur);
// Draw shadow into a new ImageBuffer
OwnPtr<ImageBuffer> shadowBuffer = ImageBuffer::create(shadowBufferSize);
GraphicsContext* shadowContext = shadowBuffer->context();
cairo_t* shadowCr = shadowContext->platformContext();
- cairo_translate(shadowCr, kernelSize, extents.height + kernelSize);
+ cairo_translate(shadowCr, radius, extents.height + radius);
cairo_set_scaled_font(shadowCr, font->platformData().scaledFont());
cairo_show_glyphs(shadowCr, glyphs, numGlyphs);
@@ -113,7 +113,7 @@ void Font::drawGlyphs(GraphicsContext* context, const SimpleFontData* font, cons
cairo_restore(shadowCr);
}
cairo_translate(cr, 0.0, -extents.height);
- context->createPlatformShadow(shadowBuffer.release(), shadowColor, shadowRect, kernelSize);
+ context->createPlatformShadow(shadowBuffer.release(), shadowColor, shadowRect, radius);
#else
cairo_translate(cr, shadowSize.width(), shadowSize.height());
cairo_show_glyphs(cr, glyphs, numGlyphs);
diff --git a/WebCore/platform/graphics/cairo/GraphicsContextCairo.cpp b/WebCore/platform/graphics/cairo/GraphicsContextCairo.cpp
index 9b3096e..3a667ac 100644
--- a/WebCore/platform/graphics/cairo/GraphicsContextCairo.cpp
+++ b/WebCore/platform/graphics/cairo/GraphicsContextCairo.cpp
@@ -61,6 +61,8 @@
#include "GraphicsContextPlatformPrivateCairo.h"
#include "GraphicsContextPrivate.h"
+using namespace std;
+
#ifndef M_PI
#define M_PI 3.14159265358979323846
#endif
@@ -173,18 +175,17 @@ static void addConvexPolygonToContext(cairo_t* context, size_t numPoints, const
cairo_close_path(context);
}
-void GraphicsContext::calculateShadowBufferDimensions(IntSize& shadowBufferSize, FloatRect& shadowRect, float& kernelSize, const FloatRect& sourceRect, const FloatSize& shadowSize, float shadowBlur)
+void GraphicsContext::calculateShadowBufferDimensions(IntSize& shadowBufferSize, FloatRect& shadowRect, float& radius, const FloatRect& sourceRect, const FloatSize& shadowSize, float shadowBlur)
{
#if ENABLE(FILTERS)
- // calculate the kernel size according to the HTML5 canvas shadow specification
- kernelSize = (shadowBlur < 8 ? shadowBlur / 2.f : sqrt(shadowBlur * 2.f));
- int blurRadius = ceil(kernelSize);
+ // limit radius to 128
+ radius = min(128.f, max(shadowBlur, 0.f));
- shadowBufferSize = IntSize(sourceRect.width() + blurRadius * 2, sourceRect.height() + blurRadius * 2);
+ shadowBufferSize = IntSize(sourceRect.width() + radius * 2, sourceRect.height() + radius * 2);
// determine dimensions of shadow rect
shadowRect = FloatRect(sourceRect.location(), shadowBufferSize);
- shadowRect.move(shadowSize.width() - kernelSize, shadowSize.height() - kernelSize);
+ shadowRect.move(shadowSize.width() - radius, shadowSize.height() - radius);
#endif
}
@@ -209,8 +210,8 @@ static inline void drawPathShadow(GraphicsContext* context, GraphicsContextPriva
IntSize shadowBufferSize;
FloatRect shadowRect;
- float kernelSize = 0;
- GraphicsContext::calculateShadowBufferDimensions(shadowBufferSize, shadowRect, kernelSize, rect, shadowSize, shadowBlur);
+ float radius = 0;
+ GraphicsContext::calculateShadowBufferDimensions(shadowBufferSize, shadowRect, radius, rect, shadowSize, shadowBlur);
// Create suitably-sized ImageBuffer to hold the shadow.
OwnPtr<ImageBuffer> shadowBuffer = ImageBuffer::create(shadowBufferSize);
@@ -218,7 +219,7 @@ static inline void drawPathShadow(GraphicsContext* context, GraphicsContextPriva
// Draw shadow into a new ImageBuffer.
cairo_t* shadowContext = shadowBuffer->context()->platformContext();
copyContextProperties(cr, shadowContext);
- cairo_translate(shadowContext, -rect.x() + kernelSize, -rect.y() + kernelSize);
+ cairo_translate(shadowContext, -rect.x() + radius, -rect.y() + radius);
cairo_new_path(shadowContext);
cairo_append_path(shadowContext, path);
@@ -227,7 +228,7 @@ static inline void drawPathShadow(GraphicsContext* context, GraphicsContextPriva
if (strokeShadow)
setPlatformStroke(context, shadowContext, gcp);
- context->createPlatformShadow(shadowBuffer.release(), shadowColor, shadowRect, kernelSize);
+ context->createPlatformShadow(shadowBuffer.release(), shadowColor, shadowRect, radius);
#endif
}
@@ -631,15 +632,15 @@ static void drawBorderlessRectShadow(GraphicsContext* context, const FloatRect&
IntSize shadowBufferSize;
FloatRect shadowRect;
- float kernelSize = 0;
- GraphicsContext::calculateShadowBufferDimensions(shadowBufferSize, shadowRect, kernelSize, rect, shadowSize, shadowBlur);
+ float radius = 0;
+ GraphicsContext::calculateShadowBufferDimensions(shadowBufferSize, shadowRect, radius, rect, shadowSize, shadowBlur);
// Draw shadow into a new ImageBuffer
OwnPtr<ImageBuffer> shadowBuffer = ImageBuffer::create(shadowBufferSize);
GraphicsContext* shadowContext = shadowBuffer->context();
- shadowContext->fillRect(FloatRect(FloatPoint(kernelSize, kernelSize), rect.size()), rectColor, DeviceColorSpace);
+ shadowContext->fillRect(FloatRect(FloatPoint(radius, radius), rect.size()), rectColor, DeviceColorSpace);
- context->createPlatformShadow(shadowBuffer.release(), shadowColor, shadowRect, kernelSize);
+ context->createPlatformShadow(shadowBuffer.release(), shadowColor, shadowRect, radius);
#endif
}
@@ -920,28 +921,28 @@ void GraphicsContext::setPlatformShadow(FloatSize const& size, float, Color cons
}
}
-void GraphicsContext::createPlatformShadow(PassOwnPtr<ImageBuffer> buffer, const Color& shadowColor, const FloatRect& shadowRect, float kernelSize)
+void GraphicsContext::createPlatformShadow(PassOwnPtr<ImageBuffer> buffer, const Color& shadowColor, const FloatRect& shadowRect, float radius)
{
#if ENABLE(FILTERS)
cairo_t* cr = m_data->cr;
- // draw the shadow without blurring, if kernelSize is zero
- if (!kernelSize) {
+ // calculate the standard deviation
+ float sd = FEGaussianBlur::calculateStdDeviation(radius);
+
+ // draw the shadow without blurring, if radius is zero
+ if (!radius || !sd) {
setColor(cr, shadowColor);
cairo_mask_surface(cr, buffer->m_data.m_surface, shadowRect.x(), shadowRect.y());
return;
}
- // limit kernel size to 1000, this is what CG is doing.
- kernelSize = std::min(1000.f, kernelSize);
-
// create filter
RefPtr<Filter> filter = ImageBufferFilter::create();
filter->setSourceImage(buffer);
RefPtr<FilterEffect> source = SourceGraphic::create();
source->setScaledSubRegion(FloatRect(FloatPoint(), shadowRect.size()));
source->setIsAlphaImage(true);
- RefPtr<FilterEffect> blur = FEGaussianBlur::create(source.get(), kernelSize, kernelSize);
+ RefPtr<FilterEffect> blur = FEGaussianBlur::create(source.get(), sd, sd);
blur->setScaledSubRegion(FloatRect(FloatPoint(), shadowRect.size()));
blur->apply(filter.get());
diff --git a/WebCore/platform/graphics/cairo/GraphicsContextPlatformPrivateCairo.h b/WebCore/platform/graphics/cairo/GraphicsContextPlatformPrivateCairo.h
index 97e7e07..81987ef 100644
--- a/WebCore/platform/graphics/cairo/GraphicsContextPlatformPrivateCairo.h
+++ b/WebCore/platform/graphics/cairo/GraphicsContextPlatformPrivateCairo.h
@@ -27,6 +27,7 @@
#include "GraphicsContext.h"
+#include "CairoPath.h"
#include <cairo.h>
#include <math.h>
#include <stdio.h>
diff --git a/WebCore/platform/graphics/cairo/ImageBufferCairo.cpp b/WebCore/platform/graphics/cairo/ImageBufferCairo.cpp
index db66276..976dcb4 100644
--- a/WebCore/platform/graphics/cairo/ImageBufferCairo.cpp
+++ b/WebCore/platform/graphics/cairo/ImageBufferCairo.cpp
@@ -38,10 +38,8 @@
#include "NotImplemented.h"
#include "Pattern.h"
#include "PlatformString.h"
-
#include <cairo.h>
#include <wtf/Vector.h>
-#include <math.h>
using namespace std;
@@ -100,7 +98,7 @@ GraphicsContext* ImageBuffer::context() const
bool ImageBuffer::drawsUsingCopy() const
{
- return true;
+ return false;
}
PassRefPtr<Image> ImageBuffer::copyImage() const
@@ -112,20 +110,23 @@ PassRefPtr<Image> ImageBuffer::copyImage() const
void ImageBuffer::clip(GraphicsContext*, const FloatRect&) const
{
notImplemented();
+ // See https://bugs.webkit.org/show_bug.cgi?id=23526 for why this is unimplemented.
}
void ImageBuffer::draw(GraphicsContext* context, ColorSpace styleColorSpace, const FloatRect& destRect, const FloatRect& srcRect,
CompositeOperator op , bool useLowQualityScale)
{
- RefPtr<Image> imageCopy = copyImage();
- context->drawImage(imageCopy.get(), styleColorSpace, destRect, srcRect, op, useLowQualityScale);
+ // BitmapImage will release the passed in surface on destruction
+ RefPtr<Image> image = BitmapImage::create(cairo_surface_reference(m_data.m_surface));
+ context->drawImage(image.get(), styleColorSpace, destRect, srcRect, op, useLowQualityScale);
}
void ImageBuffer::drawPattern(GraphicsContext* context, const FloatRect& srcRect, const AffineTransform& patternTransform,
const FloatPoint& phase, ColorSpace styleColorSpace, CompositeOperator op, const FloatRect& destRect)
{
- RefPtr<Image> imageCopy = copyImage();
- imageCopy->drawPattern(context, srcRect, patternTransform, phase, styleColorSpace, op, destRect);
+ // BitmapImage will release the passed in surface on destruction
+ RefPtr<Image> image = BitmapImage::create(cairo_surface_reference(m_data.m_surface));
+ image->drawPattern(context, srcRect, patternTransform, phase, styleColorSpace, op, destRect);
}
void ImageBuffer::platformTransformColorSpace(const Vector<int>& lookUpTable)
diff --git a/WebCore/platform/graphics/cairo/ImageCairo.cpp b/WebCore/platform/graphics/cairo/ImageCairo.cpp
index 1582671..d9eb5e6 100644
--- a/WebCore/platform/graphics/cairo/ImageCairo.cpp
+++ b/WebCore/platform/graphics/cairo/ImageCairo.cpp
@@ -33,7 +33,7 @@
#include "AffineTransform.h"
#include "Color.h"
#include "FloatRect.h"
-#include "GRefPtrCairo.h"
+#include "PlatformRefPtrCairo.h"
#include "GraphicsContext.h"
#include "ImageBuffer.h"
#include "ImageObserver.h"
@@ -141,8 +141,8 @@ void BitmapImage::draw(GraphicsContext* context, const FloatRect& dst, const Flo
if (context->getShadow(shadowSize, shadowBlur, shadowColor)) {
IntSize shadowBufferSize;
FloatRect shadowRect;
- float kernelSize (0.0);
- GraphicsContext::calculateShadowBufferDimensions(shadowBufferSize, shadowRect, kernelSize, dstRect, shadowSize, shadowBlur);
+ float radius = 0;
+ context->calculateShadowBufferDimensions(shadowBufferSize, shadowRect, radius, dstRect, shadowSize, shadowBlur);
shadowColor = colorWithOverrideAlpha(shadowColor.rgb(), (shadowColor.alpha() * context->getAlpha()) / 255.f);
//draw shadow into a new ImageBuffer
@@ -153,7 +153,7 @@ void BitmapImage::draw(GraphicsContext* context, const FloatRect& dst, const Flo
cairo_rectangle(shadowContext, 0, 0, dstRect.width(), dstRect.height());
cairo_fill(shadowContext);
- context->createPlatformShadow(shadowBuffer.release(), shadowColor, shadowRect, kernelSize);
+ context->createPlatformShadow(shadowBuffer.release(), shadowColor, shadowRect, radius);
}
#endif
@@ -185,11 +185,11 @@ void Image::drawPattern(GraphicsContext* context, const FloatRect& tileRect, con
cairo_t* cr = context->platformContext();
context->save();
- GRefPtr<cairo_surface_t> clippedImageSurface = 0;
+ PlatformRefPtr<cairo_surface_t> clippedImageSurface = 0;
if (tileRect.size() != size()) {
IntRect imageSize = enclosingIntRect(tileRect);
- clippedImageSurface = adoptGRef(cairo_image_surface_create(CAIRO_FORMAT_ARGB32, imageSize.width(), imageSize.height()));
- GRefPtr<cairo_t> clippedImageContext(cairo_create(clippedImageSurface.get()));
+ clippedImageSurface = adoptPlatformRef(cairo_image_surface_create(CAIRO_FORMAT_ARGB32, imageSize.width(), imageSize.height()));
+ PlatformRefPtr<cairo_t> clippedImageContext(cairo_create(clippedImageSurface.get()));
cairo_set_source_surface(clippedImageContext.get(), image, -tileRect.x(), -tileRect.y());
cairo_paint(clippedImageContext.get());
image = clippedImageSurface.get();
diff --git a/WebCore/platform/graphics/cairo/GRefPtrCairo.cpp b/WebCore/platform/graphics/cairo/PlatformRefPtrCairo.cpp
index d244954..6870560 100644
--- a/WebCore/platform/graphics/cairo/GRefPtrCairo.cpp
+++ b/WebCore/platform/graphics/cairo/PlatformRefPtrCairo.cpp
@@ -17,33 +17,33 @@
*/
#include "config.h"
-#include "GRefPtrCairo.h"
+#include "PlatformRefPtrCairo.h"
#include <cairo.h>
namespace WTF {
-template <> cairo_t* refGPtr(cairo_t* ptr)
+template <> cairo_t* refPlatformPtr(cairo_t* ptr)
{
if (ptr)
cairo_reference(ptr);
return ptr;
}
-template <> void derefGPtr(cairo_t* ptr)
+template <> void derefPlatformPtr(cairo_t* ptr)
{
if (ptr)
cairo_destroy(ptr);
}
-template <> cairo_surface_t* refGPtr(cairo_surface_t* ptr)
+template <> cairo_surface_t* refPlatformPtr(cairo_surface_t* ptr)
{
if (ptr)
cairo_surface_reference(ptr);
return ptr;
}
-template <> void derefGPtr(cairo_surface_t* ptr)
+template <> void derefPlatformPtr(cairo_surface_t* ptr)
{
if (ptr)
cairo_surface_destroy(ptr);
diff --git a/WebCore/platform/graphics/cairo/GRefPtrCairo.h b/WebCore/platform/graphics/cairo/PlatformRefPtrCairo.h
index aef51fe..51d8fa9 100644
--- a/WebCore/platform/graphics/cairo/GRefPtrCairo.h
+++ b/WebCore/platform/graphics/cairo/PlatformRefPtrCairo.h
@@ -17,21 +17,21 @@
* Boston, MA 02110-1301, USA.
*/
-#ifndef GRefPtrCairo_h
-#define GRefPtrCairo_h
+#ifndef PlatformRefPtrCairo_h
+#define PlatformRefPtrCairo_h
-#include "GRefPtr.h"
+#include "PlatformRefPtr.h"
typedef struct _cairo cairo_t;
typedef struct _cairo_surface cairo_surface_t;
namespace WTF {
-template <> cairo_t* refGPtr(cairo_t* ptr);
-template <> void derefGPtr(cairo_t* ptr);
+template <> cairo_t* refPlatformPtr(cairo_t* ptr);
+template <> void derefPlatformPtr(cairo_t* ptr);
-template <> cairo_surface_t* refGPtr(cairo_surface_t* ptr);
-template <> void derefGPtr(cairo_surface_t* ptr);
+template <> cairo_surface_t* refPlatformPtr(cairo_surface_t* ptr);
+template <> void derefPlatformPtr(cairo_surface_t* ptr);
}
diff --git a/WebCore/platform/graphics/cg/ImageSourceCG.cpp b/WebCore/platform/graphics/cg/ImageSourceCG.cpp
index 4a7aecc..5fa4896 100644
--- a/WebCore/platform/graphics/cg/ImageSourceCG.cpp
+++ b/WebCore/platform/graphics/cg/ImageSourceCG.cpp
@@ -63,8 +63,10 @@ void sharedBufferRelease(void* info)
}
#endif
-ImageSource::ImageSource()
+ImageSource::ImageSource(bool premultiplyAlpha)
: m_decoder(0)
+ // FIXME: m_premultiplyAlpha is ignored in cg at the moment.
+ , m_premultiplyAlpha(premultiplyAlpha)
{
}
diff --git a/WebCore/platform/graphics/chromium/CanvasLayerChromium.cpp b/WebCore/platform/graphics/chromium/CanvasLayerChromium.cpp
index 7e732d1..bbf091c 100644
--- a/WebCore/platform/graphics/chromium/CanvasLayerChromium.cpp
+++ b/WebCore/platform/graphics/chromium/CanvasLayerChromium.cpp
@@ -35,11 +35,63 @@
#include "CanvasLayerChromium.h"
#include "GraphicsContext3D.h"
+#include "LayerRendererChromium.h"
#include <GLES2/gl2.h>
namespace WebCore {
-unsigned CanvasLayerChromium::m_shaderProgramId = 0;
+CanvasLayerChromium::SharedValues::SharedValues()
+ : m_canvasShaderProgram(0)
+ , m_shaderSamplerLocation(-1)
+ , m_shaderMatrixLocation(-1)
+ , m_shaderAlphaLocation(-1)
+ , m_initialized(false)
+{
+ char vertexShaderString[] =
+ "attribute vec4 a_position; \n"
+ "attribute vec2 a_texCoord; \n"
+ "uniform mat4 matrix; \n"
+ "varying vec2 v_texCoord; \n"
+ "void main() \n"
+ "{ \n"
+ " gl_Position = matrix * a_position; \n"
+ " v_texCoord = a_texCoord; \n"
+ "} \n";
+
+ // Canvas layers need to be flipped vertically and their colors shouldn't be
+ // swizzled.
+ char fragmentShaderString[] =
+ "precision mediump float; \n"
+ "varying vec2 v_texCoord; \n"
+ "uniform sampler2D s_texture; \n"
+ "uniform float alpha; \n"
+ "void main() \n"
+ "{ \n"
+ " vec4 texColor = texture2D(s_texture, vec2(v_texCoord.x, 1.0 - v_texCoord.y)); \n"
+ " gl_FragColor = vec4(texColor.x, texColor.y, texColor.z, texColor.w) * alpha; \n"
+ "} \n";
+
+ m_canvasShaderProgram = createShaderProgram(vertexShaderString, fragmentShaderString);
+ if (!m_canvasShaderProgram) {
+ LOG_ERROR("CanvasLayerChromium: Failed to create shader program");
+ return;
+ }
+
+ m_shaderSamplerLocation = glGetUniformLocation(m_canvasShaderProgram, "s_texture");
+ m_shaderMatrixLocation = glGetUniformLocation(m_canvasShaderProgram, "matrix");
+ m_shaderAlphaLocation = glGetUniformLocation(m_canvasShaderProgram, "alpha");
+ ASSERT(m_shaderSamplerLocation != -1);
+ ASSERT(m_shaderMatrixLocation != -1);
+ ASSERT(m_shaderAlphaLocation != -1);
+
+ m_initialized = true;
+}
+
+CanvasLayerChromium::SharedValues::~SharedValues()
+{
+ if (m_canvasShaderProgram)
+ GLC(glDeleteProgram(m_canvasShaderProgram));
+}
PassRefPtr<CanvasLayerChromium> CanvasLayerChromium::create(GraphicsLayerChromium* owner)
{
@@ -54,14 +106,8 @@ CanvasLayerChromium::CanvasLayerChromium(GraphicsLayerChromium* owner)
{
}
-unsigned CanvasLayerChromium::textureId()
-{
- return m_textureId;
-}
-
-void CanvasLayerChromium::updateTextureContents(unsigned textureId)
+void CanvasLayerChromium::updateContents()
{
- ASSERT(textureId == m_textureId);
ASSERT(m_context);
if (m_textureChanged) {
glBindTexture(GL_TEXTURE_2D, m_textureId);
@@ -92,5 +138,19 @@ void CanvasLayerChromium::setContext(const GraphicsContext3D* context)
m_textureId = textureId;
}
+void CanvasLayerChromium::draw()
+{
+ ASSERT(layerRenderer());
+ const CanvasLayerChromium::SharedValues* sv = layerRenderer()->canvasLayerSharedValues();
+ ASSERT(sv && sv->initialized());
+ GLC(glActiveTexture(GL_TEXTURE0));
+ GLC(glBindTexture(GL_TEXTURE_2D, m_textureId));
+ layerRenderer()->useShader(sv->canvasShaderProgram());
+ GLC(glUniform1i(sv->shaderSamplerLocation(), 0));
+ drawTexturedQuad(layerRenderer()->projectionMatrix(), drawTransform(),
+ bounds().width(), bounds().height(), drawOpacity(),
+ sv->shaderMatrixLocation(), sv->shaderAlphaLocation());
+}
+
}
#endif // USE(ACCELERATED_COMPOSITING)
diff --git a/WebCore/platform/graphics/chromium/CanvasLayerChromium.h b/WebCore/platform/graphics/chromium/CanvasLayerChromium.h
index 98be270..053efff 100644
--- a/WebCore/platform/graphics/chromium/CanvasLayerChromium.h
+++ b/WebCore/platform/graphics/chromium/CanvasLayerChromium.h
@@ -45,14 +45,29 @@ class CanvasLayerChromium : public LayerChromium {
public:
static PassRefPtr<CanvasLayerChromium> create(GraphicsLayerChromium* owner = 0);
virtual bool drawsContent() { return m_context; }
- virtual bool ownsTexture() { return true; }
- virtual void updateTextureContents(unsigned);
- virtual unsigned textureId();
- virtual unsigned shaderProgramId() { return m_shaderProgramId; }
+ virtual void updateContents();
+ virtual void draw();
void setContext(const GraphicsContext3D* context);
- static void setShaderProgramId(unsigned shaderProgramId) { m_shaderProgramId = shaderProgramId; }
+ class SharedValues {
+ public:
+ SharedValues();
+ ~SharedValues();
+
+ unsigned canvasShaderProgram() const { return m_canvasShaderProgram; }
+ int shaderSamplerLocation() const { return m_shaderSamplerLocation; }
+ int shaderMatrixLocation() const { return m_shaderMatrixLocation; }
+ int shaderAlphaLocation() const { return m_shaderAlphaLocation; }
+ bool initialized() const { return m_initialized; }
+
+ private:
+ unsigned m_canvasShaderProgram;
+ int m_shaderSamplerLocation;
+ int m_shaderMatrixLocation;
+ int m_shaderAlphaLocation;
+ bool m_initialized;
+ };
class PrepareTextureCallback : public Noncopyable {
public:
@@ -66,8 +81,6 @@ private:
unsigned m_textureId;
bool m_textureChanged;
OwnPtr<PrepareTextureCallback> m_prepareTextureCallback;
-
- static unsigned m_shaderProgramId;
};
}
diff --git a/WebCore/platform/graphics/chromium/ContentLayerChromium.cpp b/WebCore/platform/graphics/chromium/ContentLayerChromium.cpp
new file mode 100644
index 0000000..974933d
--- /dev/null
+++ b/WebCore/platform/graphics/chromium/ContentLayerChromium.cpp
@@ -0,0 +1,301 @@
+/*
+ * Copyright (C) 2010 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+
+#if USE(ACCELERATED_COMPOSITING)
+
+#include "ContentLayerChromium.h"
+
+#include "LayerRendererChromium.h"
+#include "RenderLayerBacking.h"
+
+#if PLATFORM(SKIA)
+#include "NativeImageSkia.h"
+#include "PlatformContextSkia.h"
+#include "skia/ext/platform_canvas.h"
+#elif PLATFORM(CG)
+#include <CoreGraphics/CGBitmapContext.h>
+#endif
+
+#include <GLES2/gl2.h>
+
+namespace WebCore {
+
+ContentLayerChromium::SharedValues::SharedValues()
+ : m_contentShaderProgram(0)
+ , m_shaderSamplerLocation(-1)
+ , m_shaderMatrixLocation(-1)
+ , m_shaderAlphaLocation(-1)
+ , m_initialized(false)
+{
+ // Shaders for drawing the layer contents.
+ char vertexShaderString[] =
+ "attribute vec4 a_position; \n"
+ "attribute vec2 a_texCoord; \n"
+ "uniform mat4 matrix; \n"
+ "varying vec2 v_texCoord; \n"
+ "void main() \n"
+ "{ \n"
+ " gl_Position = matrix * a_position; \n"
+ " v_texCoord = a_texCoord; \n"
+ "} \n";
+
+ // Note differences between Skia and Core Graphics versions:
+ // - Skia uses BGRA and origin is upper left
+ // - Core Graphics uses RGBA and origin is lower left
+ char fragmentShaderString[] =
+ "precision mediump float; \n"
+ "varying vec2 v_texCoord; \n"
+ "uniform sampler2D s_texture; \n"
+ "uniform float alpha; \n"
+ "void main() \n"
+ "{ \n"
+#if PLATFORM(SKIA)
+ " vec4 texColor = texture2D(s_texture, v_texCoord); \n"
+ " gl_FragColor = vec4(texColor.z, texColor.y, texColor.x, texColor.w) * alpha; \n"
+#elif PLATFORM(CG)
+ " vec4 texColor = texture2D(s_texture, vec2(v_texCoord.x, 1.0 - v_texCoord.y)); \n"
+ " gl_FragColor = vec4(texColor.x, texColor.y, texColor.z, texColor.w) * alpha; \n"
+#else
+#error "Need to implement for your platform."
+#endif
+ "} \n";
+
+ m_contentShaderProgram = createShaderProgram(vertexShaderString, fragmentShaderString);
+ if (!m_contentShaderProgram) {
+ LOG_ERROR("ContentLayerChromium: Failed to create shader program");
+ return;
+ }
+
+ m_shaderSamplerLocation = glGetUniformLocation(m_contentShaderProgram, "s_texture");
+ m_shaderMatrixLocation = glGetUniformLocation(m_contentShaderProgram, "matrix");
+ m_shaderAlphaLocation = glGetUniformLocation(m_contentShaderProgram, "alpha");
+ ASSERT(m_shaderSamplerLocation != -1);
+ ASSERT(m_shaderMatrixLocation != -1);
+ ASSERT(m_shaderAlphaLocation != -1);
+
+ m_initialized = true;
+}
+
+ContentLayerChromium::SharedValues::~SharedValues()
+{
+ if (m_contentShaderProgram)
+ GLC(glDeleteProgram(m_contentShaderProgram));
+}
+
+
+PassRefPtr<ContentLayerChromium> ContentLayerChromium::create(GraphicsLayerChromium* owner)
+{
+ return adoptRef(new ContentLayerChromium(owner));
+}
+
+ContentLayerChromium::ContentLayerChromium(GraphicsLayerChromium* owner)
+ : LayerChromium(owner)
+ , m_contentsTexture(0)
+{
+}
+
+ContentLayerChromium::~ContentLayerChromium()
+{
+ if (m_contentsTexture)
+ GLC(glDeleteTextures(1, &m_contentsTexture));
+}
+
+
+void ContentLayerChromium::updateContents()
+{
+ RenderLayerBacking* backing = static_cast<RenderLayerBacking*>(m_owner->client());
+ if (!backing || backing->paintingGoesToWindow())
+ return;
+
+ ASSERT(drawsContent());
+
+ ASSERT(layerRenderer());
+
+ // FIXME: Remove this test when tiled layers are implemented.
+ m_skipsDraw = false;
+ if (!layerRenderer()->checkTextureSize(m_bounds)) {
+ m_skipsDraw = true;
+ return;
+ }
+
+ void* pixels = 0;
+ IntRect dirtyRect(m_dirtyRect);
+ IntSize requiredTextureSize;
+ IntSize bitmapSize;
+
+#if PLATFORM(SKIA)
+ const SkBitmap* skiaBitmap = 0;
+ OwnPtr<skia::PlatformCanvas> canvas;
+ OwnPtr<PlatformContextSkia> skiaContext;
+ OwnPtr<GraphicsContext> graphicsContext;
+
+ requiredTextureSize = m_bounds;
+ IntRect boundsRect(IntPoint(0, 0), m_bounds);
+
+ // If the texture needs to be reallocated then we must redraw the entire
+ // contents of the layer.
+ if (requiredTextureSize != m_allocatedTextureSize)
+ dirtyRect = boundsRect;
+ else {
+ // Clip the dirtyRect to the size of the layer to avoid drawing outside
+ // the bounds of the backing texture.
+ dirtyRect.intersect(boundsRect);
+ }
+
+ canvas.set(new skia::PlatformCanvas(dirtyRect.width(), dirtyRect.height(), false));
+ skiaContext.set(new PlatformContextSkia(canvas.get()));
+
+#if OS(WINDOWS)
+ // This is needed to get text to show up correctly. Without it,
+ // GDI renders with zero alpha and the text becomes invisible.
+ // Unfortunately, setting this to true disables cleartype.
+ // FIXME: Does this take us down a very slow text rendering path?
+ // FIXME: why is this is a windows-only call ?
+ skiaContext->setDrawingToImageBuffer(true);
+#endif
+
+ graphicsContext.set(new GraphicsContext(reinterpret_cast<PlatformGraphicsContext*>(skiaContext.get())));
+
+ // Bring the canvas into the coordinate system of the paint rect.
+ canvas->translate(static_cast<SkScalar>(-dirtyRect.x()), static_cast<SkScalar>(-dirtyRect.y()));
+
+ m_owner->paintGraphicsLayerContents(*graphicsContext, dirtyRect);
+ const SkBitmap& bitmap = canvas->getDevice()->accessBitmap(false);
+ skiaBitmap = &bitmap;
+ ASSERT(skiaBitmap);
+
+ SkAutoLockPixels lock(*skiaBitmap);
+ SkBitmap::Config skiaConfig = skiaBitmap->config();
+ // FIXME: do we need to support more image configurations?
+ if (skiaConfig == SkBitmap::kARGB_8888_Config) {
+ pixels = skiaBitmap->getPixels();
+ bitmapSize = IntSize(skiaBitmap->width(), skiaBitmap->height());
+ }
+#elif PLATFORM(CG)
+ requiredTextureSize = m_bounds;
+ IntRect boundsRect(IntPoint(0, 0), m_bounds);
+
+ // If the texture needs to be reallocated then we must redraw the entire
+ // contents of the layer.
+ if (requiredTextureSize != m_allocatedTextureSize)
+ dirtyRect = boundsRect;
+ else {
+ // Clip the dirtyRect to the size of the layer to avoid drawing outside
+ // the bounds of the backing texture.
+ dirtyRect.intersect(boundsRect);
+ }
+
+ Vector<uint8_t> tempVector;
+ int rowBytes = 4 * dirtyRect.width();
+ tempVector.resize(rowBytes * dirtyRect.height());
+ memset(tempVector.data(), 0, tempVector.size());
+ RetainPtr<CGColorSpaceRef> colorSpace(AdoptCF, CGColorSpaceCreateDeviceRGB());
+ RetainPtr<CGContextRef> contextCG(AdoptCF, CGBitmapContextCreate(tempVector.data(),
+ dirtyRect.width(), dirtyRect.height(), 8, rowBytes,
+ colorSpace.get(),
+ kCGImageAlphaPremultipliedLast));
+
+ GraphicsContext graphicsContext(contextCG.get());
+
+ // Translate the graphics contxt into the coordinate system of the dirty rect.
+ graphicsContext.translate(-dirtyRect.x(), -dirtyRect.y());
+
+ m_owner->paintGraphicsLayerContents(graphicsContext, dirtyRect);
+
+ pixels = tempVector.data();
+ bitmapSize = dirtyRect.size();
+#else
+#error "Need to implement for your platform."
+#endif
+
+ unsigned textureId = m_contentsTexture;
+ if (!textureId)
+ textureId = layerRenderer()->createLayerTexture();
+
+ if (pixels)
+ updateTextureRect(pixels, bitmapSize, requiredTextureSize, dirtyRect, textureId);
+}
+
+void ContentLayerChromium::updateTextureRect(void* pixels, const IntSize& bitmapSize, const IntSize& requiredTextureSize, const IntRect& updateRect, unsigned textureId)
+{
+ if (!pixels)
+ return;
+
+ glBindTexture(GL_TEXTURE_2D, textureId);
+
+ // If the texture id or size changed since last time then we need to tell GL
+ // to re-allocate a texture.
+ if (m_contentsTexture != textureId || requiredTextureSize != m_allocatedTextureSize) {
+ ASSERT(bitmapSize == requiredTextureSize);
+ GLC(glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, requiredTextureSize.width(), requiredTextureSize.height(), 0, GL_RGBA, GL_UNSIGNED_BYTE, pixels));
+
+ m_contentsTexture = textureId;
+ m_allocatedTextureSize = requiredTextureSize;
+ } else {
+ ASSERT(updateRect.width() <= m_allocatedTextureSize.width() && updateRect.height() <= m_allocatedTextureSize.height());
+ ASSERT(updateRect.width() == bitmapSize.width() && updateRect.height() == bitmapSize.height());
+#if PLATFORM(CG)
+ // The origin is at the lower left in Core Graphics' coordinate system. We need to correct for this here.
+ GLC(glTexSubImage2D(GL_TEXTURE_2D, 0,
+ updateRect.x(), m_allocatedTextureSize.height() - updateRect.height() - updateRect.y(),
+ updateRect.width(), updateRect.height(),
+ GL_RGBA, GL_UNSIGNED_BYTE, pixels));
+#elif PLATFORM(SKIA)
+ GLC(glTexSubImage2D(GL_TEXTURE_2D, 0, updateRect.x(), updateRect.y(), updateRect.width(), updateRect.height(), GL_RGBA, GL_UNSIGNED_BYTE, pixels));
+#else
+#error "Need to implement for your platform."
+#endif
+ }
+
+ m_dirtyRect.setSize(FloatSize());
+ m_contentsDirty = false;
+}
+
+void ContentLayerChromium::draw()
+{
+ if (m_skipsDraw)
+ return;
+
+ ASSERT(layerRenderer());
+ const ContentLayerChromium::SharedValues* sv = layerRenderer()->contentLayerSharedValues();
+ ASSERT(sv && sv->initialized());
+ GLC(glActiveTexture(GL_TEXTURE0));
+ GLC(glBindTexture(GL_TEXTURE_2D, m_contentsTexture));
+ layerRenderer()->useShader(sv->contentShaderProgram());
+ GLC(glUniform1i(sv->shaderSamplerLocation(), 0));
+ drawTexturedQuad(layerRenderer()->projectionMatrix(), drawTransform(),
+ bounds().width(), bounds().height(), drawOpacity(),
+ sv->shaderMatrixLocation(), sv->shaderAlphaLocation());
+}
+
+}
+#endif // USE(ACCELERATED_COMPOSITING)
diff --git a/WebCore/platform/graphics/chromium/ContentLayerChromium.h b/WebCore/platform/graphics/chromium/ContentLayerChromium.h
new file mode 100644
index 0000000..3e15372
--- /dev/null
+++ b/WebCore/platform/graphics/chromium/ContentLayerChromium.h
@@ -0,0 +1,90 @@
+/*
+ * Copyright (C) 2010 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+
+#ifndef ContentLayerChromium_h
+#define ContentLayerChromium_h
+
+#if USE(ACCELERATED_COMPOSITING)
+
+#include "LayerChromium.h"
+
+namespace WebCore {
+
+// A Layer that requires a GraphicsContext to render its contents.
+class ContentLayerChromium : public LayerChromium {
+ friend class LayerRendererChromium;
+public:
+ static PassRefPtr<ContentLayerChromium> create(GraphicsLayerChromium* owner = 0);
+
+ ~ContentLayerChromium();
+
+ virtual void updateContents();
+ virtual void draw();
+ virtual bool drawsContent() { return m_owner && m_owner->drawsContent(); }
+
+ // Stores values that are shared between instances of this class that are
+ // associated with the same LayerRendererChromium (and hence the same GL
+ // context).
+ class SharedValues {
+ public:
+ SharedValues();
+ ~SharedValues();
+
+ unsigned contentShaderProgram() const { return m_contentShaderProgram; }
+ int shaderSamplerLocation() const { return m_shaderSamplerLocation; }
+ int shaderMatrixLocation() const { return m_shaderMatrixLocation; }
+ int shaderAlphaLocation() const { return m_shaderAlphaLocation; }
+ int initialized() const { return m_initialized; }
+
+ private:
+ unsigned m_contentShaderProgram;
+ int m_shaderSamplerLocation;
+ int m_shaderMatrixLocation;
+ int m_shaderAlphaLocation;
+ int m_initialized;
+ };
+
+protected:
+ ContentLayerChromium(GraphicsLayerChromium* owner);
+
+ void updateTextureRect(void* pixels, const IntSize& bitmapSize, const IntSize& requiredTextureSize,
+ const IntRect& updateRect, unsigned textureId);
+
+ unsigned m_contentsTexture;
+ IntSize m_allocatedTextureSize;
+ bool m_skipsDraw;
+
+};
+
+}
+#endif // USE(ACCELERATED_COMPOSITING)
+
+#endif
diff --git a/WebCore/platform/graphics/chromium/GLES2Canvas.cpp b/WebCore/platform/graphics/chromium/GLES2Canvas.cpp
index 534de7b..c0cb87c 100644
--- a/WebCore/platform/graphics/chromium/GLES2Canvas.cpp
+++ b/WebCore/platform/graphics/chromium/GLES2Canvas.cpp
@@ -34,13 +34,11 @@
#include "GLES2Canvas.h"
-#include "Float32Array.h"
#include "FloatRect.h"
#include "GLES2Texture.h"
#include "GraphicsContext3D.h"
#include "IntRect.h"
#include "PlatformString.h"
-#include "Uint16Array.h"
#define _USE_MATH_DEFINES
#include <math.h>
@@ -79,7 +77,6 @@ struct GLES2Canvas::State {
GLES2Canvas::GLES2Canvas(GraphicsContext3D* context, const IntSize& size)
: m_context(context)
, m_quadVertices(0)
- , m_quadIndices(0)
, m_simpleProgram(0)
, m_texProgram(0)
, m_simpleMatrixLocation(-1)
@@ -111,40 +108,33 @@ GLES2Canvas::~GLES2Canvas()
m_context->deleteProgram(m_simpleProgram);
m_context->deleteProgram(m_texProgram);
m_context->deleteBuffer(m_quadVertices);
- m_context->deleteBuffer(m_quadIndices);
}
void GLES2Canvas::clearRect(const FloatRect& rect)
{
- m_context->scissor(rect.x(), rect.y(), rect.width(), rect.height());
- m_context->enable(GraphicsContext3D::SCISSOR_TEST);
- m_context->clear(GraphicsContext3D::COLOR_BUFFER_BIT);
- m_context->disable(GraphicsContext3D::SCISSOR_TEST);
+ if (m_state->m_ctm.isIdentity()) {
+ m_context->scissor(rect.x(), rect.y(), rect.width(), rect.height());
+ m_context->enable(GraphicsContext3D::SCISSOR_TEST);
+ m_context->clear(GraphicsContext3D::COLOR_BUFFER_BIT);
+ m_context->disable(GraphicsContext3D::SCISSOR_TEST);
+ } else {
+ save();
+ setCompositeOperation(CompositeClear);
+ fillRect(rect, Color(RGBA32(0)), DeviceColorSpace);
+ restore();
+ }
}
void GLES2Canvas::fillRect(const FloatRect& rect, const Color& color, ColorSpace colorSpace)
{
- m_context->bindBuffer(GraphicsContext3D::ARRAY_BUFFER, getQuadVertices());
- m_context->bindBuffer(GraphicsContext3D::ELEMENT_ARRAY_BUFFER, getQuadIndices());
-
- float rgba[4];
- color.getRGBA(rgba[0], rgba[1], rgba[2], rgba[3]);
- m_context->uniform4f(m_simpleColorLocation, rgba[0] * rgba[3], rgba[1] * rgba[3], rgba[2] * rgba[3], rgba[3]);
-
- m_context->drawElements(GraphicsContext3D::TRIANGLES, 6, GraphicsContext3D::UNSIGNED_SHORT, 0);
-}
-
-void GLES2Canvas::fillRect(const FloatRect& rect)
-{
applyCompositeOperator(m_state->m_compositeOp);
m_context->bindBuffer(GraphicsContext3D::ARRAY_BUFFER, getQuadVertices());
- m_context->bindBuffer(GraphicsContext3D::ELEMENT_ARRAY_BUFFER, getQuadIndices());
m_context->useProgram(getSimpleProgram());
float rgba[4];
- m_state->m_fillColor.getRGBA(rgba[0], rgba[1], rgba[2], rgba[3]);
+ color.getRGBA(rgba[0], rgba[1], rgba[2], rgba[3]);
m_context->uniform4f(m_simpleColorLocation, rgba[0] * rgba[3], rgba[1] * rgba[3], rgba[2] * rgba[3], rgba[3]);
AffineTransform matrix(m_flipMatrix);
@@ -159,7 +149,12 @@ void GLES2Canvas::fillRect(const FloatRect& rect)
m_context->enableVertexAttribArray(m_simplePositionLocation);
- m_context->drawElements(GraphicsContext3D::TRIANGLES, 6, GraphicsContext3D::UNSIGNED_SHORT, 0);
+ m_context->drawArrays(GraphicsContext3D::TRIANGLE_STRIP, 0, 4);
+}
+
+void GLES2Canvas::fillRect(const FloatRect& rect)
+{
+ fillRect(rect, m_state->m_fillColor, DeviceColorSpace);
}
void GLES2Canvas::setFillColor(const Color& color, ColorSpace colorSpace)
@@ -215,7 +210,6 @@ void GLES2Canvas::drawTexturedRect(GLES2Texture* texture, const FloatRect& srcRe
applyCompositeOperator(compositeOp);
m_context->bindBuffer(GraphicsContext3D::ARRAY_BUFFER, getQuadVertices());
- m_context->bindBuffer(GraphicsContext3D::ELEMENT_ARRAY_BUFFER, getQuadIndices());
checkGLError("glBindBuffer");
m_context->useProgram(getTexProgram());
@@ -275,8 +269,8 @@ void GLES2Canvas::drawTexturedRectTile(GLES2Texture* texture, int tile, const Fl
m_context->uniformMatrix3fv(m_texTexMatrixLocation, false /*transpose*/, texMat, 1 /*count*/);
checkGLError("glUniformMatrix3fv");
- m_context->drawElements(GraphicsContext3D::TRIANGLES, 6, GraphicsContext3D::UNSIGNED_SHORT, 0);
- checkGLError("glDrawElements");
+ m_context->drawArrays(GraphicsContext3D::TRIANGLE_STRIP, 0, 4);
+ checkGLError("glDrawArrays");
}
void GLES2Canvas::setCompositeOperation(CompositeOperator op)
@@ -351,30 +345,16 @@ unsigned GLES2Canvas::getQuadVertices()
if (!m_quadVertices) {
float vertices[] = { 0.0f, 0.0f, 1.0f,
1.0f, 0.0f, 1.0f,
- 1.0f, 1.0f, 1.0f,
- 0.0f, 1.0f, 1.0f };
+ 0.0f, 1.0f, 1.0f,
+ 1.0f, 1.0f, 1.0f };
m_quadVertices = m_context->createBuffer();
- RefPtr<Float32Array> vertexArray = Float32Array::create(vertices, sizeof(vertices) / sizeof(float));
m_context->bindBuffer(GraphicsContext3D::ARRAY_BUFFER, m_quadVertices);
- m_context->bufferData(GraphicsContext3D::ARRAY_BUFFER, vertexArray.get(), GraphicsContext3D::STATIC_DRAW);
+ m_context->bufferData(GraphicsContext3D::ARRAY_BUFFER, sizeof(vertices), vertices, GraphicsContext3D::STATIC_DRAW);
}
return m_quadVertices;
}
-unsigned GLES2Canvas::getQuadIndices()
-{
- if (!m_quadIndices) {
- unsigned short indices[] = { 0, 1, 2, 0, 2, 3};
-
- m_quadIndices = m_context->createBuffer();
- RefPtr<Uint16Array> indexArray = Uint16Array::create(indices, sizeof(indices) / sizeof(unsigned short));
- m_context->bindBuffer(GraphicsContext3D::ELEMENT_ARRAY_BUFFER, m_quadIndices);
- m_context->bufferData(GraphicsContext3D::ELEMENT_ARRAY_BUFFER, indexArray.get(), GraphicsContext3D::STATIC_DRAW);
- }
- return m_quadIndices;
-}
-
static unsigned loadShader(GraphicsContext3D* context, unsigned type, const char* shaderSource)
{
unsigned shader = context->createShader(type);
diff --git a/WebCore/platform/graphics/chromium/GLES2Canvas.h b/WebCore/platform/graphics/chromium/GLES2Canvas.h
index 0ad07fc..d00510a 100644
--- a/WebCore/platform/graphics/chromium/GLES2Canvas.h
+++ b/WebCore/platform/graphics/chromium/GLES2Canvas.h
@@ -85,7 +85,6 @@ private:
void applyCompositeOperator(CompositeOperator);
void checkGLError(const char* header);
unsigned getQuadVertices();
- unsigned getQuadIndices();
unsigned getSimpleProgram();
unsigned getTexProgram();
@@ -94,7 +93,6 @@ private:
WTF::Vector<State> m_stateStack;
State* m_state;
unsigned m_quadVertices;
- unsigned m_quadIndices;
unsigned m_simpleProgram;
unsigned m_texProgram;
int m_simpleMatrixLocation;
diff --git a/WebCore/platform/graphics/chromium/GraphicsLayerChromium.cpp b/WebCore/platform/graphics/chromium/GraphicsLayerChromium.cpp
index 1d67857..648e35f 100644
--- a/WebCore/platform/graphics/chromium/GraphicsLayerChromium.cpp
+++ b/WebCore/platform/graphics/chromium/GraphicsLayerChromium.cpp
@@ -45,6 +45,7 @@
#include "GraphicsLayerChromium.h"
+#include "ContentLayerChromium.h"
#include "FloatConversion.h"
#include "FloatRect.h"
#include "Image.h"
@@ -52,7 +53,6 @@
#include "LayerChromium.h"
#include "PlatformString.h"
#include "SystemTime.h"
-#include "TransformLayerChromium.h"
#include <wtf/CurrentTime.h>
#include <wtf/StringExtras.h>
@@ -97,7 +97,7 @@ GraphicsLayerChromium::GraphicsLayerChromium(GraphicsLayerClient* client)
, m_contentsLayerPurpose(NoContentsLayer)
, m_contentsLayerHasBackgroundColor(false)
{
- m_layer = LayerChromium::create(this);
+ m_layer = ContentLayerChromium::create(this);
updateDebugIndicators();
}
@@ -538,7 +538,7 @@ void GraphicsLayerChromium::updateLayerPreserves3D()
{
if (m_preserves3D && !m_transformLayer) {
// Create the transform layer.
- m_transformLayer = TransformLayerChromium::create(this);
+ m_transformLayer = LayerChromium::create(this);
// Copy the position from this layer.
updateLayerPosition();
diff --git a/WebCore/platform/graphics/chromium/ImageLayerChromium.cpp b/WebCore/platform/graphics/chromium/ImageLayerChromium.cpp
index 3cc7cad..09b388d 100644
--- a/WebCore/platform/graphics/chromium/ImageLayerChromium.cpp
+++ b/WebCore/platform/graphics/chromium/ImageLayerChromium.cpp
@@ -34,6 +34,8 @@
#include "ImageLayerChromium.h"
+#include "LayerRendererChromium.h"
+
#if PLATFORM(SKIA)
#include "NativeImageSkia.h"
#include "PlatformContextSkia.h"
@@ -54,7 +56,7 @@ PassRefPtr<ImageLayerChromium> ImageLayerChromium::create(GraphicsLayerChromium*
}
ImageLayerChromium::ImageLayerChromium(GraphicsLayerChromium* owner)
- : LayerChromium(owner)
+ : ContentLayerChromium(owner)
, m_contents(0)
{
}
@@ -68,8 +70,10 @@ void ImageLayerChromium::setContents(NativeImagePtr contents)
setNeedsDisplay();
}
-void ImageLayerChromium::updateTextureContents(unsigned textureId)
+void ImageLayerChromium::updateContents()
{
+ ASSERT(layerRenderer());
+
void* pixels = 0;
IntRect dirtyRect(m_dirtyRect);
IntSize requiredTextureSize;
@@ -129,6 +133,17 @@ void ImageLayerChromium::updateTextureContents(unsigned textureId)
#else
#error "Need to implement for your platform."
#endif
+ // FIXME: Remove this test when tiled layers are implemented.
+ m_skipsDraw = false;
+ if (!layerRenderer()->checkTextureSize(requiredTextureSize)) {
+ m_skipsDraw = true;
+ return;
+ }
+
+ unsigned textureId = m_contentsTexture;
+ if (!textureId)
+ textureId = layerRenderer()->createLayerTexture();
+
if (pixels)
updateTextureRect(pixels, bitmapSize, requiredTextureSize, dirtyRect, textureId);
}
diff --git a/WebCore/platform/graphics/chromium/ImageLayerChromium.h b/WebCore/platform/graphics/chromium/ImageLayerChromium.h
index 9355b2d..e95284c 100644
--- a/WebCore/platform/graphics/chromium/ImageLayerChromium.h
+++ b/WebCore/platform/graphics/chromium/ImageLayerChromium.h
@@ -34,16 +34,18 @@
#if USE(ACCELERATED_COMPOSITING)
-#include "LayerChromium.h"
+#include "ContentLayerChromium.h"
namespace WebCore {
// A Layer that contains only an Image element.
-class ImageLayerChromium : public LayerChromium {
+class ImageLayerChromium : public ContentLayerChromium {
public:
static PassRefPtr<ImageLayerChromium> create(GraphicsLayerChromium* owner = 0);
+
+ virtual void updateContents();
virtual bool drawsContent() { return m_contents; }
- virtual void updateTextureContents(unsigned textureId);
+
void setContents(NativeImagePtr);
private:
diff --git a/WebCore/platform/graphics/chromium/LayerChromium.cpp b/WebCore/platform/graphics/chromium/LayerChromium.cpp
index 21d8d12..3553878 100644
--- a/WebCore/platform/graphics/chromium/LayerChromium.cpp
+++ b/WebCore/platform/graphics/chromium/LayerChromium.cpp
@@ -48,7 +48,93 @@ namespace WebCore {
using namespace std;
-unsigned LayerChromium::m_shaderProgramId = 0;
+const unsigned LayerChromium::s_positionAttribLocation = 0;
+const unsigned LayerChromium::s_texCoordAttribLocation = 1;
+
+static GLuint loadShader(GLenum type, const char* shaderSource)
+{
+ GLuint shader = glCreateShader(type);
+ if (!shader)
+ return 0;
+ GLC(glShaderSource(shader, 1, &shaderSource, 0));
+ GLC(glCompileShader(shader));
+ GLint compiled;
+ GLC(glGetShaderiv(shader, GL_COMPILE_STATUS, &compiled));
+ if (!compiled) {
+ GLC(glDeleteShader(shader));
+ return 0;
+ }
+ return shader;
+}
+
+LayerChromium::SharedValues::SharedValues()
+ : m_quadVerticesVbo(0)
+ , m_quadElementsVbo(0)
+ , m_maxTextureSize(0)
+ , m_borderShaderProgram(0)
+ , m_borderShaderMatrixLocation(-1)
+ , m_borderShaderColorLocation(-1)
+ , m_initialized(false)
+{
+ // Vertex positions and texture coordinates for the 4 corners of a 1x1 quad.
+ GLfloat vertices[] = { -0.5f, 0.5f, 0.0f, 0.0f, 1.0f,
+ -0.5f, -0.5f, 0.0f, 0.0f, 0.0f,
+ 0.5f, -0.5f, 0.0f, 1.0f, 0.0f,
+ 0.5f, 0.5f, 0.0f, 1.0f, 1.0f };
+ GLushort indices[] = { 0, 1, 2, 0, 2, 3, // The two triangles that make up the layer quad.
+ 0, 1, 2, 3}; // A line path for drawing the layer border.
+
+ GLuint vboIds[2];
+ GLC(glGenBuffers(2, vboIds));
+ m_quadVerticesVbo = vboIds[0];
+ m_quadElementsVbo = vboIds[1];
+ GLC(glBindBuffer(GL_ARRAY_BUFFER, m_quadVerticesVbo));
+ GLC(glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW));
+ GLC(glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_quadElementsVbo));
+ GLC(glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(indices), indices, GL_STATIC_DRAW));
+
+ // Get the max texture size supported by the system.
+ GLC(glGetIntegerv(GL_MAX_TEXTURE_SIZE, &m_maxTextureSize));
+
+ // Shaders for drawing the debug borders around the layers.
+ char borderVertexShaderString[] =
+ "attribute vec4 a_position; \n"
+ "uniform mat4 matrix; \n"
+ "void main() \n"
+ "{ \n"
+ " gl_Position = matrix * a_position; \n"
+ "} \n";
+ char borderFragmentShaderString[] =
+ "precision mediump float; \n"
+ "uniform vec4 color; \n"
+ "void main() \n"
+ "{ \n"
+ " gl_FragColor = color; \n"
+ "} \n";
+
+ m_borderShaderProgram = createShaderProgram(borderVertexShaderString, borderFragmentShaderString);
+ if (!m_borderShaderProgram) {
+ LOG_ERROR("ContentLayerChromium: Failed to create shader program");
+ return;
+ }
+
+ m_borderShaderMatrixLocation = glGetUniformLocation(m_borderShaderProgram, "matrix");
+ m_borderShaderColorLocation = glGetUniformLocation(m_borderShaderProgram, "color");
+ ASSERT(m_borderShaderMatrixLocation != -1);
+ ASSERT(m_borderShaderColorLocation != -1);
+
+ m_initialized = true;
+}
+
+LayerChromium::SharedValues::~SharedValues()
+{
+ GLuint vboIds[2] = { m_quadVerticesVbo, m_quadElementsVbo };
+ GLC(glDeleteBuffers(2, vboIds));
+
+ if (m_borderShaderProgram)
+ GLC(glDeleteProgram(m_borderShaderProgram));
+}
+
PassRefPtr<LayerChromium> LayerChromium::create(GraphicsLayerChromium* owner)
{
@@ -62,13 +148,10 @@ LayerChromium::LayerChromium(GraphicsLayerChromium* owner)
, m_anchorPoint(0.5, 0.5)
, m_backgroundColor(0, 0, 0, 0)
, m_borderColor(0, 0, 0, 0)
- , m_layerRenderer(0)
- , m_edgeAntialiasingMask(0)
, m_opacity(1.0)
, m_zPosition(0.0)
, m_anchorPointZ(0)
, m_borderWidth(0)
- , m_allocatedTextureId(0)
, m_clearsContext(false)
, m_doubleSided(true)
, m_hidden(false)
@@ -76,6 +159,7 @@ LayerChromium::LayerChromium(GraphicsLayerChromium* owner)
, m_opaque(true)
, m_geometryFlipped(false)
, m_needsDisplayOnBoundsChange(false)
+ , m_layerRenderer(0)
{
}
@@ -87,10 +171,6 @@ LayerChromium::~LayerChromium()
// Remove the superlayer reference from all sublayers.
removeAllSublayers();
-
- // Notify the renderer to clean up the texture associated with the layer.
- if (m_layerRenderer)
- m_layerRenderer->freeLayerTexture(this);
}
void LayerChromium::setLayerRenderer(LayerRendererChromium* renderer)
@@ -101,140 +181,46 @@ void LayerChromium::setLayerRenderer(LayerRendererChromium* renderer)
m_layerRenderer = renderer;
}
-void LayerChromium::updateTextureContents(unsigned textureId)
+unsigned LayerChromium::createShaderProgram(const char* vertexShaderSource, const char* fragmentShaderSource)
{
- RenderLayerBacking* backing = static_cast<RenderLayerBacking*>(m_owner->client());
- if (!backing || backing->paintingGoesToWindow())
- return;
-
- ASSERT(drawsContent());
-
- void* pixels = 0;
- IntRect dirtyRect(m_dirtyRect);
- IntSize requiredTextureSize;
- IntSize bitmapSize;
-
-#if PLATFORM(SKIA)
- const SkBitmap* skiaBitmap = 0;
- OwnPtr<skia::PlatformCanvas> canvas;
- OwnPtr<PlatformContextSkia> skiaContext;
- OwnPtr<GraphicsContext> graphicsContext;
-
- requiredTextureSize = m_bounds;
- IntRect boundsRect(IntPoint(0, 0), m_bounds);
-
- // If the texture needs to be reallocated then we must redraw the entire
- // contents of the layer.
- if (requiredTextureSize != m_allocatedTextureSize)
- dirtyRect = boundsRect;
- else {
- // Clip the dirtyRect to the size of the layer to avoid drawing outside
- // the bounds of the backing texture.
- dirtyRect.intersect(boundsRect);
+ GLuint vertexShader = loadShader(GL_VERTEX_SHADER, vertexShaderSource);
+ if (!vertexShader) {
+ LOG_ERROR("Failed to create vertex shader");
+ return 0;
}
- canvas.set(new skia::PlatformCanvas(dirtyRect.width(), dirtyRect.height(), false));
- skiaContext.set(new PlatformContextSkia(canvas.get()));
-
-#if OS(WINDOWS)
- // This is needed to get text to show up correctly. Without it,
- // GDI renders with zero alpha and the text becomes invisible.
- // Unfortunately, setting this to true disables cleartype.
- // FIXME: Does this take us down a very slow text rendering path?
- // FIXME: why is this is a windows-only call ?
- skiaContext->setDrawingToImageBuffer(true);
-#endif
-
- graphicsContext.set(new GraphicsContext(reinterpret_cast<PlatformGraphicsContext*>(skiaContext.get())));
-
- // Bring the canvas into the coordinate system of the paint rect.
- canvas->translate(static_cast<SkScalar>(-dirtyRect.x()), static_cast<SkScalar>(-dirtyRect.y()));
-
- m_owner->paintGraphicsLayerContents(*graphicsContext, dirtyRect);
- const SkBitmap& bitmap = canvas->getDevice()->accessBitmap(false);
- skiaBitmap = &bitmap;
- ASSERT(skiaBitmap);
-
- SkAutoLockPixels lock(*skiaBitmap);
- SkBitmap::Config skiaConfig = skiaBitmap->config();
- // FIXME: do we need to support more image configurations?
- if (skiaConfig == SkBitmap::kARGB_8888_Config) {
- pixels = skiaBitmap->getPixels();
- bitmapSize = IntSize(skiaBitmap->width(), skiaBitmap->height());
- }
-#elif PLATFORM(CG)
- requiredTextureSize = m_bounds;
- IntRect boundsRect(IntPoint(0, 0), m_bounds);
-
- // If the texture needs to be reallocated then we must redraw the entire
- // contents of the layer.
- if (requiredTextureSize != m_allocatedTextureSize)
- dirtyRect = boundsRect;
- else {
- // Clip the dirtyRect to the size of the layer to avoid drawing outside
- // the bounds of the backing texture.
- dirtyRect.intersect(boundsRect);
+ GLuint fragmentShader = loadShader(GL_FRAGMENT_SHADER, fragmentShaderSource);
+ if (!fragmentShader) {
+ GLC(glDeleteShader(vertexShader));
+ LOG_ERROR("Failed to create fragment shader");
+ return 0;
}
- Vector<uint8_t> tempVector;
- int rowBytes = 4 * dirtyRect.width();
- tempVector.resize(rowBytes * dirtyRect.height());
- memset(tempVector.data(), 0, tempVector.size());
- RetainPtr<CGColorSpaceRef> colorSpace(AdoptCF, CGColorSpaceCreateDeviceRGB());
- RetainPtr<CGContextRef> contextCG(AdoptCF, CGBitmapContextCreate(tempVector.data(),
- dirtyRect.width(), dirtyRect.height(), 8, rowBytes,
- colorSpace.get(),
- kCGImageAlphaPremultipliedLast));
-
- GraphicsContext graphicsContext(contextCG.get());
-
- // Translate the graphics contxt into the coordinate system of the dirty rect.
- graphicsContext.translate(-dirtyRect.x(), -dirtyRect.y());
-
- m_owner->paintGraphicsLayerContents(graphicsContext, dirtyRect);
-
- pixels = tempVector.data();
- bitmapSize = dirtyRect.size();
-#else
-#error "Need to implement for your platform."
-#endif
+ GLuint programObject = glCreateProgram();
+ if (!programObject) {
+ LOG_ERROR("Failed to create shader program");
+ return 0;
+ }
- if (pixels)
- updateTextureRect(pixels, bitmapSize, requiredTextureSize, dirtyRect, textureId);
-}
+ GLC(glAttachShader(programObject, vertexShader));
+ GLC(glAttachShader(programObject, fragmentShader));
-void LayerChromium::updateTextureRect(void* pixels, const IntSize& bitmapSize, const IntSize& requiredTextureSize, const IntRect& updateRect, unsigned textureId)
-{
- if (!pixels)
- return;
+ // Bind the common attrib locations.
+ GLC(glBindAttribLocation(programObject, s_positionAttribLocation, "a_position"));
+ GLC(glBindAttribLocation(programObject, s_texCoordAttribLocation, "a_texCoord"));
- glBindTexture(GL_TEXTURE_2D, textureId);
- // If the texture id or size changed since last time then we need to tell GL
- // to re-allocate a texture.
- if (m_allocatedTextureId != textureId || requiredTextureSize != m_allocatedTextureSize) {
- ASSERT(bitmapSize == requiredTextureSize);
- glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, requiredTextureSize.width(), requiredTextureSize.height(), 0, GL_RGBA, GL_UNSIGNED_BYTE, pixels);
-
- m_allocatedTextureId = textureId;
- m_allocatedTextureSize = requiredTextureSize;
- } else {
- ASSERT(updateRect.width() <= m_allocatedTextureSize.width() && updateRect.height() <= m_allocatedTextureSize.height());
- ASSERT(updateRect.width() == bitmapSize.width() && updateRect.height() == bitmapSize.height());
-#if PLATFORM(CG)
- // The origin is at the lower left in Core Graphics' coordinate system. We need to correct for this here.
- glTexSubImage2D(GL_TEXTURE_2D, 0,
- updateRect.x(), m_allocatedTextureSize.height() - updateRect.height() - updateRect.y(),
- updateRect.width(), updateRect.height(),
- GL_RGBA, GL_UNSIGNED_BYTE, pixels);
-#elif PLATFORM(SKIA)
- glTexSubImage2D(GL_TEXTURE_2D, 0, updateRect.x(), updateRect.y(), updateRect.width(), updateRect.height(), GL_RGBA, GL_UNSIGNED_BYTE, pixels);
-#else
-#error "Need to implement for your platform."
-#endif
+ GLC(glLinkProgram(programObject));
+ GLint linked;
+ GLC(glGetProgramiv(programObject, GL_LINK_STATUS, &linked));
+ if (!linked) {
+ LOG_ERROR("Failed to link shader program");
+ GLC(glDeleteProgram(programObject));
+ return 0;
}
- m_dirtyRect.setSize(FloatSize());
- m_contentsDirty = false;
+ GLC(glDeleteShader(vertexShader));
+ GLC(glDeleteShader(fragmentShader));
+ return programObject;
}
void LayerChromium::setNeedsCommit()
@@ -377,5 +363,86 @@ void LayerChromium::setNeedsDisplay()
m_contentsDirty = true;
}
+void LayerChromium::toGLMatrix(float* flattened, const TransformationMatrix& m)
+{
+ flattened[0] = m.m11();
+ flattened[1] = m.m12();
+ flattened[2] = m.m13();
+ flattened[3] = m.m14();
+ flattened[4] = m.m21();
+ flattened[5] = m.m22();
+ flattened[6] = m.m23();
+ flattened[7] = m.m24();
+ flattened[8] = m.m31();
+ flattened[9] = m.m32();
+ flattened[10] = m.m33();
+ flattened[11] = m.m34();
+ flattened[12] = m.m41();
+ flattened[13] = m.m42();
+ flattened[14] = m.m43();
+ flattened[15] = m.m44();
+}
+
+void LayerChromium::drawTexturedQuad(const TransformationMatrix& projectionMatrix, const TransformationMatrix& drawMatrix,
+ float width, float height, float opacity,
+ int matrixLocation, int alphaLocation)
+{
+ static GLfloat glMatrix[16];
+
+ TransformationMatrix renderMatrix = drawMatrix;
+
+ // Apply a scaling factor to size the quad from 1x1 to its intended size.
+ renderMatrix.scale3d(width, height, 1);
+
+ // Apply the projection matrix before sending the transform over to the shader.
+ renderMatrix.multiply(projectionMatrix);
+
+ toGLMatrix(&glMatrix[0], renderMatrix);
+
+ GLC(glUniformMatrix4fv(matrixLocation, 1, false, &glMatrix[0]));
+
+ if (alphaLocation != -1)
+ GLC(glUniform1f(alphaLocation, opacity));
+
+ GLC(glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, 0));
+}
+
+void LayerChromium::drawDebugBorder()
+{
+ static GLfloat glMatrix[16];
+ if (!borderColor().alpha())
+ return;
+
+ ASSERT(layerRenderer());
+ const SharedValues* sv = layerRenderer()->layerSharedValues();
+ ASSERT(sv && sv->initialized());
+ layerRenderer()->useShader(sv->borderShaderProgram());
+ TransformationMatrix renderMatrix = drawTransform();
+ renderMatrix.scale3d(bounds().width(), bounds().height(), 1);
+ renderMatrix.multiply(layerRenderer()->projectionMatrix());
+ toGLMatrix(&glMatrix[0], renderMatrix);
+ GLC(glUniformMatrix4fv(sv->borderShaderMatrixLocation(), 1, false, &glMatrix[0]));
+
+ GLC(glUniform4f(sv->borderShaderColorLocation(), borderColor().red() / 255.0, borderColor().green() / 255.0, borderColor().blue() / 255.0, 1));
+
+ GLC(glLineWidth(borderWidth()));
+
+ // The indices for the line are stored in the same array as the triangle indices.
+ GLC(glDrawElements(GL_LINE_LOOP, 4, GL_UNSIGNED_SHORT, (void*)(6 * sizeof(unsigned short))));
+}
+
+// static
+void LayerChromium::prepareForDraw(const SharedValues* sv)
+{
+ GLC(glBindBuffer(GL_ARRAY_BUFFER, sv->quadVerticesVbo()));
+ GLC(glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, sv->quadElementsVbo()));
+ GLuint offset = 0;
+ GLC(glVertexAttribPointer(s_positionAttribLocation, 3, GL_FLOAT, GL_FALSE, 5 * sizeof(GLfloat), (GLvoid*)offset));
+ offset += 3 * sizeof(GLfloat);
+ GLC(glVertexAttribPointer(s_texCoordAttribLocation, 2, GL_FLOAT, GL_FALSE, 5 * sizeof(GLfloat), (GLvoid*)offset));
+ GLC(glEnableVertexAttribArray(s_positionAttribLocation));
+ GLC(glEnableVertexAttribArray(s_texCoordAttribLocation));
+}
+
}
#endif // USE(ACCELERATED_COMPOSITING)
diff --git a/WebCore/platform/graphics/chromium/LayerChromium.h b/WebCore/platform/graphics/chromium/LayerChromium.h
index 9fba415..0d0d362 100644
--- a/WebCore/platform/graphics/chromium/LayerChromium.h
+++ b/WebCore/platform/graphics/chromium/LayerChromium.h
@@ -55,19 +55,24 @@ namespace WebCore {
class GraphicsContext3D;
class LayerRendererChromium;
-// Base class for composited layers. The implementation covers layers that require
-// a GraphicsContext to render their contents. Special layer types are derived from
+// Base class for composited layers. Special layer types are derived from
// this class.
class LayerChromium : public RefCounted<LayerChromium> {
+ friend class LayerRendererChromium;
public:
static PassRefPtr<LayerChromium> create(GraphicsLayerChromium* owner = 0);
~LayerChromium();
+ const LayerChromium* rootLayer() const;
+ LayerChromium* superlayer() const;
void addSublayer(PassRefPtr<LayerChromium>);
void insertSublayer(PassRefPtr<LayerChromium>, size_t index);
void replaceSublayer(LayerChromium* reference, PassRefPtr<LayerChromium> newLayer);
void removeFromSuperlayer();
+ void removeAllSublayers();
+ void setSublayers(const Vector<RefPtr<LayerChromium> >&);
+ const Vector<RefPtr<LayerChromium> >& getSublayers() const { return m_sublayers; }
void setAnchorPoint(const FloatPoint& anchorPoint) { m_anchorPoint = anchorPoint; setNeedsCommit(); }
FloatPoint anchorPoint() const { return m_anchorPoint; }
@@ -93,9 +98,6 @@ public:
void setDoubleSided(bool doubleSided) { m_doubleSided = doubleSided; setNeedsCommit(); }
bool doubleSided() const { return m_doubleSided; }
- void setEdgeAntialiasingMask(uint32_t mask) { m_edgeAntialiasingMask = mask; setNeedsCommit(); }
- uint32_t edgeAntialiasingMask() const { return m_edgeAntialiasingMask; }
-
void setFrame(const FloatRect&);
FloatRect frame() const { return m_frame; }
@@ -120,76 +122,99 @@ public:
bool opaque() const { return m_opaque; }
void setPosition(const FloatPoint& position) { m_position = position; setNeedsCommit(); }
-
FloatPoint position() const { return m_position; }
void setZPosition(float zPosition) { m_zPosition = zPosition; setNeedsCommit(); }
float zPosition() const { return m_zPosition; }
- const LayerChromium* rootLayer() const;
-
- void removeAllSublayers();
-
- void setSublayers(const Vector<RefPtr<LayerChromium> >&);
-
- const Vector<RefPtr<LayerChromium> >& getSublayers() const { return m_sublayers; }
-
void setSublayerTransform(const TransformationMatrix& transform) { m_sublayerTransform = transform; setNeedsCommit(); }
const TransformationMatrix& sublayerTransform() const { return m_sublayerTransform; }
- LayerChromium* superlayer() const;
-
-
void setTransform(const TransformationMatrix& transform) { m_transform = transform; setNeedsCommit(); }
const TransformationMatrix& transform() const { return m_transform; }
+ // FIXME: This setting is currently ignored.
void setGeometryFlipped(bool flipped) { m_geometryFlipped = flipped; setNeedsCommit(); }
bool geometryFlipped() const { return m_geometryFlipped; }
- virtual void updateTextureContents(unsigned textureId);
- bool contentsDirty() { return m_contentsDirty; }
-
void setDrawTransform(const TransformationMatrix& transform) { m_drawTransform = transform; }
const TransformationMatrix& drawTransform() const { return m_drawTransform; }
void setDrawOpacity(float opacity) { m_drawOpacity = opacity; }
float drawOpacity() const { return m_drawOpacity; }
- virtual bool drawsContent() { return m_owner && m_owner->drawsContent(); }
-
- // Return true if the layer has its own GL texture and false if the texture
- // needs to be allocated by the compositor.
- virtual bool ownsTexture() { return false; }
-
- // Returns the id of the GL texture that stores the contents of this layer.
- // Derived layer classes that own their own textures should overwrite this method.
- virtual unsigned textureId() { return m_allocatedTextureId; }
-
bool preserves3D() { return m_owner && m_owner->preserves3D(); }
void setLayerRenderer(LayerRendererChromium*);
- static void setShaderProgramId(unsigned shaderProgramId) { m_shaderProgramId = shaderProgramId; }
- virtual unsigned shaderProgramId() { return m_shaderProgramId; }
-
void setOwner(GraphicsLayerChromium* owner) { m_owner = owner; }
+ bool contentsDirty() { return m_contentsDirty; }
+
+ // These methods typically need to be overwritten by derived classes.
+ virtual bool drawsContent() { return false; }
+ virtual void updateContents() { };
+ virtual void draw() { };
+
+ void drawDebugBorder();
+
+ // Stores values that are shared between instances of this class that are
+ // associated with the same LayerRendererChromium (and hence the same GL
+ // context).
+ class SharedValues {
+ public:
+ SharedValues();
+ ~SharedValues();
+
+ unsigned quadVerticesVbo() const { return m_quadVerticesVbo; }
+ unsigned quadElementsVbo() const { return m_quadElementsVbo; }
+ int maxTextureSize() const { return m_maxTextureSize; }
+ unsigned borderShaderProgram() const { return m_borderShaderProgram; }
+ int borderShaderMatrixLocation() const { return m_borderShaderMatrixLocation; }
+ int borderShaderColorLocation() const { return m_borderShaderColorLocation; }
+ bool initialized() const { return m_initialized; }
+
+ private:
+ unsigned m_quadVerticesVbo;
+ unsigned m_quadElementsVbo;
+ int m_maxTextureSize;
+ unsigned m_borderShaderProgram;
+ int m_borderShaderMatrixLocation;
+ int m_borderShaderColorLocation;
+ bool m_initialized;
+ };
+
+ static void prepareForDraw(const SharedValues*);
+
protected:
GraphicsLayerChromium* m_owner;
LayerChromium(GraphicsLayerChromium* owner);
- void updateTextureRect(void* pixels, const IntSize& bitmapSize, const IntSize& requiredTextureSize, const IntRect& dirtyRect, unsigned textureId);
+
+ LayerRendererChromium* layerRenderer() const { return m_layerRenderer; }
+
+ static void drawTexturedQuad(const TransformationMatrix& projectionMatrix, const TransformationMatrix& layerMatrix,
+ float width, float height, float opacity,
+ int matrixLocation, int alphaLocation);
+
+ static void toGLMatrix(float*, const TransformationMatrix&);
+
+ static unsigned createShaderProgram(const char* vertexShaderSource, const char* fragmentShaderSource);
IntSize m_bounds;
FloatRect m_dirtyRect;
bool m_contentsDirty;
+ // All layer shaders share the same attribute locations for the vertex positions
+ // and texture coordinates. This allows switching shaders without rebinding attribute
+ // arrays.
+ static const unsigned s_positionAttribLocation;
+ static const unsigned s_texCoordAttribLocation;
+
private:
void setNeedsCommit();
void setSuperlayer(LayerChromium* superlayer) { m_superlayer = superlayer; }
- void paintMe();
-
size_t numSublayers() const
{
return m_sublayers.size();
@@ -204,35 +229,17 @@ private:
Vector<RefPtr<LayerChromium> > m_sublayers;
LayerChromium* m_superlayer;
+ // Layer properties.
IntSize m_backingStoreSize;
FloatPoint m_position;
FloatPoint m_anchorPoint;
Color m_backgroundColor;
Color m_borderColor;
-
- LayerRendererChromium* m_layerRenderer;
-
- FloatRect m_frame;
- TransformationMatrix m_transform;
- TransformationMatrix m_sublayerTransform;
-
- TransformationMatrix m_drawTransform;
-
- uint32_t m_edgeAntialiasingMask;
float m_opacity;
float m_zPosition;
float m_anchorPointZ;
float m_borderWidth;
-
float m_drawOpacity;
-
- unsigned m_allocatedTextureId;
- IntSize m_allocatedTextureSize;
-
- // The shader program used by all layers of this type is the same.
- // This static can be shadowed by derived classes to use a special shader.
- static unsigned m_shaderProgramId;
-
bool m_clearsContext;
bool m_doubleSided;
bool m_hidden;
@@ -241,6 +248,14 @@ private:
bool m_geometryFlipped;
bool m_needsDisplayOnBoundsChange;
+ // Points to the layer renderer that updates and draws this layer.
+ LayerRendererChromium* m_layerRenderer;
+
+ FloatRect m_frame;
+ TransformationMatrix m_transform;
+ TransformationMatrix m_sublayerTransform;
+ TransformationMatrix m_drawTransform;
+
String m_name;
};
diff --git a/WebCore/platform/graphics/chromium/LayerRendererChromium.cpp b/WebCore/platform/graphics/chromium/LayerRendererChromium.cpp
index 2f70efa..cf23871 100644
--- a/WebCore/platform/graphics/chromium/LayerRendererChromium.cpp
+++ b/WebCore/platform/graphics/chromium/LayerRendererChromium.cpp
@@ -35,10 +35,10 @@
#include "LayerRendererChromium.h"
#include "CanvasLayerChromium.h"
+#include "ContentLayerChromium.h"
#include "GLES2Context.h"
#include "LayerChromium.h"
#include "NotImplemented.h"
-#include "TransformLayerChromium.h"
#if PLATFORM(SKIA)
#include "NativeImageSkia.h"
#include "PlatformContextSkia.h"
@@ -50,101 +50,6 @@
namespace WebCore {
-#ifndef NDEBUG
-static WTFLogChannel LogLayerRenderer = { 0x00000000, "LayerRenderer", WTFLogChannelOn };
-#endif
-
-static void checkGLError()
-{
-#ifndef NDEBUG
- GLenum error = glGetError();
- if (error)
- LOG_ERROR("GL Error: %d " , error);
-#endif
-}
-
-static GLuint loadShader(GLenum type, const char* shaderSource)
-{
- GLuint shader = glCreateShader(type);
- if (!shader)
- return 0;
- glShaderSource(shader, 1, &shaderSource, 0);
- glCompileShader(shader);
- GLint compiled;
- glGetShaderiv(shader, GL_COMPILE_STATUS, &compiled);
- if (!compiled) {
- glDeleteShader(shader);
- return 0;
- }
- return shader;
-}
-
-static GLuint loadShaderProgram(const char* vertexShaderSource, const char* fragmentShaderSource)
-{
- GLuint vertexShader;
- GLuint fragmentShader;
- GLuint programObject;
- GLint linked;
- vertexShader = loadShader(GL_VERTEX_SHADER, vertexShaderSource);
- if (!vertexShader)
- return 0;
- fragmentShader = loadShader(GL_FRAGMENT_SHADER, fragmentShaderSource);
- if (!fragmentShader) {
- glDeleteShader(vertexShader);
- return 0;
- }
- programObject = glCreateProgram();
- if (!programObject)
- return 0;
- glAttachShader(programObject, vertexShader);
- glAttachShader(programObject, fragmentShader);
- glLinkProgram(programObject);
- glGetProgramiv(programObject, GL_LINK_STATUS, &linked);
- if (!linked) {
- glDeleteProgram(programObject);
- return 0;
- }
- glDeleteShader(vertexShader);
- glDeleteShader(fragmentShader);
- return programObject;
-}
-
-bool LayerRendererChromium::createLayerShader(ShaderProgramType type, const char* vertexShaderSource, const char* fragmentShaderSource)
-{
- unsigned programId = loadShaderProgram(vertexShaderSource, fragmentShaderSource);
- ASSERT(programId);
-
- ShaderProgram* program = &m_shaderPrograms[type];
-
- program->m_shaderProgramId = programId;
- program->m_samplerLocation = glGetUniformLocation(programId, "s_texture");
- program->m_matrixLocation = glGetUniformLocation(programId, "matrix");
- program->m_alphaLocation = glGetUniformLocation(programId, "alpha");
-
- return programId;
-}
-
-
-static void toGLMatrix(float* flattened, const TransformationMatrix& m)
-{
- flattened[0] = m.m11();
- flattened[1] = m.m12();
- flattened[2] = m.m13();
- flattened[3] = m.m14();
- flattened[4] = m.m21();
- flattened[5] = m.m22();
- flattened[6] = m.m23();
- flattened[7] = m.m24();
- flattened[8] = m.m31();
- flattened[9] = m.m32();
- flattened[10] = m.m33();
- flattened[11] = m.m34();
- flattened[12] = m.m41();
- flattened[13] = m.m42();
- flattened[14] = m.m43();
- flattened[15] = m.m44();
-}
-
static TransformationMatrix orthoMatrix(float left, float right, float bottom, float top, float nearZ, float farZ)
{
float deltaX = right - left;
@@ -162,21 +67,6 @@ static TransformationMatrix orthoMatrix(float left, float right, float bottom, f
return ortho;
}
-// Creates a GL texture object to be used for transfering the layer's bitmap into.
-static GLuint createLayerTexture()
-{
- GLuint textureId = 0;
- glGenTextures(1, &textureId);
- glBindTexture(GL_TEXTURE_2D, textureId);
- // Do basic linear filtering on resize.
- glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
- glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
- // NPOT textures in GL ES only work when the wrap mode is set to GL_CLAMP_TO_EDGE.
- glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
- glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
- return textureId;
-}
-
static inline bool compareLayerZ(const LayerChromium* a, const LayerChromium* b)
{
const TransformationMatrix& transformA = a->drawTransform();
@@ -185,51 +75,35 @@ static inline bool compareLayerZ(const LayerChromium* a, const LayerChromium* b)
return transformA.m43() < transformB.m43();
}
-ShaderProgram::ShaderProgram()
- : m_shaderProgramId(0)
- , m_samplerLocation(-1)
- , m_matrixLocation(-1)
- , m_alphaLocation(-1)
-{
-}
-
PassOwnPtr<LayerRendererChromium> LayerRendererChromium::create(PassOwnPtr<GLES2Context> gles2Context)
{
return new LayerRendererChromium(gles2Context);
}
LayerRendererChromium::LayerRendererChromium(PassOwnPtr<GLES2Context> gles2Context)
- : m_rootLayerTextureWidth(0)
+ : m_rootLayerTextureId(0)
+ , m_rootLayerTextureWidth(0)
, m_rootLayerTextureHeight(0)
- , m_positionLocation(0)
- , m_texCoordLocation(1)
+ , m_scrollShaderProgram(0)
, m_rootLayer(0)
, m_needsDisplay(false)
, m_scrollPosition(IntPoint(-1, -1))
- , m_currentShaderProgramType(NumShaderProgramTypes)
+ , m_currentShader(0)
, m_gles2Context(gles2Context)
{
- m_quadVboIds[Vertices] = m_quadVboIds[LayerElements] = 0;
- m_hardwareCompositing = (m_gles2Context && initializeSharedGLObjects());
+ m_hardwareCompositing = (m_gles2Context && initializeSharedObjects());
}
LayerRendererChromium::~LayerRendererChromium()
{
- if (m_hardwareCompositing) {
- makeContextCurrent();
- glDeleteBuffers(3, m_quadVboIds);
-
- for (int i = 0; i < NumShaderProgramTypes; i++) {
- if (m_shaderPrograms[i].m_shaderProgramId)
- glDeleteProgram(m_shaderPrograms[i].m_shaderProgramId);
- }
- }
+ cleanupSharedObjects();
+}
- // Free up all GL textures.
- for (TextureIdMap::iterator iter = m_textureIdMap.begin(); iter != m_textureIdMap.end(); ++iter) {
- glDeleteTextures(1, &(iter->second));
- iter->first->setLayerRenderer(0);
- }
+void LayerRendererChromium::debugGLCall(const char* command, const char* file, int line)
+{
+ GLenum error = glGetError();
+ if (error != GL_NO_ERROR)
+ LOG_ERROR("GL command failed: File: %s\n\tLine %d\n\tcommand: %s, error %x\n", file, line, command, error);
}
// Creates a canvas and an associated graphics context that the root layer will
@@ -268,43 +142,14 @@ void LayerRendererChromium::setRootLayerCanvasSize(const IntSize& size)
m_rootLayerCanvasSize = size;
}
-void LayerRendererChromium::useShaderProgram(ShaderProgramType programType)
+void LayerRendererChromium::useShader(unsigned programId)
{
- if (programType != m_currentShaderProgramType) {
- ShaderProgram* program = &m_shaderPrograms[programType];
- glUseProgram(program->m_shaderProgramId);
- m_currentShaderProgramType = programType;
-
- // Set the uniform locations matching the program.
- m_samplerLocation = program->m_samplerLocation;
- m_matrixLocation = program->m_matrixLocation;
- m_alphaLocation = program->m_alphaLocation;
+ if (programId != m_currentShader) {
+ GLC(glUseProgram(programId));
+ m_currentShader = programId;
}
}
-void LayerRendererChromium::drawTexturedQuad(const TransformationMatrix& matrix, float width, float height, float opacity)
-{
- static GLfloat glMatrix[16];
-
- TransformationMatrix renderMatrix = matrix;
-
- // Apply a scaling factor to size the quad from 1x1 to its intended size.
- renderMatrix.scale3d(width, height, 1);
-
- // Apply the projection matrix before sending the transform over to the shader.
- renderMatrix.multiply(m_projectionMatrix);
-
- toGLMatrix(&glMatrix[0], renderMatrix);
-
- glUniformMatrix4fv(m_matrixLocation, 1, false, &glMatrix[0]);
-
- if (m_alphaLocation != -1)
- glUniform1f(m_alphaLocation, opacity);
-
- glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, 0);
-}
-
-
// Updates the contents of the root layer texture that fall inside the updateRect
// and re-composits all sublayers.
void LayerRendererChromium::drawLayers(const IntRect& updateRect, const IntRect& visibleRect,
@@ -315,17 +160,13 @@ void LayerRendererChromium::drawLayers(const IntRect& updateRect, const IntRect&
if (!m_rootLayer)
return;
- // If the size of the visible area has changed then allocate a new texture
- // to store the contents of the root layer and adjust the projection matrix
- // and viewport.
makeContextCurrent();
- checkGLError();
-
- glBindTexture(GL_TEXTURE_2D, m_rootLayerTextureId);
-
- checkGLError();
+ GLC(glBindTexture(GL_TEXTURE_2D, m_rootLayerTextureId));
+ // If the size of the visible area has changed then allocate a new texture
+ // to store the contents of the root layer and adjust the projection matrix
+ // and viewport.
int visibleRectWidth = visibleRect.width();
int visibleRectHeight = visibleRect.height();
if (visibleRectWidth != m_rootLayerTextureWidth || visibleRectHeight != m_rootLayerTextureHeight) {
@@ -333,38 +174,18 @@ void LayerRendererChromium::drawLayers(const IntRect& updateRect, const IntRect&
m_rootLayerTextureHeight = visibleRect.height();
m_projectionMatrix = orthoMatrix(0, visibleRectWidth, visibleRectHeight, 0, -1000, 1000);
- glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, m_rootLayerTextureWidth, m_rootLayerTextureHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);
-
- checkGLError();
+ GLC(glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, m_rootLayerTextureWidth, m_rootLayerTextureHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0));
}
// The GL viewport covers the entire visible area, including the scrollbars.
- glViewport(0, 0, visibleRectWidth, visibleRectHeight);
-
- checkGLError();
-
- // The layer, scroll and debug border shaders all use the same vertex attributes
- // so we can bind them only once.
- glBindBuffer(GL_ARRAY_BUFFER, m_quadVboIds[Vertices]);
- checkGLError();
- glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_quadVboIds[LayerElements]);
- checkGLError();
- GLuint offset = 0;
- glVertexAttribPointer(m_positionLocation, 3, GL_FLOAT, GL_FALSE, 5 * sizeof(GLfloat), (GLvoid*)(offset));
- checkGLError();
- offset += 3 * sizeof(GLfloat);
- glVertexAttribPointer(m_texCoordLocation, 2, GL_FLOAT, GL_FALSE, 5 * sizeof(GLfloat), (GLvoid*)(offset));
- checkGLError();
- glEnableVertexAttribArray(m_positionLocation);
- checkGLError();
- glEnableVertexAttribArray(m_texCoordLocation);
- checkGLError();
- glActiveTexture(GL_TEXTURE0);
- checkGLError();
- glDisable(GL_DEPTH_TEST);
- checkGLError();
- glDisable(GL_CULL_FACE);
- checkGLError();
+ GLC(glViewport(0, 0, visibleRectWidth, visibleRectHeight));
+
+ // Bind the common vertex attributes used for drawing all the layers.
+ LayerChromium::prepareForDraw(layerSharedValues());
+
+ GLC(glDisable(GL_DEPTH_TEST));
+ GLC(glDisable(GL_CULL_FACE));
+ GLC(glDepthFunc(GL_LEQUAL));
if (m_scrollPosition == IntPoint(-1, -1))
m_scrollPosition = scrollPosition;
@@ -390,21 +211,21 @@ void LayerRendererChromium::drawLayers(const IntRect& updateRect, const IntRect&
#error "Need to implement for your platform."
#endif
- scrolledLayerMatrix.translate3d((int)floorf(0.5 * visibleRect.width()) - scrollDelta.x(),
- (int)floorf(0.5 * visibleRect.height()) + scaleFactor * scrollDelta.y(), 0);
+ scrolledLayerMatrix.translate3d(0.5 * visibleRect.width() - scrollDelta.x(),
+ 0.5 * visibleRect.height() + scaleFactor * scrollDelta.y(), 0);
scrolledLayerMatrix.scale3d(1, -1, 1);
- // Switch shaders to avoid RGB swizzling.
- useShaderProgram(ScrollLayerProgram);
- glUniform1i(m_shaderPrograms[ScrollLayerProgram].m_samplerLocation, 0);
- checkGLError();
-
- drawTexturedQuad(scrolledLayerMatrix, visibleRect.width(), visibleRect.height(), 1);
- checkGLError();
+ useShader(m_scrollShaderProgram);
+ GLC(glUniform1i(m_scrollShaderSamplerLocation, 0));
+ LayerChromium::drawTexturedQuad(m_projectionMatrix, scrolledLayerMatrix,
+ visibleRect.width(), visibleRect.height(), 1,
+ m_scrollShaderMatrixLocation, -1);
- glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, contentRect.width(), contentRect.height());
-
- checkGLError();
+ GLC(glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, contentRect.width(), contentRect.height()));
+ m_scrollPosition = scrollPosition;
+ } else if (abs(scrollDelta.y()) > contentRect.height() || abs(scrollDelta.x()) > contentRect.width()) {
+ // Scrolling larger than the contentRect size does not preserve any of the pixels, so there is
+ // no need to copy framebuffer pixels back into the texture.
m_scrollPosition = scrollPosition;
}
@@ -423,154 +244,92 @@ void LayerRendererChromium::drawLayers(const IntRect& updateRect, const IntRect&
ASSERT(rootLayerWidth == updateRect.width() && rootLayerHeight == updateRect.height());
void* pixels = bitmap.getPixels();
- checkGLError();
// Copy the contents of the updated rect to the root layer texture.
- glTexSubImage2D(GL_TEXTURE_2D, 0, updateRect.x(), updateRect.y(), updateRect.width(), updateRect.height(), GL_RGBA, GL_UNSIGNED_BYTE, pixels);
- checkGLError();
+ GLC(glTexSubImage2D(GL_TEXTURE_2D, 0, updateRect.x(), updateRect.y(), updateRect.width(), updateRect.height(), GL_RGBA, GL_UNSIGNED_BYTE, pixels));
#elif PLATFORM(CG)
// Get the contents of the updated rect.
ASSERT(static_cast<int>(CGBitmapContextGetWidth(m_rootLayerCGContext.get())) == updateRect.width() && static_cast<int>(CGBitmapContextGetHeight(m_rootLayerCGContext.get())) == updateRect.height());
void* pixels = m_rootLayerBackingStore.data();
- checkGLError();
// Copy the contents of the updated rect to the root layer texture.
// The origin is at the lower left in Core Graphics' coordinate system. We need to correct for this here.
- glTexSubImage2D(GL_TEXTURE_2D, 0,
- updateRect.x(), m_rootLayerTextureHeight - updateRect.y() - updateRect.height(),
- updateRect.width(), updateRect.height(),
- GL_RGBA, GL_UNSIGNED_BYTE, pixels);
- checkGLError();
+ GLC(glTexSubImage2D(GL_TEXTURE_2D, 0,
+ updateRect.x(), m_rootLayerTextureHeight - updateRect.y() - updateRect.height(),
+ updateRect.width(), updateRect.height(),
+ GL_RGBA, GL_UNSIGNED_BYTE, pixels));
#else
#error "Need to implement for your platform."
#endif
}
glClearColor(0, 0, 1, 1);
- checkGLError();
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
- checkGLError();
// Render the root layer using a quad that takes up the entire visible area of the window.
- useShaderProgram(ContentLayerProgram);
- checkGLError();
- glUniform1i(m_samplerLocation, 0);
- checkGLError();
+ // We reuse the shader program used by ContentLayerChromium.
+ const ContentLayerChromium::SharedValues* contentLayerValues = contentLayerSharedValues();
+ useShader(contentLayerValues->contentShaderProgram());
+ GLC(glUniform1i(contentLayerValues->shaderSamplerLocation(), 0));
TransformationMatrix layerMatrix;
layerMatrix.translate3d(visibleRect.width() * 0.5f, visibleRect.height() * 0.5f, 0);
- drawTexturedQuad(layerMatrix, visibleRect.width(), visibleRect.height(), 1);
- checkGLError();
+ LayerChromium::drawTexturedQuad(m_projectionMatrix, layerMatrix,
+ visibleRect.width(), visibleRect.height(), 1,
+ contentLayerValues->shaderMatrixLocation(), contentLayerValues->shaderAlphaLocation());
// If culling is enabled then we will cull the backface.
- glCullFace(GL_BACK);
- checkGLError();
+ GLC(glCullFace(GL_BACK));
// The orthographic projection is setup such that Y starts at zero and
// increases going down the page so we need to adjust the winding order of
// front facing triangles.
- glFrontFace(GL_CW);
- checkGLError();
+ GLC(glFrontFace(GL_CW));
// The shader used to render layers returns pre-multiplied alpha colors
// so we need to send the blending mode appropriately.
- glEnable(GL_BLEND);
- checkGLError();
- glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
-
- checkGLError();
+ GLC(glEnable(GL_BLEND));
+ GLC(glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA));
// Translate all the composited layers by the scroll position.
TransformationMatrix matrix;
matrix.translate3d(-m_scrollPosition.x(), -m_scrollPosition.y(), 0);
+ // Traverse the layer tree and update the layer transforms.
float opacity = 1;
- m_layerList.shrink(0);
const Vector<RefPtr<LayerChromium> >& sublayers = m_rootLayer->getSublayers();
- for (size_t i = 0; i < sublayers.size(); i++)
- updateLayersRecursive(sublayers[i].get(), matrix, opacity, visibleRect);
-
- // Sort layers by the z coordinate of their center so that layers further
- // away get drawn first.
- std::stable_sort(m_layerList.begin(), m_layerList.end(), compareLayerZ);
+ size_t i;
+ for (i = 0; i < sublayers.size(); i++)
+ updateLayersRecursive(sublayers[i].get(), matrix, opacity);
// Enable scissoring to avoid rendering composited layers over the scrollbars.
- glEnable(GL_SCISSOR_TEST);
- glScissor(0, visibleRect.height() - contentRect.height(), contentRect.width(), contentRect.height());
+ GLC(glEnable(GL_SCISSOR_TEST));
+ GLC(glScissor(0, visibleRect.height() - contentRect.height(), contentRect.width(), contentRect.height()));
- for (size_t j = 0; j < m_layerList.size(); j++)
- drawLayer(m_layerList[j]);
+ // Traverse the layer tree one more time to draw the layers.
+ m_visibleRect = visibleRect;
+ for (i = 0; i < sublayers.size(); i++)
+ drawLayersRecursive(sublayers[i].get());
- glDisable(GL_SCISSOR_TEST);
+ GLC(glDisable(GL_SCISSOR_TEST));
- glFlush();
m_gles2Context->swapBuffers();
m_needsDisplay = false;
}
-// Returns the id of the texture currently associated with the layer or
-// -1 if the id hasn't been registered yet.
-int LayerRendererChromium::getTextureId(LayerChromium* layer)
+// FIXME: This method should eventually be replaced by a proper texture manager.
+unsigned LayerRendererChromium::createLayerTexture()
{
- TextureIdMap::iterator textureId = m_textureIdMap.find(layer);
- if (textureId != m_textureIdMap.end())
- return textureId->second;
-
- return -1;
-}
-
-// Allocates a new texture for the layer and registers it in the textureId map.
-// FIXME: We will need to come up with a more sophisticated allocation strategy here.
-int LayerRendererChromium::assignTextureForLayer(LayerChromium* layer)
-{
- GLuint textureId = createLayerTexture();
-
- // FIXME: Check that textureId is valid
- m_textureIdMap.set(layer, textureId);
-
- layer->setLayerRenderer(this);
-
+ GLuint textureId = 0;
+ GLC(glGenTextures(1, &textureId));
+ GLC(glBindTexture(GL_TEXTURE_2D, textureId));
+ // Do basic linear filtering on resize.
+ GLC(glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR));
+ GLC(glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR));
+ // NPOT textures in GL ES only work when the wrap mode is set to GL_CLAMP_TO_EDGE.
+ GLC(glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE));
+ GLC(glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE));
return textureId;
}
-bool LayerRendererChromium::freeLayerTexture(LayerChromium* layer)
-{
- TextureIdMap::iterator textureId = m_textureIdMap.find(layer);
- if (textureId == m_textureIdMap.end())
- return false;
- // Free up the texture.
- glDeleteTextures(1, &(textureId->second));
- m_textureIdMap.remove(textureId);
- return true;
-}
-
-// Draws a debug border around the layer's bounds.
-void LayerRendererChromium::drawDebugBorder(LayerChromium* layer, const TransformationMatrix& matrix)
-{
- static GLfloat glMatrix[16];
- Color borderColor = layer->borderColor();
- if (!borderColor.alpha())
- return;
-
- useShaderProgram(DebugBorderProgram);
- TransformationMatrix renderMatrix = matrix;
- IntSize bounds = layer->bounds();
- renderMatrix.scale3d(bounds.width(), bounds.height(), 1);
- renderMatrix.multiply(m_projectionMatrix);
- toGLMatrix(&glMatrix[0], renderMatrix);
- unsigned borderMatrixLocation = m_shaderPrograms[DebugBorderProgram].m_matrixLocation;
- glUniformMatrix4fv(borderMatrixLocation, 1, false, &glMatrix[0]);
-
- glUniform4f(m_borderColorLocation, borderColor.red() / 255.0,
- borderColor.green() / 255.0,
- borderColor.blue() / 255.0,
- 1);
-
- glLineWidth(layer->borderWidth());
-
- // The indices for the line are stored in the same array as the triangle indices.
- glDrawElements(GL_LINE_LOOP, 4, GL_UNSIGNED_SHORT, (void*)(6 * sizeof(unsigned short)));
- checkGLError();
-}
-
// Returns true if any part of the layer falls within the visibleRect
bool LayerRendererChromium::isLayerVisible(LayerChromium* layer, const TransformationMatrix& matrix, const IntRect& visibleRect)
{
@@ -588,9 +347,9 @@ bool LayerRendererChromium::isLayerVisible(LayerChromium* layer, const Transform
return mappedRect.intersects(FloatRect(-1, -1, 2, 2));
}
-// Updates and caches the layer transforms and opacity values that will be used
-// when rendering them.
-void LayerRendererChromium::updateLayersRecursive(LayerChromium* layer, const TransformationMatrix& parentMatrix, float opacity, const IntRect& visibleRect)
+// Recursively walks the layer tree starting at the given node and updates the
+// transform and opacity values.
+void LayerRendererChromium::updateLayersRecursive(LayerChromium* layer, const TransformationMatrix& parentMatrix, float opacity)
{
// Compute the new matrix transformation that will be applied to this layer and
// all its sublayers. It's important to remember that the layer's position
@@ -627,23 +386,11 @@ void LayerRendererChromium::updateLayersRecursive(LayerChromium* layer, const Tr
// M = M[p] * Tr[l] * M[l] * Tr[c]
localMatrix.translate3d(centerOffsetX, centerOffsetY, -layer->anchorPointZ());
- // Check if the layer falls within the visible bounds of the page.
- bool layerVisible = isLayerVisible(layer, localMatrix, visibleRect);
-
- bool skipLayer = false;
- if (bounds.width() > 2048 || bounds.height() > 2048) {
- if (layer->drawsContent())
- LOG(LayerRenderer, "Skipping layer with size %d %d", bounds.width(), bounds.height());
- skipLayer = true;
- }
-
// Calculate the layer's opacity.
opacity *= layer->opacity();
layer->setDrawTransform(localMatrix);
layer->setDrawOpacity(opacity);
- if (layerVisible && !skipLayer)
- m_layerList.append(layer);
// Flatten to 2D if the layer doesn't preserve 3D.
if (!layer->preserves3D()) {
@@ -667,29 +414,71 @@ void LayerRendererChromium::updateLayersRecursive(LayerChromium* layer, const Tr
const Vector<RefPtr<LayerChromium> >& sublayers = layer->getSublayers();
for (size_t i = 0; i < sublayers.size(); i++)
- updateLayersRecursive(sublayers[i].get(), localMatrix, opacity, visibleRect);
+ updateLayersRecursive(sublayers[i].get(), localMatrix, opacity);
+
+ layer->setLayerRenderer(this);
+}
+
+// Recursively walk the layer tree and draw the layers.
+void LayerRendererChromium::drawLayersRecursive(LayerChromium* layer)
+{
+ static bool depthTestEnabledForSubtree = false;
+
+ // Check if the layer falls within the visible bounds of the page.
+ bool layerVisible = isLayerVisible(layer, layer->drawTransform(), m_visibleRect);
+
+ // Enable depth testing for this layer and all its descendants if preserves3D is set.
+ bool mustClearDepth = false;
+ if (layer->preserves3D()) {
+ if (!depthTestEnabledForSubtree) {
+ GLC(glEnable(GL_DEPTH_TEST));
+ depthTestEnabledForSubtree = true;
+
+ // Need to clear the depth buffer when we're done rendering this subtree.
+ mustClearDepth = true;
+ }
+ }
+
+ if (layerVisible)
+ drawLayer(layer);
+
+ // If we're using depth testing then we need to sort the children in Z to
+ // get the transparency to work properly.
+ if (depthTestEnabledForSubtree) {
+ const Vector<RefPtr<LayerChromium> >& sublayers = layer->getSublayers();
+ Vector<LayerChromium*> sublayerList;
+ size_t i;
+ for (i = 0; i < sublayers.size(); i++)
+ sublayerList.append(sublayers[i].get());
+
+ // Sort by the z coordinate of the layer center so that layers further away
+ // are drawn first.
+ std::stable_sort(sublayerList.begin(), sublayerList.end(), compareLayerZ);
+
+ for (i = 0; i < sublayerList.size(); i++)
+ drawLayersRecursive(sublayerList[i]);
+ } else {
+ const Vector<RefPtr<LayerChromium> >& sublayers = layer->getSublayers();
+ for (size_t i = 0; i < sublayers.size(); i++)
+ drawLayersRecursive(sublayers[i].get());
+ }
+
+ if (mustClearDepth) {
+ GLC(glDisable(GL_DEPTH_TEST));
+ GLC(glClear(GL_DEPTH_BUFFER_BIT));
+ depthTestEnabledForSubtree = false;
+ }
}
void LayerRendererChromium::drawLayer(LayerChromium* layer)
{
- const TransformationMatrix& localMatrix = layer->drawTransform();
IntSize bounds = layer->bounds();
if (layer->drawsContent()) {
- int textureId;
- if (layer->ownsTexture())
- textureId = layer->textureId();
- else {
- textureId = getTextureId(layer);
- // If no texture has been created for the layer yet then create one now.
- if (textureId == -1)
- textureId = assignTextureForLayer(layer);
- }
-
- // Redraw the contents of the layer if necessary.
+ // Update the contents of the layer if necessary.
if (layer->contentsDirty()) {
// Update the backing texture contents for any dirty portion of the layer.
- layer->updateTextureContents(textureId);
+ layer->updateContents();
m_gles2Context->makeCurrent();
}
@@ -698,13 +487,11 @@ void LayerRendererChromium::drawLayer(LayerChromium* layer)
else
glEnable(GL_CULL_FACE);
- glBindTexture(GL_TEXTURE_2D, textureId);
- useShaderProgram(static_cast<ShaderProgramType>(layer->shaderProgramId()));
- drawTexturedQuad(localMatrix, bounds.width(), bounds.height(), layer->drawOpacity());
+ layer->draw();
}
// Draw the debug border if there is one.
- drawDebugBorder(layer, localMatrix);
+ layer->drawDebugBorder();
}
bool LayerRendererChromium::makeContextCurrent()
@@ -712,21 +499,22 @@ bool LayerRendererChromium::makeContextCurrent()
return m_gles2Context->makeCurrent();
}
-void LayerRendererChromium::bindCommonAttribLocations(ShaderProgramType program)
+// Checks whether a given size is within the maximum allowed texture size range.
+bool LayerRendererChromium::checkTextureSize(const IntSize& textureSize)
{
- unsigned programId = m_shaderPrograms[program].m_shaderProgramId;
- glBindAttribLocation(programId, m_positionLocation, "a_position");
- glBindAttribLocation(programId, m_texCoordLocation, "a_texCoord");
-
- // Re-link the program for the new attribute locations to take effect.
- glLinkProgram(programId);
- checkGLError();
+ if (textureSize.width() > m_maxTextureSize || textureSize.height() > m_maxTextureSize)
+ return false;
+ return true;
}
-bool LayerRendererChromium::initializeSharedGLObjects()
+bool LayerRendererChromium::initializeSharedObjects()
{
- // Shaders for drawing the layer contents.
- char vertexShaderString[] =
+ makeContextCurrent();
+
+ // Vertex and fragment shaders for rendering the scrolled root layer quad.
+ // They differ from a regular content layer shader in that they don't swizzle
+ // the colors or take an alpha value.
+ char scrollVertexShaderString[] =
"attribute vec4 a_position; \n"
"attribute vec2 a_texCoord; \n"
"uniform mat4 matrix; \n"
@@ -736,30 +524,6 @@ bool LayerRendererChromium::initializeSharedGLObjects()
" gl_Position = matrix * a_position; \n"
" v_texCoord = a_texCoord; \n"
"} \n";
- // Note differences between Skia and Core Graphics versions:
- // - Skia uses BGRA and origin is upper left
- // - Core Graphics uses RGBA and origin is lower left
- char fragmentShaderString[] =
- "precision mediump float; \n"
- "varying vec2 v_texCoord; \n"
- "uniform sampler2D s_texture; \n"
- "uniform float alpha; \n"
- "void main() \n"
- "{ \n"
-#if PLATFORM(SKIA)
- " vec4 texColor = texture2D(s_texture, v_texCoord); \n"
- " gl_FragColor = vec4(texColor.z, texColor.y, texColor.x, texColor.w) * alpha; \n"
-#elif PLATFORM(CG)
- " vec4 texColor = texture2D(s_texture, vec2(v_texCoord.x, 1.0 - v_texCoord.y)); \n"
- " gl_FragColor = vec4(texColor.x, texColor.y, texColor.z, texColor.w) * alpha; \n"
-#else
-#error "Need to implement for your platform."
-#endif
- "} \n";
-
- // Fragment shader used for rendering the scrolled root layer quad. It differs
- // from fragmentShaderString in that it doesn't swizzle the colors and doesn't
- // take an alpha value.
char scrollFragmentShaderString[] =
"precision mediump float; \n"
"varying vec2 v_texCoord; \n"
@@ -770,101 +534,67 @@ bool LayerRendererChromium::initializeSharedGLObjects()
" gl_FragColor = vec4(texColor.x, texColor.y, texColor.z, texColor.w); \n"
"} \n";
- // Canvas layers need to be flipped vertically and their colors shouldn't be
- // swizzled.
- char canvasFragmentShaderString[] =
- "precision mediump float; \n"
- "varying vec2 v_texCoord; \n"
- "uniform sampler2D s_texture; \n"
- "uniform float alpha; \n"
- "void main() \n"
- "{ \n"
- " vec4 texColor = texture2D(s_texture, vec2(v_texCoord.x, 1.0 - v_texCoord.y)); \n"
- " gl_FragColor = vec4(texColor.x, texColor.y, texColor.z, texColor.w) * alpha; \n"
- "} \n";
-
- // Shaders for drawing the debug borders around the layers.
- char borderVertexShaderString[] =
- "attribute vec4 a_position; \n"
- "uniform mat4 matrix; \n"
- "void main() \n"
- "{ \n"
- " gl_Position = matrix * a_position; \n"
- "} \n";
- char borderFragmentShaderString[] =
- "precision mediump float; \n"
- "uniform vec4 color; \n"
- "void main() \n"
- "{ \n"
- " gl_FragColor = color; \n"
- "} \n";
-
- GLfloat vertices[] = { -0.5f, 0.5f, 0.0f, // Position 0
- 0.0f, 1.0f, // TexCoord 0
- -0.5f, -0.5f, 0.0f, // Position 1
- 0.0f, 0.0f, // TexCoord 1
- 0.5f, -0.5f, 0.0f, // Position 2
- 1.0f, 0.0f, // TexCoord 2
- 0.5f, 0.5f, 0.0f, // Position 3
- 1.0f, 1.0f // TexCoord 3
- };
- GLushort indices[] = { 0, 1, 2, 0, 2, 3, // The two triangles that make up the layer quad.
- 0, 1, 2, 3}; // A line path for drawing the layer border.
-
- makeContextCurrent();
-
- if (!createLayerShader(ContentLayerProgram, vertexShaderString, fragmentShaderString)) {
- LOG_ERROR("Failed to create shader program for content layers");
- return false;
- }
- LayerChromium::setShaderProgramId(ContentLayerProgram);
-
- if (!createLayerShader(CanvasLayerProgram, vertexShaderString, canvasFragmentShaderString)) {
- LOG_ERROR("Failed to create shader program for Canvas layers");
+ m_scrollShaderProgram = LayerChromium::createShaderProgram(scrollVertexShaderString, scrollFragmentShaderString);
+ if (!m_scrollShaderProgram) {
+ LOG_ERROR("LayerRendererChromium: Failed to create scroll shader program");
+ cleanupSharedObjects();
return false;
}
- CanvasLayerChromium::setShaderProgramId(CanvasLayerProgram);
- if (!createLayerShader(ScrollLayerProgram, vertexShaderString, scrollFragmentShaderString)) {
- LOG_ERROR("Failed to create shader program for scrolling layer");
+ GLC(m_scrollShaderSamplerLocation = glGetUniformLocation(m_scrollShaderProgram, "s_texture"));
+ GLC(m_scrollShaderMatrixLocation = glGetUniformLocation(m_scrollShaderProgram, "matrix"));
+ if (m_scrollShaderSamplerLocation == -1 || m_scrollShaderMatrixLocation == -1) {
+ LOG_ERROR("Failed to initialize scroll shader.");
+ cleanupSharedObjects();
return false;
}
- if (!createLayerShader(DebugBorderProgram, borderVertexShaderString, borderFragmentShaderString)) {
- LOG_ERROR("Failed to create shader program for debug borders");
- return false;
- }
-
- // Specify the attrib location for the position and texCoord and make it the same for all programs to
- // avoid binding re-binding the vertex attributes.
- bindCommonAttribLocations(ContentLayerProgram);
- bindCommonAttribLocations(CanvasLayerProgram);
- bindCommonAttribLocations(DebugBorderProgram);
- bindCommonAttribLocations(ScrollLayerProgram);
-
- // Get the location of the color uniform for the debug border shader program.
- m_borderColorLocation = glGetUniformLocation(m_shaderPrograms[DebugBorderProgram].m_shaderProgramId, "color");
-
- glGenBuffers(3, m_quadVboIds);
- glBindBuffer(GL_ARRAY_BUFFER, m_quadVboIds[Vertices]);
- glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);
- glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_quadVboIds[LayerElements]);
- glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(indices), indices, GL_STATIC_DRAW);
-
// Create a texture object to hold the contents of the root layer.
m_rootLayerTextureId = createLayerTexture();
if (!m_rootLayerTextureId) {
LOG_ERROR("Failed to create texture for root layer");
+ cleanupSharedObjects();
return false;
}
// Turn off filtering for the root layer to avoid blurring from the repeated
// writes and reads to the framebuffer that happen while scrolling.
- glBindTexture(GL_TEXTURE_2D, m_rootLayerTextureId);
- glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
- glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
+ GLC(glBindTexture(GL_TEXTURE_2D, m_rootLayerTextureId));
+ GLC(glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST));
+ GLC(glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST));
+
+ // Get the max texture size supported by the system.
+ GLC(glGetIntegerv(GL_MAX_TEXTURE_SIZE, &m_maxTextureSize));
+
+ m_layerSharedValues = adoptPtr(new LayerChromium::SharedValues());
+ m_contentLayerSharedValues = adoptPtr(new ContentLayerChromium::SharedValues());
+ m_canvasLayerSharedValues = adoptPtr(new CanvasLayerChromium::SharedValues());
+ if (!m_layerSharedValues->initialized() || !m_contentLayerSharedValues->initialized() || !m_canvasLayerSharedValues->initialized()) {
+ cleanupSharedObjects();
+ return false;
+ }
return true;
}
+
+void LayerRendererChromium::cleanupSharedObjects()
+{
+ makeContextCurrent();
+
+ m_layerSharedValues.clear();
+ m_contentLayerSharedValues.clear();
+ m_canvasLayerSharedValues.clear();
+
+ if (m_scrollShaderProgram) {
+ GLC(glDeleteProgram(m_scrollShaderProgram));
+ m_scrollShaderProgram = 0;
+ }
+
+ if (m_rootLayerTextureId) {
+ GLC(glDeleteTextures(1, &m_rootLayerTextureId));
+ m_rootLayerTextureId = 0;
+ }
+}
+
} // namespace WebCore
#endif // USE(ACCELERATED_COMPOSITING)
diff --git a/WebCore/platform/graphics/chromium/LayerRendererChromium.h b/WebCore/platform/graphics/chromium/LayerRendererChromium.h
index e4474b5..24bbe65 100644
--- a/WebCore/platform/graphics/chromium/LayerRendererChromium.h
+++ b/WebCore/platform/graphics/chromium/LayerRendererChromium.h
@@ -34,6 +34,8 @@
#if USE(ACCELERATED_COMPOSITING)
+#include "CanvasLayerChromium.h"
+#include "ContentLayerChromium.h"
#include "IntRect.h"
#include "LayerChromium.h"
#include "SkBitmap.h"
@@ -51,16 +53,6 @@ namespace WebCore {
class GLES2Context;
-class ShaderProgram {
-public:
- ShaderProgram();
-
- unsigned m_shaderProgramId;
- int m_samplerLocation;
- int m_matrixLocation;
- int m_alphaLocation;
-};
-
// Class that handles drawing of composited render layers using GL.
class LayerRendererChromium : public Noncopyable {
public:
@@ -78,73 +70,58 @@ public:
void setNeedsDisplay() { m_needsDisplay = true; }
- // Frees the texture associated with the given layer.
- bool freeLayerTexture(LayerChromium*);
-
bool hardwareCompositing() const { return m_hardwareCompositing; }
void setRootLayerCanvasSize(const IntSize&);
GraphicsContext* rootLayerGraphicsContext() const { return m_rootLayerGraphicsContext.get(); }
-private:
- enum ShaderProgramType { DebugBorderProgram, ScrollLayerProgram, ContentLayerProgram, CanvasLayerProgram, NumShaderProgramTypes };
+ unsigned createLayerTexture();
- void updateLayersRecursive(LayerChromium* layer, const TransformationMatrix& parentMatrix, float opacity, const IntRect& visibleRect);
+ static void debugGLCall(const char* command, const char* file, int line);
- void drawLayer(LayerChromium*);
+ const TransformationMatrix& projectionMatrix() const { return m_projectionMatrix; }
- void drawDebugBorder(LayerChromium*, const TransformationMatrix&);
+ void useShader(unsigned);
- void drawTexturedQuad(const TransformationMatrix& matrix, float width, float height, float opacity);
+ bool checkTextureSize(const IntSize&);
- bool isLayerVisible(LayerChromium*, const TransformationMatrix&, const IntRect& visibleRect);
+ const LayerChromium::SharedValues* layerSharedValues() const { return m_layerSharedValues.get(); }
+ const ContentLayerChromium::SharedValues* contentLayerSharedValues() const { return m_contentLayerSharedValues.get(); }
+ const CanvasLayerChromium::SharedValues* canvasLayerSharedValues() const { return m_canvasLayerSharedValues.get(); }
- bool createLayerShader(ShaderProgramType, const char* vertexShaderSource, const char* fragmentShaderSource);
+private:
+ void updateLayersRecursive(LayerChromium* layer, const TransformationMatrix& parentMatrix, float opacity);
- void useShaderProgram(ShaderProgramType);
+ void drawLayersRecursive(LayerChromium*);
- void bindCommonAttribLocations(ShaderProgramType);
+ void drawLayer(LayerChromium*);
- enum VboIds { Vertices, LayerElements };
+ bool isLayerVisible(LayerChromium*, const TransformationMatrix&, const IntRect& visibleRect);
- // These are here only temporarily and should be removed once we switch over to GGL
bool makeContextCurrent();
- bool initializeSharedGLObjects();
- int getTextureId(LayerChromium*);
- int assignTextureForLayer(LayerChromium*);
-
- ShaderProgram m_shaderPrograms[NumShaderProgramTypes];
+ bool initializeSharedObjects();
+ void cleanupSharedObjects();
unsigned m_rootLayerTextureId;
int m_rootLayerTextureWidth;
int m_rootLayerTextureHeight;
- // Shader uniform and attribute locations.
- const int m_positionLocation;
- const int m_texCoordLocation;
- int m_samplerLocation;
- int m_matrixLocation;
- int m_alphaLocation;
- int m_borderColorLocation;
+ // Scroll shader uniform locations.
+ unsigned m_scrollShaderProgram;
+ int m_scrollShaderSamplerLocation;
+ int m_scrollShaderMatrixLocation;
- unsigned m_quadVboIds[3];
TransformationMatrix m_projectionMatrix;
RefPtr<LayerChromium> m_rootLayer;
- Vector<LayerChromium*> m_layerList;
-
bool m_needsDisplay;
IntPoint m_scrollPosition;
bool m_hardwareCompositing;
- ShaderProgramType m_currentShaderProgramType;
-
- // Map associating layers with textures ids used by the GL compositor.
- typedef HashMap<LayerChromium*, unsigned> TextureIdMap;
- TextureIdMap m_textureIdMap;
+ unsigned int m_currentShader;
#if PLATFORM(SKIA)
OwnPtr<skia::PlatformCanvas> m_rootLayerCanvas;
@@ -158,9 +135,33 @@ private:
IntSize m_rootLayerCanvasSize;
+ IntRect m_visibleRect;
+
+ int m_maxTextureSize;
+
+ // Store values that are shared between instances of each layer type
+ // associated with this instance of the compositor. Since there can be
+ // multiple instances of the compositor running in the same renderer process
+ // we cannot store these values in static variables.
+ OwnPtr<LayerChromium::SharedValues> m_layerSharedValues;
+ OwnPtr<ContentLayerChromium::SharedValues> m_contentLayerSharedValues;
+ OwnPtr<CanvasLayerChromium::SharedValues> m_canvasLayerSharedValues;
+
OwnPtr<GLES2Context> m_gles2Context;
};
+// Setting DEBUG_GL_CALLS to 1 will call glGetError() after almost every GL
+// call made by the compositor. Useful for debugging rendering issues but
+// will significantly degrade performance.
+#define DEBUG_GL_CALLS 0
+
+#if DEBUG_GL_CALLS && !defined ( NDEBUG )
+#define GLC(x) { (x), LayerRendererChromium::debugGLCall(#x, __FILE__, __LINE__); }
+#else
+#define GLC(x) (x)
+#endif
+
+
}
#endif // USE(ACCELERATED_COMPOSITING)
diff --git a/WebCore/platform/graphics/chromium/TilingData.cpp b/WebCore/platform/graphics/chromium/TilingData.cpp
index c52288d..4da242b 100755
--- a/WebCore/platform/graphics/chromium/TilingData.cpp
+++ b/WebCore/platform/graphics/chromium/TilingData.cpp
@@ -117,18 +117,22 @@ int TilingData::tilePositionX(int xIndex) const
{
ASSERT(xIndex >= 0 && xIndex < numTilesX());
- if (!xIndex)
- return 0;
- return tilePositionX(xIndex - 1) + tileSizeX(xIndex - 1);
+ int pos = 0;
+ for (int i = 0; i < xIndex; i++)
+ pos += tileSizeX(i);
+
+ return pos;
}
int TilingData::tilePositionY(int yIndex) const
{
ASSERT(yIndex >= 0 && yIndex < numTilesY());
- if (!yIndex)
- return 0;
- return tilePositionX(yIndex - 1) + tileSizeY(yIndex - 1);
+ int pos = 0;
+ for (int i = 0; i < yIndex; i++)
+ pos += tileSizeY(i);
+
+ return pos;
}
int TilingData::tileSizeX(int xIndex) const
diff --git a/WebCore/platform/graphics/chromium/TransformLayerChromium.cpp b/WebCore/platform/graphics/chromium/VideoFrameChromium.h
index 6427eeb..bbd677e 100644
--- a/WebCore/platform/graphics/chromium/TransformLayerChromium.cpp
+++ b/WebCore/platform/graphics/chromium/VideoFrameChromium.h
@@ -28,23 +28,54 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-#include "config.h"
+#ifndef VideoFrameChromium_h
+#define VideoFrameChromium_h
-#if USE(ACCELERATED_COMPOSITING)
+namespace WebCore {
-#include "TransformLayerChromium.h"
+// A class that represents a video frame in chromium.
+class VideoFrameChromium {
+public:
+ static const unsigned cMaxPlanes;
+ static const unsigned cNumRGBPlanes;
+ static const unsigned cRGBPlane;
+ static const unsigned cNumYUVPlanes;
+ static const unsigned cYPlane;
+ static const unsigned cUPlane;
+ static const unsigned cVPlane;
-namespace WebCore {
+ // These enums must be kept in sync with WebKit::WebVideoFrame.
+ enum Format {
+ Invalid,
+ RGB555,
+ RGB565,
+ RGB24,
+ RGB32,
+ RGBA,
+ YV12,
+ YV16,
+ NV12,
+ Empty,
+ ASCII,
+ };
+
+ enum SurfaceType {
+ TypeSystemMemory,
+ TypeOMXBufferHead,
+ TypeEGLImage,
+ TypeMFBuffer,
+ TypeDirect3DSurface
+ };
-PassRefPtr<TransformLayerChromium> TransformLayerChromium::create(GraphicsLayerChromium* owner)
-{
- return adoptRef(new TransformLayerChromium(owner));
-}
+ virtual SurfaceType surfaceType() const = 0;
+ virtual Format format() const = 0;
+ virtual unsigned width() const = 0;
+ virtual unsigned height() const = 0;
+ virtual unsigned planes() const = 0;
+ virtual int stride(unsigned plane) const = 0;
+ virtual const void* data(unsigned plane) const = 0;
+};
-TransformLayerChromium::TransformLayerChromium(GraphicsLayerChromium* owner)
- : LayerChromium(owner)
-{
-}
+} // namespace WebCore
-}
-#endif // USE(ACCELERATED_COMPOSITING)
+#endif
diff --git a/WebCore/platform/graphics/chromium/TransformLayerChromium.h b/WebCore/platform/graphics/chromium/VideoFrameProvider.h
index 3d5ce94..f0bad08 100644
--- a/WebCore/platform/graphics/chromium/TransformLayerChromium.h
+++ b/WebCore/platform/graphics/chromium/VideoFrameProvider.h
@@ -28,28 +28,28 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
+#ifndef VideoFrameProvider_h
+#define VideoFrameProvider_h
-#ifndef TransformLayerChromium_h
-#define TransformLayerChromium_h
-
-#if USE(ACCELERATED_COMPOSITING)
-
-#include "LayerChromium.h"
+#include "VideoFrameChromium.h"
namespace WebCore {
-// A Layer that doesn't draw any content but simply exists to group and
-// transform its descendants.
-class TransformLayerChromium : public LayerChromium {
+class VideoFrameProvider {
public:
- static PassRefPtr<TransformLayerChromium> create(GraphicsLayerChromium* owner = 0);
- virtual bool drawsContent() { return false; }
-
-private:
- TransformLayerChromium(GraphicsLayerChromium* owner);
+ // This function returns a pointer to a VideoFrameChromium, which is
+ // the WebCore wrapper for a video frame in Chromium. getCurrentFrame()
+ // places a lock on the frame in Chromium. Calls to this method should
+ // always be followed with a call to putCurrentFrame().
+ // The ownership of the object is not transferred to the caller and
+ // the caller should not free the returned object.
+ virtual VideoFrameChromium* getCurrentFrame() = 0;
+ // This function releases the lock on the video frame in chromium. It should
+ // always be called after getCurrentFrame(). Frames passed into this method
+ // should no longer be referenced after the call is made.
+ virtual void putCurrentFrame(VideoFrameChromium*) = 0;
};
-}
-#endif // USE(ACCELERATED_COMPOSITING)
+} // namespace WebCore
#endif
diff --git a/WebCore/platform/graphics/chromium/VideoLayerChromium.cpp b/WebCore/platform/graphics/chromium/VideoLayerChromium.cpp
index 89b6ec1..7ff98b9 100644
--- a/WebCore/platform/graphics/chromium/VideoLayerChromium.cpp
+++ b/WebCore/platform/graphics/chromium/VideoLayerChromium.cpp
@@ -48,23 +48,24 @@
namespace WebCore {
-PassRefPtr<VideoLayerChromium> VideoLayerChromium::create(GraphicsLayerChromium* owner)
+PassRefPtr<VideoLayerChromium> VideoLayerChromium::create(GraphicsLayerChromium* owner,
+ VideoFrameProvider* provider)
{
- return adoptRef(new VideoLayerChromium(owner));
+ return adoptRef(new VideoLayerChromium(owner, provider));
}
-VideoLayerChromium::VideoLayerChromium(GraphicsLayerChromium* owner)
- : LayerChromium(owner)
- , m_allocatedTextureId(0)
+VideoLayerChromium::VideoLayerChromium(GraphicsLayerChromium* owner, VideoFrameProvider* provider)
+ : ContentLayerChromium(owner)
#if PLATFORM(SKIA)
, m_canvas(0)
, m_skiaContext(0)
#endif
, m_graphicsContext(0)
+ , m_provider(provider)
{
}
-void VideoLayerChromium::updateTextureContents(unsigned textureId)
+void VideoLayerChromium::updateContents()
{
RenderLayerBacking* backing = static_cast<RenderLayerBacking*>(m_owner->client());
if (!backing || backing->paintingGoesToWindow())
@@ -109,9 +110,20 @@ void VideoLayerChromium::updateTextureContents(unsigned textureId)
// Bring the canvas into the coordinate system of the paint rect.
m_canvas->translate(static_cast<SkScalar>(-dirtyRect.x()), static_cast<SkScalar>(-dirtyRect.y()));
+ // FIXME: Remove this test when tiled layers are implemented.
+ m_skipsDraw = false;
+ if (!layerRenderer()->checkTextureSize(requiredTextureSize)) {
+ m_skipsDraw = true;
+ return;
+ }
+
+ unsigned textureId = m_contentsTexture;
+ if (!textureId)
+ textureId = layerRenderer()->createLayerTexture();
+
// If the texture id or size changed since last time, then we need to tell GL
// to re-allocate a texture.
- if (m_allocatedTextureId != textureId || requiredTextureSize != m_allocatedTextureSize)
+ if (m_contentsTexture != textureId || requiredTextureSize != m_allocatedTextureSize)
createTextureRect(requiredTextureSize, dirtyRect, textureId);
else
updateTextureRect(dirtyRect, textureId);
@@ -150,7 +162,7 @@ void VideoLayerChromium::createTextureRect(const IntSize& requiredTextureSize, c
ASSERT(bitmapSize == requiredTextureSize);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, requiredTextureSize.width(), requiredTextureSize.height(), 0, GL_RGBA, GL_UNSIGNED_BYTE, pixels);
- m_allocatedTextureId = textureId;
+ m_contentsTexture = textureId;
m_allocatedTextureSize = requiredTextureSize;
updateCompleted();
diff --git a/WebCore/platform/graphics/chromium/VideoLayerChromium.h b/WebCore/platform/graphics/chromium/VideoLayerChromium.h
index 746299f..3507cb2 100644
--- a/WebCore/platform/graphics/chromium/VideoLayerChromium.h
+++ b/WebCore/platform/graphics/chromium/VideoLayerChromium.h
@@ -34,30 +34,31 @@
#if USE(ACCELERATED_COMPOSITING)
-#include "LayerChromium.h"
+#include "ContentLayerChromium.h"
+#include "VideoFrameProvider.h"
namespace WebCore {
// A Layer that contains a Video element.
-class VideoLayerChromium : public LayerChromium {
+class VideoLayerChromium : public ContentLayerChromium {
public:
- static PassRefPtr<VideoLayerChromium> create(GraphicsLayerChromium* owner = 0);
+ static PassRefPtr<VideoLayerChromium> create(GraphicsLayerChromium* owner = 0,
+ VideoFrameProvider* = 0);
virtual bool drawsContent() { return true; }
- virtual void updateTextureContents(unsigned textureId);
+ virtual void updateContents();
private:
- VideoLayerChromium(GraphicsLayerChromium* owner);
+ VideoLayerChromium(GraphicsLayerChromium* owner, VideoFrameProvider*);
void createTextureRect(const IntSize& requiredTextureSize, const IntRect& updateRect, unsigned textureId);
void updateTextureRect(const IntRect& updateRect, unsigned textureId);
void updateCompleted();
- unsigned m_allocatedTextureId;
- IntSize m_allocatedTextureSize;
#if PLATFORM(SKIA)
OwnPtr<skia::PlatformCanvas> m_canvas;
OwnPtr<PlatformContextSkia> m_skiaContext;
#endif
OwnPtr<GraphicsContext> m_graphicsContext;
+ OwnPtr<VideoFrameProvider> m_provider;
};
}
diff --git a/WebCore/platform/graphics/filters/FEComposite.cpp b/WebCore/platform/graphics/filters/FEComposite.cpp
index 0bafc48..d9f00ce 100644
--- a/WebCore/platform/graphics/filters/FEComposite.cpp
+++ b/WebCore/platform/graphics/filters/FEComposite.cpp
@@ -136,7 +136,7 @@ void FEComposite::apply(Filter* filter)
break;
case FECOMPOSITE_OPERATOR_IN:
filterContext->save();
- filterContext->clipToImageBuffer(m_in->resultImage(), calculateDrawingRect(m_in2->scaledSubRegion()));
+ filterContext->clipToImageBuffer(m_in2->resultImage(), calculateDrawingRect(m_in2->scaledSubRegion()));
filterContext->drawImageBuffer(m_in->resultImage(), DeviceColorSpace, calculateDrawingRect(m_in->scaledSubRegion()));
filterContext->restore();
break;
diff --git a/WebCore/platform/graphics/filters/FEGaussianBlur.cpp b/WebCore/platform/graphics/filters/FEGaussianBlur.cpp
index 70465a0..44bb65a 100644
--- a/WebCore/platform/graphics/filters/FEGaussianBlur.cpp
+++ b/WebCore/platform/graphics/filters/FEGaussianBlur.cpp
@@ -200,6 +200,12 @@ TextStream& FEGaussianBlur::externalRepresentation(TextStream& ts, int indent) c
return ts;
}
+float FEGaussianBlur::calculateStdDeviation(float radius)
+{
+ // Blur radius represents 2/3 times the kernel size, the dest pixel is half of the radius applied 3 times
+ return max((radius * 2 / 3.f - 0.5f) / gGaussianKernelFactor, 0.f);
+}
+
} // namespace WebCore
#endif // ENABLE(FILTERS)
diff --git a/WebCore/platform/graphics/filters/FEGaussianBlur.h b/WebCore/platform/graphics/filters/FEGaussianBlur.h
index 4c7c43c..ad5c5a3 100644
--- a/WebCore/platform/graphics/filters/FEGaussianBlur.h
+++ b/WebCore/platform/graphics/filters/FEGaussianBlur.h
@@ -43,6 +43,8 @@ public:
void dump();
TextStream& externalRepresentation(TextStream&, int indent) const;
+ static float calculateStdDeviation(float);
+
private:
FEGaussianBlur(FilterEffect*, const float&, const float&);
static void kernelPosition(int boxBlur, unsigned& std, int& dLeft, int& dRight);
diff --git a/WebCore/platform/graphics/gstreamer/GStreamerGWorld.cpp b/WebCore/platform/graphics/gstreamer/GStreamerGWorld.cpp
index c5022f9..96a639b 100644
--- a/WebCore/platform/graphics/gstreamer/GStreamerGWorld.cpp
+++ b/WebCore/platform/graphics/gstreamer/GStreamerGWorld.cpp
@@ -21,24 +21,178 @@
#include "GStreamerGWorld.h"
-#include "MediaPlayerPrivateGStreamer.h"
+#include "GOwnPtrGStreamer.h"
+
+#include <gst/gst.h>
+#include <gst/interfaces/xoverlay.h>
+
+#if PLATFORM(GTK)
+#include <gtk/gtk.h>
+#ifdef GDK_WINDOWING_X11
+#include <gdk/gdkx.h> // for GDK_WINDOW_XID
+#endif
+#endif
using namespace std;
namespace WebCore {
-PassRefPtr<GStreamerGWorld> GStreamerGWorld::createGWorld(MediaPlayerPrivateGStreamer* player)
+gboolean gstGWorldSyncMessageCallback(GstBus* bus, GstMessage* message, gpointer data)
+{
+ ASSERT(GST_MESSAGE_TYPE(message) == GST_MESSAGE_ELEMENT);
+
+ GStreamerGWorld* gstGWorld = static_cast<GStreamerGWorld*>(data);
+
+ if (gst_structure_has_name(message->structure, "prepare-xwindow-id"))
+ gstGWorld->setWindowOverlay(message);
+ return TRUE;
+}
+
+PassRefPtr<GStreamerGWorld> GStreamerGWorld::createGWorld(GstElement* pipeline)
{
- return adoptRef(new GStreamerGWorld(player));
+ return adoptRef(new GStreamerGWorld(pipeline));
}
-GStreamerGWorld::GStreamerGWorld(MediaPlayerPrivateGStreamer* player)
- : m_player(player)
+GStreamerGWorld::GStreamerGWorld(GstElement* pipeline)
+ : m_pipeline(pipeline)
+ , m_dynamicPadName(0)
{
+ // XOverlay messages need to be handled synchronously.
+ GstBus* bus = gst_pipeline_get_bus(GST_PIPELINE(m_pipeline));
+ gst_bus_set_sync_handler(bus, gst_bus_sync_signal_handler, this);
+ g_signal_connect(bus, "sync-message::element", G_CALLBACK(gstGWorldSyncMessageCallback), this);
+ gst_object_unref(bus);
}
GStreamerGWorld::~GStreamerGWorld()
{
+ exitFullscreen();
+
+ m_pipeline = 0;
+}
+
+bool GStreamerGWorld::enterFullscreen()
+{
+ if (m_dynamicPadName)
+ return false;
+
+ if (!m_videoWindow)
+ m_videoWindow = PlatformVideoWindow::createWindow();
+
+ GstElement* platformVideoSink = gst_element_factory_make("autovideosink", "platformVideoSink");
+ GstElement* colorspace = gst_element_factory_make("ffmpegcolorspace", "colorspace");
+ GstElement* queue = gst_element_factory_make("queue", "queue");
+ GstElement* videoScale = gst_element_factory_make("videoscale", "videoScale");
+
+ // Get video sink bin and the tee inside.
+ GOwnPtr<GstElement> videoSink;
+ g_object_get(m_pipeline, "video-sink", &videoSink.outPtr(), NULL);
+ GstElement* tee = gst_bin_get_by_name(GST_BIN(videoSink.get()), "videoTee");
+
+ // Add and link a queue, ffmpegcolorspace and sink in the bin.
+ gst_bin_add_many(GST_BIN(videoSink.get()), platformVideoSink, videoScale, colorspace, queue, NULL);
+ gst_element_link_many(queue, colorspace, videoScale, platformVideoSink, NULL);
+
+ // Link a new src pad from tee to queue.
+ GstPad* srcPad = gst_element_get_request_pad(tee, "src%d");
+ GstPad* sinkPad = gst_element_get_static_pad(queue, "sink");
+ gst_pad_link(srcPad, sinkPad);
+ gst_object_unref(GST_OBJECT(sinkPad));
+
+ m_dynamicPadName = gst_pad_get_name(srcPad);
+
+ // Roll new elements to pipeline state.
+ gst_element_sync_state_with_parent(queue);
+ gst_element_sync_state_with_parent(colorspace);
+ gst_element_sync_state_with_parent(videoScale);
+ gst_element_sync_state_with_parent(platformVideoSink);
+
+ gst_object_unref(tee);
+
+ // Query the current media segment informations and send them towards
+ // the new tee branch downstream.
+
+ GstQuery* query = gst_query_new_segment(GST_FORMAT_TIME);
+ gboolean queryResult = gst_element_query(m_pipeline, query);
+
+ // See https://bugzilla.gnome.org/show_bug.cgi?id=620490.
+#if GST_CHECK_VERSION(0, 10, 30)
+ if (!queryResult) {
+ gst_query_unref(query);
+ gst_object_unref(GST_OBJECT(srcPad));
+ return true;
+ }
+#endif
+
+ GstFormat format;
+ gint64 position;
+ if (!gst_element_query_position(m_pipeline, &format, &position))
+ position = 0;
+
+ gdouble rate;
+ gint64 startValue, stopValue;
+ gst_query_parse_segment(query, &rate, &format, &startValue, &stopValue);
+
+ GstEvent* event = gst_event_new_new_segment(FALSE, rate, format, startValue, stopValue, position);
+ gst_pad_push_event(srcPad, event);
+
+ gst_query_unref(query);
+ gst_object_unref(GST_OBJECT(srcPad));
+ return true;
+}
+
+void GStreamerGWorld::exitFullscreen()
+{
+ if (!m_dynamicPadName)
+ return;
+
+ // Get video sink bin and the elements to remove.
+ GOwnPtr<GstElement> videoSink;
+ g_object_get(m_pipeline, "video-sink", &videoSink.outPtr(), NULL);
+ GstElement* tee = gst_bin_get_by_name(GST_BIN(videoSink.get()), "videoTee");
+ GstElement* platformVideoSink = gst_bin_get_by_name(GST_BIN(videoSink.get()), "platformVideoSink");
+ GstElement* queue = gst_bin_get_by_name(GST_BIN(videoSink.get()), "queue");
+ GstElement* colorspace = gst_bin_get_by_name(GST_BIN(videoSink.get()), "colorspace");
+ GstElement* videoScale = gst_bin_get_by_name(GST_BIN(videoSink.get()), "videoScale");
+
+ // Get pads to unlink and remove.
+ GstPad* srcPad = gst_element_get_static_pad(tee, m_dynamicPadName);
+ GstPad* sinkPad = gst_element_get_static_pad(queue, "sink");
+
+ // Unlink and release request pad.
+ gst_pad_unlink(srcPad, sinkPad);
+ gst_element_release_request_pad(tee, srcPad);
+ gst_object_unref(GST_OBJECT(srcPad));
+ gst_object_unref(GST_OBJECT(sinkPad));
+
+ // Unlink, remove and cleanup queue, ffmpegcolorspace, videoScale and sink.
+ gst_element_unlink_many(queue, colorspace, videoScale, platformVideoSink, NULL);
+ gst_bin_remove_many(GST_BIN(videoSink.get()), queue, colorspace, videoScale, platformVideoSink, NULL);
+ gst_element_set_state(queue, GST_STATE_NULL);
+ gst_element_set_state(colorspace, GST_STATE_NULL);
+ gst_element_set_state(videoScale, GST_STATE_NULL);
+ gst_element_set_state(platformVideoSink, GST_STATE_NULL);
+ gst_object_unref(queue);
+ gst_object_unref(colorspace);
+ gst_object_unref(videoScale);
+ gst_object_unref(platformVideoSink);
+
+ gst_object_unref(tee);
+ m_dynamicPadName = 0;
+}
+
+void GStreamerGWorld::setWindowOverlay(GstMessage* message)
+{
+ GstObject* sink = GST_MESSAGE_SRC(message);
+
+ if (!GST_IS_X_OVERLAY(sink))
+ return;
+
+ if (g_object_class_find_property(G_OBJECT_GET_CLASS(sink), "force-aspect-ratio"))
+ g_object_set(sink, "force-aspect-ratio", TRUE, NULL);
+
+ if (m_videoWindow)
+ gst_x_overlay_set_xwindow_id(GST_X_OVERLAY(sink), m_videoWindow->videoWindowId());
}
}
diff --git a/WebCore/platform/graphics/gstreamer/GStreamerGWorld.h b/WebCore/platform/graphics/gstreamer/GStreamerGWorld.h
index b626298..659052a 100644
--- a/WebCore/platform/graphics/gstreamer/GStreamerGWorld.h
+++ b/WebCore/platform/graphics/gstreamer/GStreamerGWorld.h
@@ -23,25 +23,43 @@
#if ENABLE(VIDEO)
+#include "PlatformVideoWindow.h"
#include "RefCounted.h"
#include "RefPtr.h"
#include <glib.h>
+typedef struct _GstElement GstElement;
+typedef struct _GstMessage GstMessage;
+typedef struct _GstBus GstBus;
+typedef struct _GstBin GstBin;
namespace WebCore {
class MediaPlayerPrivateGStreamer;
+gboolean gstGWorldSyncMessageCallback(GstBus* bus, GstMessage* message, gpointer data);
class GStreamerGWorld : public RefCounted<GStreamerGWorld> {
+ friend gboolean gstGWorldSyncMessageCallback(GstBus* bus, GstMessage* message, gpointer data);
public:
- static PassRefPtr<GStreamerGWorld> createGWorld(MediaPlayerPrivateGStreamer*);
+ static PassRefPtr<GStreamerGWorld> createGWorld(GstElement*);
~GStreamerGWorld();
+ GstElement* pipeline() const { return m_pipeline; }
+
+ // Returns the full-screen window created
+ bool enterFullscreen();
+ void exitFullscreen();
+
+ void setWindowOverlay(GstMessage* message);
+ PlatformVideoWindow* platformVideoWindow() const { return m_videoWindow.get(); }
+
private:
- GStreamerGWorld(MediaPlayerPrivateGStreamer*);
- MediaPlayerPrivateGStreamer* m_player;
+ GStreamerGWorld(GstElement*);
+ GstElement* m_pipeline;
+ RefPtr<PlatformVideoWindow> m_videoWindow;
+ gchar* m_dynamicPadName;
};
}
diff --git a/WebCore/platform/graphics/gstreamer/MediaPlayerPrivateGStreamer.cpp b/WebCore/platform/graphics/gstreamer/MediaPlayerPrivateGStreamer.cpp
index 7184439..d9d2d97 100644
--- a/WebCore/platform/graphics/gstreamer/MediaPlayerPrivateGStreamer.cpp
+++ b/WebCore/platform/graphics/gstreamer/MediaPlayerPrivateGStreamer.cpp
@@ -54,7 +54,6 @@
#include <GOwnPtr.h>
#include <gst/gst.h>
#include <gst/interfaces/mixer.h>
-#include <gst/interfaces/xoverlay.h>
#include <gst/video/video.h>
#include <limits>
#include <math.h>
@@ -1385,7 +1384,7 @@ void MediaPlayerPrivateGStreamer::createGSTPlayBin()
ASSERT(!m_playBin);
m_playBin = gst_element_factory_make("playbin2", "play");
- m_gstGWorld = GStreamerGWorld::createGWorld(this);
+ m_gstGWorld = GStreamerGWorld::createGWorld(m_playBin);
GstBus* bus = gst_pipeline_get_bus(GST_PIPELINE(m_playBin));
gst_bus_add_signal_watch(bus);
diff --git a/WebCore/platform/graphics/gstreamer/PlatformVideoWindow.h b/WebCore/platform/graphics/gstreamer/PlatformVideoWindow.h
new file mode 100644
index 0000000..83dc5dd
--- /dev/null
+++ b/WebCore/platform/graphics/gstreamer/PlatformVideoWindow.h
@@ -0,0 +1,54 @@
+/*
+ * Copyright (C) 2010 Igalia S.L
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#ifndef PlatformVideoWindow_h
+#define PlatformVideoWindow_h
+
+#if ENABLE(VIDEO)
+
+#include <wtf/PassRefPtr.h>
+#include <wtf/RefCounted.h>
+
+#if PLATFORM(GTK)
+#include <gtk/gtk.h>
+typedef GtkWidget PlatformWindowType;
+#endif
+
+namespace WebCore {
+
+class PlatformVideoWindow : public RefCounted<PlatformVideoWindow> {
+ public:
+ static PassRefPtr<PlatformVideoWindow> createWindow() { return adoptRef(new PlatformVideoWindow()); }
+
+ PlatformVideoWindow();
+ ~PlatformVideoWindow();
+
+ PlatformWindowType* window() const { return m_window; }
+ gulong videoWindowId() const { return m_videoWindowId; }
+
+ private:
+ gulong m_videoWindowId;
+ PlatformWindowType* m_videoWindow;
+ PlatformWindowType* m_window;
+ };
+}
+
+#endif
+
+#endif
diff --git a/WebCore/platform/graphics/gstreamer/PlatformVideoWindowGtk.cpp b/WebCore/platform/graphics/gstreamer/PlatformVideoWindowGtk.cpp
new file mode 100644
index 0000000..185f535
--- /dev/null
+++ b/WebCore/platform/graphics/gstreamer/PlatformVideoWindowGtk.cpp
@@ -0,0 +1,60 @@
+/*
+ * Copyright (C) 2010 Igalia S.L
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#include "config.h"
+#include "PlatformVideoWindow.h"
+
+#ifdef GDK_WINDOWING_X11
+#include <gdk/gdkx.h> // for GDK_WINDOW_XID
+#endif
+
+using namespace WebCore;
+
+PlatformVideoWindow::PlatformVideoWindow()
+{
+ m_window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
+ gtk_widget_set_events(m_window, GDK_POINTER_MOTION_MASK | GDK_KEY_PRESS_MASK | GDK_FOCUS_CHANGE_MASK);
+
+ m_videoWindow = gtk_drawing_area_new();
+ gtk_widget_set_double_buffered(m_videoWindow, FALSE);
+ gtk_container_add(GTK_CONTAINER(m_window), m_videoWindow);
+
+ gtk_widget_realize(m_window);
+
+#ifdef GDK_WINDOWING_X11
+ m_videoWindowId = GDK_WINDOW_XID(gtk_widget_get_window(m_window));
+#endif
+
+}
+
+PlatformVideoWindow::~PlatformVideoWindow()
+{
+ if (m_videoWindow && m_window) {
+ gtk_container_remove(GTK_CONTAINER(m_window), m_videoWindow);
+ gtk_widget_destroy(m_videoWindow);
+ m_videoWindow = 0;
+ }
+
+ if (m_window) {
+ gtk_widget_destroy(m_window);
+ m_window = 0;
+ }
+
+ m_videoWindowId = 0;
+}
diff --git a/WebCore/platform/graphics/gtk/ImageBufferGtk.cpp b/WebCore/platform/graphics/gtk/ImageBufferGtk.cpp
index d0b0274..821cc12 100644
--- a/WebCore/platform/graphics/gtk/ImageBufferGtk.cpp
+++ b/WebCore/platform/graphics/gtk/ImageBufferGtk.cpp
@@ -44,7 +44,7 @@ String ImageBuffer::toDataURL(const String& mimeType, const double* quality) con
if (type != "jpeg" && type != "png" && type != "tiff" && type != "ico" && type != "bmp")
return "data:,";
- GRefPtr<GdkPixbuf> pixbuf = cairoImageSurfaceToGdkPixbuf(m_data.m_surface);
+ PlatformRefPtr<GdkPixbuf> pixbuf = cairoImageSurfaceToGdkPixbuf(m_data.m_surface);
if (!pixbuf)
return "data:,";
diff --git a/WebCore/platform/graphics/mac/FontCustomPlatformData.cpp b/WebCore/platform/graphics/mac/FontCustomPlatformData.cpp
index c591ddc..a600d73 100644
--- a/WebCore/platform/graphics/mac/FontCustomPlatformData.cpp
+++ b/WebCore/platform/graphics/mac/FontCustomPlatformData.cpp
@@ -31,8 +31,10 @@ namespace WebCore {
FontCustomPlatformData::~FontCustomPlatformData()
{
+#if defined(BUILDING_ON_TIGER) || defined(BUILDING_ON_LEOPARD)
if (m_atsContainer)
ATSFontDeactivate(m_atsContainer, NULL, kATSOptionFlagsDefault);
+#endif
CGFontRelease(m_cgFont);
}
diff --git a/WebCore/platform/graphics/mac/FontPlatformDataMac.mm b/WebCore/platform/graphics/mac/FontPlatformDataMac.mm
index 33de3c3..d905b62 100644
--- a/WebCore/platform/graphics/mac/FontPlatformDataMac.mm
+++ b/WebCore/platform/graphics/mac/FontPlatformDataMac.mm
@@ -39,9 +39,10 @@ FontPlatformData::FontPlatformData(NSFont *nsFont, bool syntheticBold, bool synt
, m_isColorBitmapFont(false)
#endif
{
- if (nsFont)
- CFRetain(nsFont);
- m_size = nsFont ? [nsFont pointSize] : 0.0f;
+ ASSERT_ARG(nsFont, nsFont);
+
+ CFRetain(nsFont);
+ m_size = [nsFont pointSize];
#ifndef BUILDING_ON_TIGER
m_cgFont.adoptCF(CTFontCopyGraphicsFont(toCTFontRef(nsFont), 0));
m_atsuFontID = CTFontGetPlatformFont(toCTFontRef(nsFont), 0);
@@ -95,14 +96,17 @@ const FontPlatformData& FontPlatformData::operator=(const FontPlatformData& f)
void FontPlatformData::setFont(NSFont *font)
{
+ ASSERT_ARG(font, font);
+ ASSERT(m_font != reinterpret_cast<NSFont *>(-1));
+
if (m_font == font)
return;
- if (font)
- CFRetain(font);
- if (m_font && m_font != reinterpret_cast<NSFont *>(-1))
+
+ CFRetain(font);
+ if (m_font)
CFRelease(m_font);
m_font = font;
- m_size = font ? [font pointSize] : 0.0f;
+ m_size = [font pointSize];
#ifndef BUILDING_ON_TIGER
m_cgFont.adoptCF(CTFontCopyGraphicsFont(toCTFontRef(font), 0));
m_atsuFontID = CTFontGetPlatformFont(toCTFontRef(font), 0);
diff --git a/WebCore/platform/graphics/mac/GraphicsContext3DMac.mm b/WebCore/platform/graphics/mac/GraphicsContext3DMac.mm
index be1d278..ab4ef4b 100644
--- a/WebCore/platform/graphics/mac/GraphicsContext3DMac.mm
+++ b/WebCore/platform/graphics/mac/GraphicsContext3DMac.mm
@@ -312,6 +312,16 @@ bool GraphicsContext3D::isGLES2Compliant() const
return false;
}
+bool GraphicsContext3D::isGLES2NPOTStrict() const
+{
+ return false;
+}
+
+bool GraphicsContext3D::isErrorGeneratedOnOutOfBoundsAccesses() const
+{
+ return false;
+}
+
void GraphicsContext3D::reshape(int width, int height)
{
if (width == m_currentWidth && height == m_currentHeight || !m_contextObj)
@@ -557,40 +567,16 @@ void GraphicsContext3D::bufferData(unsigned long target, int size, unsigned long
::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())
- return;
-
- ensureContext(m_contextObj);
- ::glBufferData(target, array->byteLength(), array->baseAddress(), usage);
-}
-
-void GraphicsContext3D::bufferSubData(unsigned long target, long offset, ArrayBuffer* array)
+void GraphicsContext3D::bufferData(unsigned long target, int size, const void* data, unsigned long usage)
{
- if (!array || !array->byteLength())
- return;
-
ensureContext(m_contextObj);
- ::glBufferSubData(target, offset, array->byteLength(), array->data());
+ ::glBufferData(target, size, data, usage);
}
-void GraphicsContext3D::bufferSubData(unsigned long target, long offset, ArrayBufferView* array)
+void GraphicsContext3D::bufferSubData(unsigned long target, long offset, int size, const void* data)
{
- if (!array || !array->length())
- return;
-
ensureContext(m_contextObj);
- ::glBufferSubData(target, offset, array->byteLength(), array->baseAddress());
+ ::glBufferSubData(target, offset, size, data);
}
unsigned long GraphicsContext3D::checkFramebufferStatus(unsigned long target)
diff --git a/WebCore/platform/graphics/mac/GraphicsLayerCA.mm b/WebCore/platform/graphics/mac/GraphicsLayerCA.mm
index cb4ca58..315cc00 100644
--- a/WebCore/platform/graphics/mac/GraphicsLayerCA.mm
+++ b/WebCore/platform/graphics/mac/GraphicsLayerCA.mm
@@ -1213,6 +1213,18 @@ void GraphicsLayerCA::updateContentsOpaque()
void GraphicsLayerCA::updateBackfaceVisibility()
{
+ if (m_structuralLayer && structuralLayerPurpose() == StructuralLayerForReplicaFlattening) {
+ [m_structuralLayer.get() setDoubleSided:m_backfaceVisibility];
+
+ if (LayerMap* layerCloneMap = m_structuralLayerClones.get()) {
+ LayerMap::const_iterator end = layerCloneMap->end();
+ for (LayerMap::const_iterator it = layerCloneMap->begin(); it != end; ++it) {
+ CALayer *currLayer = it->second.get();
+ [currLayer setDoubleSided:m_backfaceVisibility];
+ }
+ }
+ }
+
[m_layer.get() setDoubleSided:m_backfaceVisibility];
if (LayerMap* layerCloneMap = m_layerClones.get()) {
@@ -1243,7 +1255,7 @@ void GraphicsLayerCA::ensureStructuralLayer(StructuralLayerPurpose purpose)
// Release the structural layer.
m_structuralLayer = 0;
- // Update the properties of m_layer now that we no loner have a structural layer.
+ // Update the properties of m_layer now that we no longer have a structural layer.
updateLayerPosition();
updateLayerSize();
updateAnchorPoint();
@@ -1294,6 +1306,7 @@ void GraphicsLayerCA::ensureStructuralLayer(StructuralLayerPurpose purpose)
updateAnchorPoint();
updateTransform();
updateChildrenTransform();
+ updateBackfaceVisibility();
// Set properties of m_layer to their default values, since these are expressed on on the structural layer.
CGPoint point = CGPointMake(m_size.width() / 2.0f, m_size.height() / 2.0f);
diff --git a/WebCore/platform/graphics/qt/ContextShadow.cpp b/WebCore/platform/graphics/qt/ContextShadow.cpp
index 0511218..829ca82 100644
--- a/WebCore/platform/graphics/qt/ContextShadow.cpp
+++ b/WebCore/platform/graphics/qt/ContextShadow.cpp
@@ -28,8 +28,80 @@
#include "config.h"
#include "ContextShadow.h"
+#include <QTimerEvent>
+#include <wtf/Noncopyable.h>
+
namespace WebCore {
+// ContextShadow needs a scratch image as the buffer for the blur filter.
+// Instead of creating and destroying the buffer for every operation,
+// we create a buffer which will be automatically purged via a timer.
+
+class ShadowBuffer: public QObject {
+public:
+ ShadowBuffer(QObject* parent = 0);
+
+ QImage* scratchImage(const QSize& size);
+
+ void schedulePurge();
+
+protected:
+ void timerEvent(QTimerEvent* event);
+
+private:
+ QImage image;
+ int timerId;
+};
+
+ShadowBuffer::ShadowBuffer(QObject* parent)
+ : QObject(parent)
+ , timerId(0)
+{
+}
+
+QImage* ShadowBuffer::scratchImage(const QSize& size)
+{
+ int width = size.width();
+ int height = size.height();
+
+ // We do not need to recreate the buffer if the buffer is reasonably
+ // larger than the requested size. However, if the requested size is
+ // much smaller than our buffer, reduce our buffer so that we will not
+ // keep too many allocated pixels for too long.
+ if (!image.isNull() && (image.width() > width) && (image.height() > height))
+ if (((2 * width) > image.width()) && ((2 * height) > image.height())) {
+ image.fill(Qt::transparent);
+ return &image;
+ }
+
+ // Round to the nearest 32 pixels so we do not grow the buffer everytime
+ // there is larger request by 1 pixel.
+ width = (1 + (width >> 5)) << 5;
+ height = (1 + (height >> 5)) << 5;
+
+ image = QImage(width, height, QImage::Format_ARGB32_Premultiplied);
+ image.fill(Qt::transparent);
+ return &image;
+}
+
+void ShadowBuffer::schedulePurge()
+{
+ static const double BufferPurgeDelay = 2; // seconds
+ killTimer(timerId);
+ timerId = startTimer(BufferPurgeDelay * 1000);
+}
+
+void ShadowBuffer::timerEvent(QTimerEvent* event)
+{
+ if (event->timerId() == timerId) {
+ killTimer(timerId);
+ image = QImage();
+ }
+ QObject::timerEvent(event);
+}
+
+Q_GLOBAL_STATIC(ShadowBuffer, scratchShadowBuffer)
+
ContextShadow::ContextShadow()
: type(NoShadow)
, blurRadius(0)
@@ -203,54 +275,66 @@ static void shadowBlur(QImage& image, int radius, const QColor& shadowColor)
p.end();
}
-void ContextShadow::drawShadowRect(QPainter* p, const QRectF& rect)
+QPainter* ContextShadow::beginShadowLayer(QPainter* p, const QRectF &rect)
{
- if (type == NoShadow)
- return;
-
- if (type == BlurShadow) {
- QRectF shadowRect = rect.translated(offset);
-
- // We expand the area by the blur radius * 2 to give extra space
- // for the blur transition.
- int extra = blurRadius * 2;
- QRectF bufferRect = shadowRect.adjusted(-extra, -extra, extra, extra);
- QRect alignedBufferRect = bufferRect.toAlignedRect();
-
- QRect clipRect;
- if (p->hasClipping())
- clipRect = p->clipRegion().boundingRect();
- else
- clipRect = p->transform().inverted().mapRect(p->window());
-
- if (!clipRect.contains(alignedBufferRect)) {
+ // We expand the area by the blur radius * 2 to give extra space
+ // for the blur transition.
+ int extra = (type == BlurShadow) ? blurRadius * 2 : 0;
+
+ QRectF shadowRect = rect.translated(offset);
+ QRectF bufferRect = shadowRect.adjusted(-extra, -extra, extra, extra);
+ m_layerRect = bufferRect.toAlignedRect();
+
+ QRect clipRect;
+ if (p->hasClipping())
+#if QT_VERSION >= QT_VERSION_CHECK(4, 8, 0)
+ clipRect = p->clipBoundingRect();
+#else
+ clipRect = p->clipRegion().boundingRect();
+#endif
+ else
+ clipRect = p->transform().inverted().mapRect(p->window());
+
+ if (!clipRect.contains(m_layerRect)) {
+
+ // No need to have the buffer larger than the clip.
+ m_layerRect = m_layerRect.intersected(clipRect);
+ if (m_layerRect.isEmpty())
+ return 0;
+
+ // We adjust again because the pixels at the borders are still
+ // potentially affected by the pixels outside the buffer.
+ if (type == BlurShadow)
+ m_layerRect.adjust(-extra, -extra, extra, extra);
+ }
- // No need to have the buffer larger that the clip.
- alignedBufferRect = alignedBufferRect.intersected(clipRect);
- if (alignedBufferRect.isEmpty())
- return;
+ ShadowBuffer* shadowBuffer = scratchShadowBuffer();
+ QImage* shadowImage = shadowBuffer->scratchImage(m_layerRect.size());
+ m_layerImage = QImage(*shadowImage);
- // We adjust again because the pixels at the borders are still
- // potentially affected by the pixels outside the buffer.
- alignedBufferRect.adjust(-extra, -extra, extra, extra);
- }
+ m_layerPainter = new QPainter;
+ m_layerPainter->begin(&m_layerImage);
+ m_layerPainter->setFont(p->font());
+ m_layerPainter->translate(offset);
- QImage shadowImage(alignedBufferRect.size(), QImage::Format_ARGB32_Premultiplied);
- shadowImage.fill(Qt::transparent);
- QPainter shadowPainter(&shadowImage);
+ // The origin is now the top left corner of the scratch image.
+ m_layerPainter->translate(-m_layerRect.topLeft());
- shadowPainter.fillRect(shadowRect.translated(-alignedBufferRect.topLeft()), color);
- shadowPainter.end();
+ return m_layerPainter;
+}
- shadowBlur(shadowImage, blurRadius, color);
+void ContextShadow::endShadowLayer(QPainter* p)
+{
+ m_layerPainter->end();
+ delete m_layerPainter;
+ m_layerPainter = 0;
- p->drawImage(alignedBufferRect.topLeft(), shadowImage);
+ if (type == BlurShadow)
+ shadowBlur(m_layerImage, blurRadius, color);
- return;
- }
+ p->drawImage(m_layerRect.topLeft(), m_layerImage);
- p->fillRect(rect.translated(offset), color);
+ scratchShadowBuffer()->schedulePurge();
}
-
}
diff --git a/WebCore/platform/graphics/qt/ContextShadow.h b/WebCore/platform/graphics/qt/ContextShadow.h
index e114ebc..7140340 100644
--- a/WebCore/platform/graphics/qt/ContextShadow.h
+++ b/WebCore/platform/graphics/qt/ContextShadow.h
@@ -58,12 +58,35 @@ public:
void clear();
- // Draws the shadow for colored rectangle (can't be filled with pattern
- // or gradient) according to the shadow parameters.
- // Note: 'rect' specifies the rectangle which casts the shadow,
- // NOT the bounding box of the shadow.
- void drawShadowRect(QPainter* p, const QRectF& rect);
+ // The pair beginShadowLayer and endShadowLayer creates a temporary image
+ // where the caller can draw onto, using the returned QPainter. This
+ // QPainter instance must be used only to draw between the call to
+ // beginShadowLayer and endShadowLayer.
+ //
+ // Note: multiple/nested shadow layer is NOT allowed.
+ //
+ // The current clip region will be used to optimize the size of the
+ // temporary image. Thus, the original painter should not change any
+ // clipping until endShadowLayer.
+ // If the shadow will be completely outside the clipping region,
+ // beginShadowLayer will return 0.
+ //
+ // The returned QPainter will have the transformation matrix and clipping
+ // properly initialized to start doing the painting (no need to account
+ // for the shadow offset), however it will not have the same render hints,
+ // pen, brush, etc as the passed QPainter. This is intentional, usually
+ // shadow has different properties than the shape which casts the shadow.
+ //
+ // Once endShadowLayer is called, the temporary image will be drawn
+ // with the original painter. If blur radius is specified, the shadow
+ // will be filtered first.
+ QPainter* beginShadowLayer(QPainter* p, const QRectF& rect);
+ void endShadowLayer(QPainter* p);
+private:
+ QRect m_layerRect;
+ QImage m_layerImage;
+ QPainter* m_layerPainter;
};
} // namespace WebCore
diff --git a/WebCore/platform/graphics/qt/FontQt.cpp b/WebCore/platform/graphics/qt/FontQt.cpp
index 59320cb..2b246de 100644
--- a/WebCore/platform/graphics/qt/FontQt.cpp
+++ b/WebCore/platform/graphics/qt/FontQt.cpp
@@ -23,6 +23,7 @@
#include "Font.h"
#include "AffineTransform.h"
+#include "ContextShadow.h"
#include "FontDescription.h"
#include "FontFallbackList.h"
#include "FontSelector.h"
@@ -108,12 +109,6 @@ static void drawTextCommon(GraphicsContext* ctx, const TextRun& run, const Float
QString string = fromRawDataWithoutRef(sanitized);
QPointF pt(point.x(), point.y());
- // text shadow
- FloatSize shadowSize;
- float shadowBlur;
- Color shadowColor;
- bool hasShadow = ctx->textDrawingMode() == cTextFill && ctx->getShadow(shadowSize, shadowBlur, shadowColor);
-
if (from > 0 || to < run.length()) {
if (isComplexText) {
QTextLayout layout(string, font);
@@ -125,32 +120,46 @@ static void drawTextCommon(GraphicsContext* ctx, const TextRun& run, const Float
QFontMetrics fm(font);
int ascent = fm.ascent();
- QRectF clip(point.x() + x1, point.y() - ascent, x2 - x1, fm.height());
+ QRectF boundingRect(point.x() + x1, point.y() - ascent, x2 - x1, fm.height());
+ QRectF clip = boundingRect;
+
+ ContextShadow* ctxShadow = ctx->contextShadow();
- if (hasShadow) {
- // TODO: when blur support is added, the clip will need to account
- // for the blur radius
+ if (ctxShadow->type != ContextShadow::NoShadow) {
qreal dx1 = 0, dx2 = 0, dy1 = 0, dy2 = 0;
- if (shadowSize.width() > 0)
- dx2 = shadowSize.width();
+ if (ctxShadow->offset.x() > 0)
+ dx2 = ctxShadow->offset.x();
else
- dx1 = -shadowSize.width();
- if (shadowSize.height() > 0)
- dy2 = shadowSize.height();
+ dx1 = -ctxShadow->offset.x();
+ if (ctxShadow->offset.y() > 0)
+ dy2 = ctxShadow->offset.y();
else
- dy1 = -shadowSize.height();
+ dy1 = -ctxShadow->offset.y();
// expand the clip rect to include the text shadow as well
clip.adjust(dx1, dx2, dy1, dy2);
+ clip.adjust(-ctxShadow->blurRadius, -ctxShadow->blurRadius, ctxShadow->blurRadius, ctxShadow->blurRadius);
}
p->save();
p->setClipRect(clip.toRect(), Qt::IntersectClip);
pt.setY(pt.y() - ascent);
- if (hasShadow) {
- p->save();
- p->setPen(QColor(shadowColor));
- p->translate(shadowSize.width(), shadowSize.height());
- line.draw(p, pt);
- p->restore();
+
+ if (ctxShadow->type != ContextShadow::NoShadow) {
+ ContextShadow* ctxShadow = ctx->contextShadow();
+ if (ctxShadow->type != ContextShadow::BlurShadow) {
+ p->save();
+ p->setPen(ctxShadow->color);
+ p->translate(ctxShadow->offset);
+ line.draw(p, pt);
+ p->restore();
+ } else {
+ QPainter* shadowPainter = ctxShadow->beginShadowLayer(p, boundingRect);
+ if (shadowPainter) {
+ // Since it will be blurred anyway, we don't care about render hints.
+ shadowPainter->setPen(ctxShadow->color);
+ line.draw(shadowPainter, pt);
+ ctxShadow->endShadowLayer(p);
+ }
+ }
}
p->setPen(textFillPen);
line.draw(p, pt);
@@ -169,16 +178,29 @@ static void drawTextCommon(GraphicsContext* ctx, const TextRun& run, const Float
int flags = run.rtl() ? Qt::TextForceRightToLeft : Qt::TextForceLeftToRight;
#if QT_VERSION >= QT_VERSION_CHECK(4, 7, 0)
// See QWebPagePrivate::QWebPagePrivate() where the default path is set to Complex for Qt 4.6 and earlier.
- if (!isComplexText)
+ if (!isComplexText && !(ctx->textDrawingMode() & cTextStroke))
flags |= Qt::TextBypassShaping;
#endif
- if (hasShadow) {
- // TODO: text shadow blur support
- p->save();
- p->setPen(QColor(shadowColor));
- p->translate(shadowSize.width(), shadowSize.height());
- p->drawText(pt, string, flags, run.padding());
- p->restore();
+ if (ctx->contextShadow()->type != ContextShadow::NoShadow) {
+ ContextShadow* ctxShadow = ctx->contextShadow();
+ if (ctxShadow->type != ContextShadow::BlurShadow) {
+ p->save();
+ p->setPen(ctxShadow->color);
+ p->translate(ctxShadow->offset);
+ p->drawText(pt, string, flags, run.padding());
+ p->restore();
+ } else {
+ QFontMetrics fm(font);
+ QRectF boundingRect(point.x(), point.y() - fm.ascent(), fm.width(string), fm.height());
+ QPainter* shadowPainter = ctxShadow->beginShadowLayer(p, boundingRect);
+ if (shadowPainter) {
+ // Since it will be blurred anyway, we don't care about render hints.
+ shadowPainter->setFont(p->font());
+ shadowPainter->setPen(ctxShadow->color);
+ shadowPainter->drawText(pt, string, flags, run.padding());
+ ctxShadow->endShadowLayer(p);
+ }
+ }
}
if (ctx->textDrawingMode() & cTextStroke) {
QPainterPath path;
diff --git a/WebCore/platform/graphics/qt/GradientQt.cpp b/WebCore/platform/graphics/qt/GradientQt.cpp
index 1f05a15..72bb009 100644
--- a/WebCore/platform/graphics/qt/GradientQt.cpp
+++ b/WebCore/platform/graphics/qt/GradientQt.cpp
@@ -46,8 +46,15 @@ QGradient* Gradient::platformGradient()
if (m_gradient)
return m_gradient;
+ bool reversed = m_r0 > m_r1;
+
+ qreal innerRadius = reversed ? m_r1 : m_r0;
+ qreal outerRadius = reversed ? m_r0 : m_r1;
+ QPointF center = reversed ? m_p0 : m_p1;
+ QPointF focalPoint = reversed ? m_p1 : m_p0;
+
if (m_radial)
- m_gradient = new QRadialGradient(m_p1.x(), m_p1.y(), m_r1, m_p0.x(), m_p0.y());
+ m_gradient = new QRadialGradient(center, outerRadius, focalPoint);
else
m_gradient = new QLinearGradient(m_p0.x(), m_p0.y(), m_p1.x(), m_p1.y());
@@ -65,9 +72,19 @@ QGradient* Gradient::platformGradient()
lastStop = stopIterator->stop + lastStopDiff;
else
lastStop = stopIterator->stop;
- if (m_radial && m_r0)
- lastStop = m_r0 / m_r1 + lastStop * (1.0f - m_r0 / m_r1);
- m_gradient->setColorAt(qMin(lastStop, qreal(1.0f)), stopColor);
+
+ if (m_radial && !qFuzzyCompare(1 + outerRadius, qreal(1))) {
+ lastStop = lastStop * (1.0f - innerRadius / outerRadius);
+ if (!reversed)
+ lastStop += innerRadius / outerRadius;
+ }
+
+ qreal stopPosition = qMin(lastStop, qreal(1.0f));
+
+ if (m_radial && reversed)
+ stopPosition = 1 - stopPosition;
+
+ m_gradient->setColorAt(stopPosition, stopColor);
// Keep the lastStop as orginal value, since the following stopColor depend it
lastStop = stopIterator->stop;
++stopIterator;
diff --git a/WebCore/platform/graphics/qt/GraphicsContext3DQt.cpp b/WebCore/platform/graphics/qt/GraphicsContext3DQt.cpp
index d5e7b3f..7918378 100644
--- a/WebCore/platform/graphics/qt/GraphicsContext3DQt.cpp
+++ b/WebCore/platform/graphics/qt/GraphicsContext3DQt.cpp
@@ -20,18 +20,14 @@
#include "GraphicsContext3D.h"
-#include "ArrayBufferView.h"
#include "WebGLObject.h"
#include "CanvasRenderingContext.h"
-#include "Float32Array.h"
#include "GraphicsContext.h"
#include "HTMLCanvasElement.h"
#include "HostWindow.h"
#include "ImageBuffer.h"
-#include "Int32Array.h"
#include "NotImplemented.h"
#include "QWebPageClient.h"
-#include "Uint8Array.h"
#include <QAbstractScrollArea>
#include <QGLContext>
#include <wtf/UnusedParam.h>
@@ -89,6 +85,7 @@ typedef void (APIENTRY* glGenFramebuffersType) (GLsizei, GLuint*);
typedef void (APIENTRY* glGenRenderbuffersType) (GLsizei, GLuint*);
typedef void (APIENTRY* glGetActiveAttribType) (GLuint, GLuint, GLsizei, GLsizei*, GLint*, GLenum*, GLchar*);
typedef void (APIENTRY* glGetActiveUniformType) (GLuint, GLuint, GLsizei, GLsizei*, GLint*, GLenum*, GLchar*);
+typedef void (APIENTRY* glGetAttachedShadersType) (GLuint, GLsizei, GLsizei*, GLuint*);
typedef GLint (APIENTRY* glGetAttribLocationType) (GLuint, const char*);
typedef void (APIENTRY* glGetBufferParameterivType) (GLenum, GLenum, GLint*);
typedef void (APIENTRY* glGetFramebufferAttachmentParameterivType) (GLenum, GLenum, GLenum, GLint* params);
@@ -187,6 +184,7 @@ public:
glGenRenderbuffersType genRenderbuffers;
glGetActiveAttribType getActiveAttrib;
glGetActiveUniformType getActiveUniform;
+ glGetAttachedShadersType getAttachedShaders;
glGetAttribLocationType getAttribLocation;
glGetBufferParameterivType getBufferParameteriv;
glGetFramebufferAttachmentParameterivType getFramebufferAttachmentParameteriv;
@@ -276,6 +274,18 @@ bool GraphicsContext3D::isGLES2Compliant() const
#endif
}
+// Even with underlying GLES2 driver, the below flags should still be set to
+// false if extentions exist (and they almost always do).
+bool GraphicsContext3D::isGLES2NPOTStrict() const
+{
+ return false;
+}
+
+bool GraphicsContext3D::isErrorGeneratedOnOutOfBoundsAccesses() const
+{
+ return false;
+}
+
GraphicsContext3DInternal::GraphicsContext3DInternal(GraphicsContext3D::Attributes attrs, HostWindow* hostWindow)
: m_attrs(attrs)
@@ -349,6 +359,7 @@ GraphicsContext3DInternal::GraphicsContext3DInternal(GraphicsContext3D::Attribut
genRenderbuffers = GET_PROC_ADDRESS(glGenRenderbuffers);
getActiveAttrib = GET_PROC_ADDRESS(glGetActiveAttrib);
getActiveUniform = GET_PROC_ADDRESS(glGetActiveUniform);
+ getAttachedShaders = GET_PROC_ADDRESS(glGetAttachedShaders);
getAttribLocation = GET_PROC_ADDRESS(glGetAttribLocation);
getBufferParameteriv = GET_PROC_ADDRESS(glGetBufferParameteriv);
getFramebufferAttachmentParameteriv = GET_PROC_ADDRESS(glGetFramebufferAttachmentParameteriv);
@@ -582,7 +593,7 @@ void GraphicsContext3D::activeTexture(unsigned long texture)
m_internal->activeTexture(texture);
}
-void GraphicsContext3D::attachShader(PlatformGLObject program, PlatformGLObject shader)
+void GraphicsContext3D::attachShader(Platform3DObject program, Platform3DObject shader)
{
ASSERT(program);
ASSERT(shader);
@@ -590,33 +601,44 @@ void GraphicsContext3D::attachShader(PlatformGLObject program, PlatformGLObject
m_internal->attachShader((GLuint) program, (GLuint) shader);
}
-void GraphicsContext3D::bindAttribLocation(PlatformGLObject program, unsigned long index, const String& name)
+void GraphicsContext3D::getAttachedShaders(Platform3DObject program, int maxCount, int* count, unsigned int* shaders)
+{
+ if (!program) {
+ synthesizeGLError(INVALID_VALUE);
+ return;
+ }
+
+ m_internal->m_glWidget->makeCurrent();
+ getAttachedShaders((GLuint) program, maxCount, count, shaders);
+}
+
+void GraphicsContext3D::bindAttribLocation(Platform3DObject program, unsigned long index, const String& name)
{
ASSERT(program);
m_internal->m_glWidget->makeCurrent();
m_internal->bindAttribLocation((GLuint) program, index, name.utf8().data());
}
-void GraphicsContext3D::bindBuffer(unsigned long target, PlatformGLObject buffer)
+void GraphicsContext3D::bindBuffer(unsigned long target, Platform3DObject buffer)
{
m_internal->m_glWidget->makeCurrent();
- m_internal->bindBuffer(target, (GLuint) buffer->object());
+ m_internal->bindBuffer(target, (GLuint) buffer);
}
-void GraphicsContext3D::bindFramebuffer(unsigned long target, PlatformGLObject buffer)
+void GraphicsContext3D::bindFramebuffer(unsigned long target, Platform3DObject buffer)
{
m_internal->m_glWidget->makeCurrent();
m_internal->m_currentFbo = buffer ? (GLuint) buffer : m_internal->m_mainFbo;
m_internal->bindFramebuffer(target, m_internal->m_currentFbo);
}
-void GraphicsContext3D::bindRenderbuffer(unsigned long target, PlatformGLObject renderbuffer)
+void GraphicsContext3D::bindRenderbuffer(unsigned long target, Platform3DObject renderbuffer)
{
m_internal->m_glWidget->makeCurrent();
m_internal->bindRenderbuffer(target, (GLuint) renderbuffer);
}
-void GraphicsContext3D::bindTexture(unsigned long target, PlatformGLObject texture)
+void GraphicsContext3D::bindTexture(unsigned long target, Platform3DObject texture)
{
m_internal->m_glWidget->makeCurrent();
glBindTexture(target, (GLuint) texture);
@@ -658,22 +680,16 @@ void GraphicsContext3D::bufferData(unsigned long target, int size, unsigned long
m_internal->bufferData(target, size, /* data */ 0, usage);
}
-void GraphicsContext3D::bufferData(unsigned long target, ArrayBufferView* array, unsigned long usage)
+void GraphicsContext3D::bufferData(unsigned long target, int size, const void* data, unsigned long usage)
{
- if (!array || !array->length())
- return;
-
m_internal->m_glWidget->makeCurrent();
- m_internal->bufferData(target, array->byteLength(), array->baseAddress(), usage);
+ m_internal->bufferData(target, size, data, usage);
}
-void GraphicsContext3D::bufferSubData(unsigned long target, long offset, ArrayBufferView* array)
+void GraphicsContext3D::bufferSubData(unsigned long target, long offset, int size, const void* data)
{
- if (!array || !array->length())
- return;
-
m_internal->m_glWidget->makeCurrent();
- m_internal->bufferSubData(target, offset, array->byteLength(), array->baseAddress());
+ m_internal->bufferSubData(target, offset, size, data);
}
unsigned long GraphicsContext3D::checkFramebufferStatus(unsigned long target)
@@ -716,7 +732,7 @@ void GraphicsContext3D::colorMask(bool red, bool green, bool blue, bool alpha)
glColorMask(red, green, blue, alpha);
}
-void GraphicsContext3D::compileShader(PlatformGLObject shader)
+void GraphicsContext3D::compileShader(Platform3DObject shader)
{
ASSERT(shader);
m_internal->m_glWidget->makeCurrent();
@@ -763,7 +779,7 @@ void GraphicsContext3D::depthRange(double zNear, double zFar)
#endif
}
-void GraphicsContext3D::detachShader(PlatformGLObject program, PlatformGLObject shader)
+void GraphicsContext3D::detachShader(Platform3DObject program, Platform3DObject shader)
{
ASSERT(program);
ASSERT(shader);
@@ -819,13 +835,13 @@ void GraphicsContext3D::flush()
glFlush();
}
-void GraphicsContext3D::framebufferRenderbuffer(unsigned long target, unsigned long attachment, unsigned long renderbuffertarget, PlatformGLObject buffer)
+void GraphicsContext3D::framebufferRenderbuffer(unsigned long target, unsigned long attachment, unsigned long renderbuffertarget, Platform3DObject buffer)
{
m_internal->m_glWidget->makeCurrent();
m_internal->framebufferRenderbuffer(target, attachment, renderbuffertarget, (GLuint) buffer);
}
-void GraphicsContext3D::framebufferTexture2D(unsigned long target, unsigned long attachment, unsigned long textarget, PlatformGLObject texture, long level)
+void GraphicsContext3D::framebufferTexture2D(unsigned long target, unsigned long attachment, unsigned long textarget, Platform3DObject texture, long level)
{
m_internal->m_glWidget->makeCurrent();
m_internal->framebufferTexture2D(target, attachment, textarget, (GLuint) texture, level);
@@ -843,7 +859,7 @@ void GraphicsContext3D::generateMipmap(unsigned long target)
m_internal->generateMipmap(target);
}
-bool GraphicsContext3D::getActiveAttrib(PlatformGLObject program, unsigned long index, ActiveInfo& info)
+bool GraphicsContext3D::getActiveAttrib(Platform3DObject program, unsigned long index, ActiveInfo& info)
{
if (!program) {
synthesizeGLError(INVALID_VALUE);
@@ -875,7 +891,7 @@ bool GraphicsContext3D::getActiveAttrib(PlatformGLObject program, unsigned long
return true;
}
-bool GraphicsContext3D::getActiveUniform(PlatformGLObject program, unsigned long index, ActiveInfo& info)
+bool GraphicsContext3D::getActiveUniform(Platform3DObject program, unsigned long index, ActiveInfo& info)
{
if (!program) {
synthesizeGLError(INVALID_VALUE);
@@ -907,7 +923,7 @@ bool GraphicsContext3D::getActiveUniform(PlatformGLObject program, unsigned long
return true;
}
-int GraphicsContext3D::getAttribLocation(PlatformGLObject program, const String& name)
+int GraphicsContext3D::getAttribLocation(Platform3DObject program, const String& name)
{
if (!program)
return -1;
@@ -946,7 +962,7 @@ void GraphicsContext3D::hint(unsigned long target, unsigned long mode)
glHint(target, mode);
}
-bool GraphicsContext3D::isBuffer(PlatformGLObject buffer)
+bool GraphicsContext3D::isBuffer(Platform3DObject buffer)
{
if (!buffer)
return false;
@@ -961,7 +977,7 @@ bool GraphicsContext3D::isEnabled(unsigned long cap)
return glIsEnabled(cap);
}
-bool GraphicsContext3D::isFramebuffer(PlatformGLObject framebuffer)
+bool GraphicsContext3D::isFramebuffer(Platform3DObject framebuffer)
{
if (!framebuffer)
return false;
@@ -970,7 +986,7 @@ bool GraphicsContext3D::isFramebuffer(PlatformGLObject framebuffer)
return m_internal->isFramebuffer((GLuint) framebuffer);
}
-bool GraphicsContext3D::isProgram(PlatformGLObject program)
+bool GraphicsContext3D::isProgram(Platform3DObject program)
{
if (!program)
return false;
@@ -979,7 +995,7 @@ bool GraphicsContext3D::isProgram(PlatformGLObject program)
return m_internal->isProgram((GLuint) program);
}
-bool GraphicsContext3D::isRenderbuffer(PlatformGLObject renderbuffer)
+bool GraphicsContext3D::isRenderbuffer(Platform3DObject renderbuffer)
{
if (!renderbuffer)
return false;
@@ -988,7 +1004,7 @@ bool GraphicsContext3D::isRenderbuffer(PlatformGLObject renderbuffer)
return m_internal->isRenderbuffer((GLuint) renderbuffer);
}
-bool GraphicsContext3D::isShader(PlatformGLObject shader)
+bool GraphicsContext3D::isShader(Platform3DObject shader)
{
if (!shader)
return false;
@@ -997,7 +1013,7 @@ bool GraphicsContext3D::isShader(PlatformGLObject shader)
return m_internal->isShader((GLuint) shader);
}
-bool GraphicsContext3D::isTexture(PlatformGLObject texture)
+bool GraphicsContext3D::isTexture(Platform3DObject texture)
{
if (!texture)
return false;
@@ -1012,7 +1028,7 @@ void GraphicsContext3D::lineWidth(double width)
glLineWidth(static_cast<float>(width));
}
-void GraphicsContext3D::linkProgram(PlatformGLObject program)
+void GraphicsContext3D::linkProgram(Platform3DObject program)
{
ASSERT(program);
m_internal->m_glWidget->makeCurrent();
@@ -1065,7 +1081,7 @@ void GraphicsContext3D::scissor(long x, long y, unsigned long width, unsigned lo
glScissor(x, y, width, height);
}
-void GraphicsContext3D::shaderSource(PlatformGLObject shader, const String& source)
+void GraphicsContext3D::shaderSource(Platform3DObject shader, const String& source)
{
ASSERT(shader);
@@ -1247,7 +1263,7 @@ void GraphicsContext3D::uniformMatrix4fv(long location, bool transpose, float* a
m_internal->uniformMatrix4fv(location, size, transpose, array);
}
-void GraphicsContext3D::useProgram(PlatformGLObject program)
+void GraphicsContext3D::useProgram(Platform3DObject program)
{
ASSERT(program);
@@ -1255,7 +1271,7 @@ void GraphicsContext3D::useProgram(PlatformGLObject program)
m_internal->useProgram((GLuint) program);
}
-void GraphicsContext3D::validateProgram(PlatformGLObject program)
+void GraphicsContext3D::validateProgram(Platform3DObject program)
{
ASSERT(program);
@@ -1353,13 +1369,13 @@ void GraphicsContext3D::getIntegerv(unsigned long paramName, int* value)
glGetIntegerv(paramName, value);
}
-void GraphicsContext3D::getProgramiv(PlatformGLObject program, unsigned long paramName, int* value)
+void GraphicsContext3D::getProgramiv(Platform3DObject program, unsigned long paramName, int* value)
{
m_internal->m_glWidget->makeCurrent();
m_internal->getProgramiv((GLuint) program, paramName, value);
}
-String GraphicsContext3D::getProgramInfoLog(PlatformGLObject program)
+String GraphicsContext3D::getProgramInfoLog(Platform3DObject program)
{
m_internal->m_glWidget->makeCurrent();
@@ -1386,14 +1402,14 @@ void GraphicsContext3D::getRenderbufferParameteriv(unsigned long target, unsigne
m_internal->getRenderbufferParameteriv(target, paramName, value);
}
-void GraphicsContext3D::getShaderiv(PlatformGLObject shader, unsigned long paramName, int* value)
+void GraphicsContext3D::getShaderiv(Platform3DObject shader, unsigned long paramName, int* value)
{
ASSERT(shader);
m_internal->m_glWidget->makeCurrent();
m_internal->getShaderiv((GLuint) shader, paramName, value);
}
-String GraphicsContext3D::getShaderInfoLog(PlatformGLObject shader)
+String GraphicsContext3D::getShaderInfoLog(Platform3DObject shader)
{
m_internal->m_glWidget->makeCurrent();
@@ -1413,7 +1429,7 @@ String GraphicsContext3D::getShaderInfoLog(PlatformGLObject shader)
return result;
}
-String GraphicsContext3D::getShaderSource(PlatformGLObject shader)
+String GraphicsContext3D::getShaderSource(Platform3DObject shader)
{
m_internal->m_glWidget->makeCurrent();
@@ -1445,19 +1461,19 @@ void GraphicsContext3D::getTexParameteriv(unsigned long target, unsigned long pa
glGetTexParameteriv(target, paramName, value);
}
-void GraphicsContext3D::getUniformfv(PlatformGLObject program, long location, float* value)
+void GraphicsContext3D::getUniformfv(Platform3DObject program, long location, float* value)
{
m_internal->m_glWidget->makeCurrent();
m_internal->getUniformfv((GLuint) program, location, value);
}
-void GraphicsContext3D::getUniformiv(PlatformGLObject program, long location, int* value)
+void GraphicsContext3D::getUniformiv(Platform3DObject program, long location, int* value)
{
m_internal->m_glWidget->makeCurrent();
m_internal->getUniformiv((GLuint) program, location, value);
}
-long GraphicsContext3D::getUniformLocation(PlatformGLObject program, const String& name)
+long GraphicsContext3D::getUniformLocation(Platform3DObject program, const String& name)
{
ASSERT(program);
@@ -1621,7 +1637,7 @@ bool GraphicsContext3D::getImageData(Image* image,
return false;
AlphaOp neededAlphaOp = kAlphaDoNothing;
- if (!premultiplyAlpha && *hasAlphaChannel)
+ if (!premultiplyAlpha)
// FIXME: must fetch the image data before the premultiplication step
neededAlphaOp = kAlphaDoUnmultiply;
QImage nativeImage = nativePixmap->toImage().convertToFormat(QImage::Format_ARGB32);
diff --git a/WebCore/platform/graphics/qt/GraphicsContextQt.cpp b/WebCore/platform/graphics/qt/GraphicsContextQt.cpp
index 1632804..41c9759 100644
--- a/WebCore/platform/graphics/qt/GraphicsContextQt.cpp
+++ b/WebCore/platform/graphics/qt/GraphicsContextQt.cpp
@@ -209,6 +209,15 @@ public:
return shadow.type != ContextShadow::NoShadow;
}
+ QRectF clipBoundingRect() const
+ {
+#if QT_VERSION >= QT_VERSION_CHECK(4, 8, 0)
+ return painter->clipBoundingRect();
+#else
+ return painter->clipRegion().boundingRect();
+#endif
+ }
+
private:
QPainter* painter;
};
@@ -247,6 +256,9 @@ GraphicsContext::GraphicsContext(PlatformGraphicsContext* context)
// Make sure the context starts in sync with our state.
setPlatformFillColor(fillColor(), DeviceColorSpace);
setPlatformStrokeColor(strokeColor(), DeviceColorSpace);
+
+ // Make sure we start with the correct join mode.
+ setLineJoin(MiterJoin);
}
}
@@ -636,56 +648,50 @@ void GraphicsContext::fillRect(const FloatRect& rect)
return;
QPainter* p = m_data->p();
- FloatRect normalizedRect = rect.normalized();
-
- QRectF shadowDestRect;
- QImage* shadowImage = 0;
- QPainter* pShadow = 0;
-
- if (m_data->hasShadow()) {
- shadowImage = new QImage(roundedIntSize(normalizedRect.size()), QImage::Format_ARGB32_Premultiplied);
- pShadow = new QPainter(shadowImage);
- shadowDestRect = normalizedRect;
- shadowDestRect.translate(m_data->shadow.offset);
-
- pShadow->setCompositionMode(QPainter::CompositionMode_Source);
- pShadow->fillRect(shadowImage->rect(), m_data->shadow.color);
- pShadow->setCompositionMode(QPainter::CompositionMode_DestinationIn);
- }
+ QRectF normalizedRect = rect.normalized();
+ ContextShadow* shadow = contextShadow();
if (m_common->state.fillPattern) {
AffineTransform affine;
- FloatRect rectM(rect);
QBrush brush(m_common->state.fillPattern->createPlatformPattern(affine));
QPixmap* image = m_common->state.fillPattern->tileImage()->nativeImageForCurrentFrame();
-
- if (m_data->hasShadow()) {
- drawRepeatPattern(pShadow, image, FloatRect(static_cast<QRectF>(shadowImage->rect())), m_common->state.fillPattern->repeatX(), m_common->state.fillPattern->repeatY());
- pShadow->end();
- p->drawImage(shadowDestRect, *shadowImage, shadowImage->rect());
+ QPainter* shadowPainter = m_data->hasShadow() ? shadow->beginShadowLayer(p, normalizedRect) : 0;
+ if (shadowPainter) {
+ drawRepeatPattern(shadowPainter, image, normalizedRect, m_common->state.fillPattern->repeatX(), m_common->state.fillPattern->repeatY());
+ shadowPainter->setCompositionMode(QPainter::CompositionMode_SourceIn);
+ shadowPainter->fillRect(normalizedRect, shadow->color);
+ shadow->endShadowLayer(p);
}
drawRepeatPattern(p, image, normalizedRect, m_common->state.fillPattern->repeatX(), m_common->state.fillPattern->repeatY());
} else if (m_common->state.fillGradient) {
QBrush brush(*m_common->state.fillGradient->platformGradient());
brush.setTransform(m_common->state.fillGradient->gradientSpaceTransform());
-
- if (m_data->hasShadow()) {
- pShadow->fillRect(shadowImage->rect(), brush);
- pShadow->end();
- p->drawImage(shadowDestRect, *shadowImage, shadowImage->rect());
+ QPainter* shadowPainter = m_data->hasShadow() ? shadow->beginShadowLayer(p, normalizedRect) : 0;
+ if (shadowPainter) {
+ shadowPainter->fillRect(normalizedRect, brush);
+ shadowPainter->setCompositionMode(QPainter::CompositionMode_SourceIn);
+ shadowPainter->fillRect(normalizedRect, shadow->color);
+ shadow->endShadowLayer(p);
}
p->fillRect(normalizedRect, brush);
} else {
if (m_data->hasShadow()) {
- pShadow->fillRect(shadowImage->rect(), p->brush());
- pShadow->end();
- p->drawImage(shadowDestRect, *shadowImage, shadowImage->rect());
+ if (shadow->type == ContextShadow::BlurShadow) {
+ QPainter* shadowPainter = shadow->beginShadowLayer(p, normalizedRect);
+ if (shadowPainter) {
+ shadowPainter->fillRect(normalizedRect, p->brush());
+ shadow->endShadowLayer(p);
+ }
+ } else {
+ // Solid rectangle fill with no blur shadow can be done faster
+ // without using the shadow layer at all.
+ QColor shadowColor = shadow->color;
+ shadowColor.setAlphaF(shadowColor.alphaF() * p->brush().color().alphaF());
+ p->fillRect(normalizedRect.translated(shadow->offset), shadowColor);
+ }
}
p->fillRect(normalizedRect, p->brush());
}
-
- delete shadowImage;
- delete pShadow;
}
@@ -696,11 +702,25 @@ void GraphicsContext::fillRect(const FloatRect& rect, const Color& color, ColorS
m_data->solidColor.setColor(color);
QPainter* p = m_data->p();
+ QRectF normalizedRect = rect.normalized();
- if (m_data->hasShadow())
- m_data->shadow.drawShadowRect(p, rect);
+ if (m_data->hasShadow()) {
+ ContextShadow* shadow = contextShadow();
- p->fillRect(rect, m_data->solidColor);
+ if (shadow->type != ContextShadow::BlurShadow) {
+ // We do not need any layer for simple shadow.
+ p->fillRect(normalizedRect.translated(shadow->offset), shadow->color);
+ } else {
+ QPainter* shadowPainter = shadow->beginShadowLayer(p, normalizedRect);
+ if (shadowPainter) {
+ shadowPainter->setCompositionMode(QPainter::CompositionMode_Source);
+ shadowPainter->fillRect(normalizedRect, shadow->color);
+ shadow->endShadowLayer(p);
+ }
+ }
+ }
+
+ p->fillRect(normalizedRect, m_data->solidColor);
}
void GraphicsContext::fillRoundedRect(const IntRect& rect, const IntSize& topLeft, const IntSize& topRight, const IntSize& bottomLeft, const IntSize& bottomRight, const Color& color, ColorSpace colorSpace)
@@ -742,6 +762,11 @@ PlatformPath* GraphicsContext::currentPath()
return &m_data->currentPath;
}
+ContextShadow* GraphicsContext::contextShadow()
+{
+ return &m_data->shadow;
+}
+
void GraphicsContext::clip(const FloatRect& rect)
{
if (paintingDisabled())
@@ -893,7 +918,7 @@ void GraphicsContext::beginTransparencyLayer(float opacity)
w = device->width();
h = device->height();
- QRectF clip = p->clipPath().boundingRect();
+ QRectF clip = m_data->clipBoundingRect();
QRectF deviceClip = p->transform().mapRect(clip);
x = int(qBound(qreal(0), deviceClip.x(), (qreal)w));
y = int(qBound(qreal(0), deviceClip.y(), (qreal)h));
@@ -1056,7 +1081,7 @@ void GraphicsContext::clipOut(const Path& path)
QPainterPath newClip;
newClip.setFillRule(Qt::OddEvenFill);
if (p->hasClipping()) {
- newClip.addRect(p->clipRegion().boundingRect());
+ newClip.addRect(m_data->clipBoundingRect());
newClip.addPath(clippedOut);
p->setClipPath(newClip, Qt::IntersectClip);
} else {
@@ -1126,7 +1151,7 @@ void GraphicsContext::clipOut(const IntRect& rect)
QPainterPath newClip;
newClip.setFillRule(Qt::OddEvenFill);
if (p->hasClipping()) {
- newClip.addRect(p->clipRegion().boundingRect());
+ newClip.addRect(m_data->clipBoundingRect());
newClip.addRect(QRect(rect));
p->setClipPath(newClip, Qt::IntersectClip);
} else {
@@ -1148,7 +1173,7 @@ void GraphicsContext::clipOutEllipseInRect(const IntRect& rect)
QPainterPath newClip;
newClip.setFillRule(Qt::OddEvenFill);
if (p->hasClipping()) {
- newClip.addRect(p->clipRegion().boundingRect());
+ newClip.addRect(m_data->clipBoundingRect());
newClip.addEllipse(QRect(rect));
p->setClipPath(newClip, Qt::IntersectClip);
} else {
diff --git a/WebCore/platform/graphics/qt/GraphicsLayerQt.h b/WebCore/platform/graphics/qt/GraphicsLayerQt.h
index f81bd3d..4282e64 100644
--- a/WebCore/platform/graphics/qt/GraphicsLayerQt.h
+++ b/WebCore/platform/graphics/qt/GraphicsLayerQt.h
@@ -20,6 +20,9 @@
#ifndef GraphicsLayerQt_h
#define GraphicsLayerQt_h
+#if ENABLE(3D_CANVAS)
+#include "GraphicsContext3D.h"
+#endif
#include "GraphicsLayer.h"
#include "GraphicsLayerClient.h"
diff --git a/WebCore/platform/graphics/qt/ImageBufferQt.cpp b/WebCore/platform/graphics/qt/ImageBufferQt.cpp
index 11ca377..ee01222 100644
--- a/WebCore/platform/graphics/qt/ImageBufferQt.cpp
+++ b/WebCore/platform/graphics/qt/ImageBufferQt.cpp
@@ -216,11 +216,11 @@ PassRefPtr<ImageData> getImageData(const IntRect& rect, const ImageBufferData& i
const uchar* bits = image.bits();
#endif
- quint32* destRows = reinterpret_cast<quint32*>(&data[desty * rect.width() + destx]);
+ quint32* destRows = reinterpret_cast_ptr<quint32*>(&data[desty * rect.width() + destx]);
if (multiplied == Unmultiplied) {
for (int y = 0; y < numRows; ++y) {
- const quint32* scanLine = reinterpret_cast<const quint32*>(bits + (y + originy) * bytesPerLine);
+ const quint32* scanLine = reinterpret_cast_ptr<const quint32*>(bits + (y + originy) * bytesPerLine);
for (int x = 0; x < numColumns; x++) {
QRgb pixel = scanLine[x + originx];
int alpha = qAlpha(pixel);
@@ -242,7 +242,7 @@ PassRefPtr<ImageData> getImageData(const IntRect& rect, const ImageBufferData& i
}
} else {
for (int y = 0; y < numRows; ++y) {
- const quint32* scanLine = reinterpret_cast<const quint32*>(bits + (y + originy) * bytesPerLine);
+ const quint32* scanLine = reinterpret_cast_ptr<const quint32*>(bits + (y + originy) * bytesPerLine);
for (int x = 0; x < numColumns; x++) {
QRgb pixel = scanLine[x + originx];
// Convert RGB to BGR.
@@ -318,11 +318,11 @@ void putImageData(ImageData*& source, const IntRect& sourceRect, const IntPoint&
uchar* bits = image.bits();
const int bytesPerLine = image.bytesPerLine();
- const quint32* srcScanLine = reinterpret_cast<const quint32*>(source->data()->data()->data() + originy * srcBytesPerRow + originx * 4);
+ const quint32* srcScanLine = reinterpret_cast_ptr<const quint32*>(source->data()->data()->data() + originy * srcBytesPerRow + originx * 4);
if (multiplied == Unmultiplied) {
for (int y = 0; y < numRows; ++y) {
- quint32* destScanLine = reinterpret_cast<quint32*>(bits + y * bytesPerLine);
+ quint32* destScanLine = reinterpret_cast_ptr<quint32*>(bits + y * bytesPerLine);
for (int x = 0; x < numColumns; x++) {
// Premultiply and convert BGR to RGB.
quint32 pixel = srcScanLine[x];
@@ -332,7 +332,7 @@ void putImageData(ImageData*& source, const IntRect& sourceRect, const IntPoint&
}
} else {
for (int y = 0; y < numRows; ++y) {
- quint32* destScanLine = reinterpret_cast<quint32*>(bits + y * bytesPerLine);
+ quint32* destScanLine = reinterpret_cast_ptr<quint32*>(bits + y * bytesPerLine);
for (int x = 0; x < numColumns; x++) {
// Convert BGR to RGB.
quint32 pixel = srcScanLine[x];
diff --git a/WebCore/platform/graphics/qt/ImageDecoderQt.cpp b/WebCore/platform/graphics/qt/ImageDecoderQt.cpp
index 858cc44..02bb110 100644
--- a/WebCore/platform/graphics/qt/ImageDecoderQt.cpp
+++ b/WebCore/platform/graphics/qt/ImageDecoderQt.cpp
@@ -37,17 +37,18 @@
namespace WebCore {
-ImageDecoder* ImageDecoder::create(const SharedBuffer& data)
+ImageDecoder* ImageDecoder::create(const SharedBuffer& data, bool premultiplyAlpha)
{
// We need at least 4 bytes to figure out what kind of image we're dealing with.
if (data.size() < 4)
return 0;
- return new ImageDecoderQt;
+ return new ImageDecoderQt(premultiplyAlpha);
}
-ImageDecoderQt::ImageDecoderQt()
- : m_repetitionCount(cAnimationNone)
+ImageDecoderQt::ImageDecoderQt(bool premultiplyAlpha)
+ : ImageDecoder(premultiplyAlpha)
+ , m_repetitionCount(cAnimationNone)
{
}
@@ -104,10 +105,15 @@ size_t ImageDecoderQt::frameCount()
// we will have to parse everything...
if (!imageCount)
forceLoadEverything();
- else
+ else {
m_frameBufferCache.resize(imageCount);
- } else
+ for (size_t i = 0; i < m_frameBufferCache.size(); ++i)
+ m_frameBufferCache[i].setPremultiplyAlpha(m_premultiplyAlpha);
+ }
+ } else {
m_frameBufferCache.resize(1);
+ m_frameBufferCache[0].setPremultiplyAlpha(m_premultiplyAlpha);
+ }
}
return m_frameBufferCache.size();
@@ -236,6 +242,8 @@ void ImageDecoderQt::forceLoadEverything()
// Otherwise, we want to forget about
// the last attempt to decode a image.
m_frameBufferCache.resize(imageCount - 1);
+ for (size_t i = 0; i < m_frameBufferCache.size(); ++i)
+ m_frameBufferCache[i].setPremultiplyAlpha(m_premultiplyAlpha);
if (imageCount == 1)
setFailed();
}
diff --git a/WebCore/platform/graphics/qt/ImageDecoderQt.h b/WebCore/platform/graphics/qt/ImageDecoderQt.h
index ceef884..5014d53 100644
--- a/WebCore/platform/graphics/qt/ImageDecoderQt.h
+++ b/WebCore/platform/graphics/qt/ImageDecoderQt.h
@@ -41,7 +41,7 @@ namespace WebCore {
class ImageDecoderQt : public ImageDecoder
{
public:
- ImageDecoderQt();
+ ImageDecoderQt(bool premultiplyAlpha);
~ImageDecoderQt();
virtual void setData(SharedBuffer* data, bool allDataReceived);
diff --git a/WebCore/platform/graphics/qt/TransparencyLayer.h b/WebCore/platform/graphics/qt/TransparencyLayer.h
index 0d9c121..1a614ac 100644
--- a/WebCore/platform/graphics/qt/TransparencyLayer.h
+++ b/WebCore/platform/graphics/qt/TransparencyLayer.h
@@ -52,7 +52,7 @@ struct TransparencyLayer : FastAllocBase {
offset = rect.topLeft();
pixmap.fill(Qt::transparent);
painter.begin(&pixmap);
- painter.setRenderHint(QPainter::Antialiasing, p->testRenderHint(QPainter::Antialiasing));
+ painter.setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform);
painter.translate(-offset);
painter.setPen(p->pen());
painter.setBrush(p->brush());
diff --git a/WebCore/platform/graphics/skia/BitmapImageSingleFrameSkia.h b/WebCore/platform/graphics/skia/BitmapImageSingleFrameSkia.h
index 9fb6a8b..553f203 100644
--- a/WebCore/platform/graphics/skia/BitmapImageSingleFrameSkia.h
+++ b/WebCore/platform/graphics/skia/BitmapImageSingleFrameSkia.h
@@ -46,9 +46,10 @@ namespace WebCore {
// is that NativeImagePtr = NativeImageSkia, yet callers have SkBitmap.
class BitmapImageSingleFrameSkia : public Image {
public:
- // Creates a new Image, by copying the pixel values out of |bitmap|.
- // If creation failed, returns null.
- static PassRefPtr<BitmapImageSingleFrameSkia> create(const SkBitmap&);
+ // Creates a new Image from the given SkBitmap. If "copyPixels" is true, a
+ // deep copy is done. Otherwise, a shallow copy is done (pixel data is
+ // ref'ed).
+ static PassRefPtr<BitmapImageSingleFrameSkia> create(const SkBitmap&, bool copyPixels);
virtual bool isBitmapImage() const { return true; }
@@ -77,8 +78,8 @@ protected:
private:
NativeImageSkia m_nativeImage;
- // Use create().
- BitmapImageSingleFrameSkia() { }
+ // Creates a new Image from the given SkBitmap, using a shallow copy.
+ explicit BitmapImageSingleFrameSkia(const SkBitmap&);
};
} // namespace WebCore
diff --git a/WebCore/platform/graphics/skia/GraphicsContext3DSkia.cpp b/WebCore/platform/graphics/skia/GraphicsContext3DSkia.cpp
index ee0a874..61039f2 100644
--- a/WebCore/platform/graphics/skia/GraphicsContext3DSkia.cpp
+++ b/WebCore/platform/graphics/skia/GraphicsContext3DSkia.cpp
@@ -31,6 +31,7 @@
#include "GraphicsContext3D.h"
#include "Image.h"
+#include "ImageSource.h"
#include "NativeImageSkia.h"
#include <algorithm>
@@ -43,27 +44,28 @@ bool GraphicsContext3D::getImageData(Image* image,
bool premultiplyAlpha,
Vector<uint8_t>& outputVector)
{
- if (!image)
+ if (!image || !image->data())
return false;
- NativeImageSkia* skiaImage = image->nativeImageForCurrentFrame();
- if (!skiaImage)
+ ImageSource decoder(false);
+ decoder.setData(image->data(), true);
+ if (!decoder.frameCount() || !decoder.frameIsCompleteAtIndex(0))
return false;
- SkBitmap::Config skiaConfig = skiaImage->config();
- // FIXME: must support more image configurations.
+ bool hasAlpha = decoder.frameHasAlphaAtIndex(0);
+ OwnPtr<NativeImageSkia> pixels(decoder.createFrameAtIndex(0));
+ if (!pixels.get() || !pixels->isDataComplete() || !pixels->width() || !pixels->height())
+ return false;
+ SkBitmap::Config skiaConfig = pixels->config();
if (skiaConfig != SkBitmap::kARGB_8888_Config)
return false;
- SkBitmap& skiaImageRef = *skiaImage;
+ SkBitmap& skiaImageRef = *pixels;
SkAutoLockPixels lock(skiaImageRef);
- int height = skiaImage->height();
- int rowBytes = skiaImage->rowBytes();
- ASSERT(rowBytes == skiaImage->width() * 4);
- uint8_t* pixels = reinterpret_cast<uint8_t*>(skiaImage->getPixels());
- outputVector.resize(rowBytes * height);
+ ASSERT(pixels->rowBytes() == pixels->width() * 4);
+ outputVector.resize(pixels->rowBytes() * pixels->height());
AlphaOp neededAlphaOp = kAlphaDoNothing;
- if (!premultiplyAlpha)
- // FIXME: must fetch the image data before the premultiplication step
- neededAlphaOp = kAlphaDoUnmultiply;
- return packPixels(pixels, kSourceFormatBGRA8, skiaImage->width(), height, 0,
+ if (hasAlpha && premultiplyAlpha)
+ neededAlphaOp = kAlphaDoPremultiply;
+ return packPixels(reinterpret_cast<const uint8_t*>(pixels->getPixels()),
+ kSourceFormatBGRA8, pixels->width(), pixels->height(), 0,
format, type, neededAlphaOp, outputVector.data());
}
diff --git a/WebCore/platform/graphics/skia/GraphicsContextSkia.cpp b/WebCore/platform/graphics/skia/GraphicsContextSkia.cpp
index fe7f6ce..1b20e26 100644
--- a/WebCore/platform/graphics/skia/GraphicsContextSkia.cpp
+++ b/WebCore/platform/graphics/skia/GraphicsContextSkia.cpp
@@ -323,7 +323,6 @@ void GraphicsContext::addPath(const Path& path)
{
if (paintingDisabled())
return;
- platformContext()->prepareForSoftwareDraw();
platformContext()->addPath(*path.platformPath());
}
@@ -331,7 +330,6 @@ void GraphicsContext::beginPath()
{
if (paintingDisabled())
return;
- platformContext()->prepareForSoftwareDraw();
platformContext()->beginPath();
}
@@ -783,7 +781,7 @@ void GraphicsContext::fillRect(const FloatRect& rect)
}
#if USE(GLES2_RENDERING)
- if (platformContext()->useGPU() && !m_common->state.fillPattern && !m_common->state.fillGradient) {
+ if (platformContext()->useGPU() && !m_common->state.fillPattern && !m_common->state.fillGradient && !platformContext()->getDrawLooper()) {
platformContext()->prepareForHardwareDraw();
platformContext()->gpuCanvas()->fillRect(rect);
return;
diff --git a/WebCore/platform/graphics/skia/ImageBufferSkia.cpp b/WebCore/platform/graphics/skia/ImageBufferSkia.cpp
index a63eec5..9403406 100644
--- a/WebCore/platform/graphics/skia/ImageBufferSkia.cpp
+++ b/WebCore/platform/graphics/skia/ImageBufferSkia.cpp
@@ -89,12 +89,13 @@ GraphicsContext* ImageBuffer::context() const
bool ImageBuffer::drawsUsingCopy() const
{
- return true;
+ return false;
}
PassRefPtr<Image> ImageBuffer::copyImage() const
{
- return BitmapImageSingleFrameSkia::create(*m_data.m_platformContext.bitmap());
+ m_context->platformContext()->syncSoftwareCanvas();
+ return BitmapImageSingleFrameSkia::create(*m_data.m_platformContext.bitmap(), true);
}
void ImageBuffer::clip(GraphicsContext* context, const FloatRect& rect) const
@@ -107,15 +108,15 @@ void ImageBuffer::clip(GraphicsContext* context, const FloatRect& rect) const
void ImageBuffer::draw(GraphicsContext* context, ColorSpace styleColorSpace, const FloatRect& destRect, const FloatRect& srcRect,
CompositeOperator op, bool useLowQualityScale)
{
- RefPtr<Image> imageCopy = copyImage();
- context->drawImage(imageCopy.get(), styleColorSpace, destRect, srcRect, op, useLowQualityScale);
+ RefPtr<Image> image = BitmapImageSingleFrameSkia::create(*m_data.m_platformContext.bitmap(), context == m_context);
+ context->drawImage(image.get(), styleColorSpace, destRect, srcRect, op, useLowQualityScale);
}
void ImageBuffer::drawPattern(GraphicsContext* context, const FloatRect& srcRect, const AffineTransform& patternTransform,
const FloatPoint& phase, ColorSpace styleColorSpace, CompositeOperator op, const FloatRect& destRect)
{
- RefPtr<Image> imageCopy = copyImage();
- imageCopy->drawPattern(context, srcRect, patternTransform, phase, styleColorSpace, op, destRect);
+ RefPtr<Image> image = BitmapImageSingleFrameSkia::create(*m_data.m_platformContext.bitmap(), context == m_context);
+ image->drawPattern(context, srcRect, patternTransform, phase, styleColorSpace, op, destRect);
}
void ImageBuffer::platformTransformColorSpace(const Vector<int>& lookUpTable)
diff --git a/WebCore/platform/graphics/skia/ImageSkia.cpp b/WebCore/platform/graphics/skia/ImageSkia.cpp
index b514b1a..1ff87cc 100644
--- a/WebCore/platform/graphics/skia/ImageSkia.cpp
+++ b/WebCore/platform/graphics/skia/ImageSkia.cpp
@@ -419,8 +419,9 @@ static void drawBitmapGLES2(GraphicsContext* ctxt, NativeImageSkia* bitmap, cons
ASSERT(bitmap->config() == SkBitmap::kARGB_8888_Config);
ASSERT(bitmap->rowBytes() == bitmap->width() * 4);
texture = gpuCanvas->createTexture(bitmap, GLES2Texture::BGRA8, bitmap->width(), bitmap->height());
- ASSERT(bitmap->pixelRef());
- texture->load(bitmap->pixelRef()->pixels());
+ SkAutoLockPixels lock(*bitmap);
+ ASSERT(bitmap->getPixels());
+ texture->load(bitmap->getPixels());
}
gpuCanvas->drawTexturedRect(texture, srcRect, dstRect, styleColorSpace, compositeOp);
}
@@ -516,11 +517,19 @@ void BitmapImageSingleFrameSkia::draw(GraphicsContext* ctxt,
WebCoreCompositeToSkiaComposite(compositeOp));
}
-PassRefPtr<BitmapImageSingleFrameSkia> BitmapImageSingleFrameSkia::create(const SkBitmap& bitmap)
+BitmapImageSingleFrameSkia::BitmapImageSingleFrameSkia(const SkBitmap& bitmap)
+ : m_nativeImage(bitmap)
{
- RefPtr<BitmapImageSingleFrameSkia> image(adoptRef(new BitmapImageSingleFrameSkia()));
- bitmap.copyTo(&image->m_nativeImage, bitmap.config());
- return image.release();
+}
+
+PassRefPtr<BitmapImageSingleFrameSkia> BitmapImageSingleFrameSkia::create(const SkBitmap& bitmap, bool copyPixels)
+{
+ if (copyPixels) {
+ SkBitmap temp;
+ bitmap.copyTo(&temp, bitmap.config());
+ return adoptRef(new BitmapImageSingleFrameSkia(temp));
+ }
+ return adoptRef(new BitmapImageSingleFrameSkia(bitmap));
}
} // namespace WebCore
diff --git a/WebCore/platform/graphics/skia/NativeImageSkia.cpp b/WebCore/platform/graphics/skia/NativeImageSkia.cpp
index 007a32c..28e0758 100644
--- a/WebCore/platform/graphics/skia/NativeImageSkia.cpp
+++ b/WebCore/platform/graphics/skia/NativeImageSkia.cpp
@@ -46,6 +46,14 @@ NativeImageSkia::NativeImageSkia()
{
}
+NativeImageSkia::NativeImageSkia(const SkBitmap& other)
+ : SkBitmap(other),
+ m_isDataComplete(false),
+ m_lastRequestSize(0, 0),
+ m_resizeRequests(0)
+{
+}
+
int NativeImageSkia::decodedSize() const
{
return getSize() + m_resizedImage.getSize();
diff --git a/WebCore/platform/graphics/skia/NativeImageSkia.h b/WebCore/platform/graphics/skia/NativeImageSkia.h
index 0718836..e26a5ea 100644
--- a/WebCore/platform/graphics/skia/NativeImageSkia.h
+++ b/WebCore/platform/graphics/skia/NativeImageSkia.h
@@ -43,6 +43,11 @@ class NativeImageSkia : public SkBitmap {
public:
NativeImageSkia();
+ // This constructor does a shallow copy of the passed-in SkBitmap (ie., it
+ // references the same pixel data and bumps the refcount). Use only when
+ // you want sharing semantics.
+ explicit NativeImageSkia(const SkBitmap&);
+
// Returns the number of bytes of image data. This includes the cached
// resized version if there is one.
int decodedSize() const;
diff --git a/WebCore/platform/graphics/skia/PlatformContextSkia.cpp b/WebCore/platform/graphics/skia/PlatformContextSkia.cpp
index 1161224..b9de0a2 100644
--- a/WebCore/platform/graphics/skia/PlatformContextSkia.cpp
+++ b/WebCore/platform/graphics/skia/PlatformContextSkia.cpp
@@ -733,11 +733,7 @@ void PlatformContextSkia::prepareForSoftwareDraw() const
if (m_state->m_xferMode == SkXfermode::kSrcOver_Mode) {
// Last drawn on hardware; clear out the canvas.
- m_canvas->save();
- SkRect bounds = {0, 0, m_canvas->getDevice()->width(), m_canvas->getDevice()->height()};
- m_canvas->clipRect(bounds, SkRegion::kReplace_Op);
- m_canvas->drawARGB(0, 0, 0, 0, SkXfermode::kClear_Mode);
- m_canvas->restore();
+ m_canvas->getDevice()->eraseColor(0);
// Start compositing into the empty canvas.
m_backingStoreState = Mixed;
} else {
@@ -753,6 +749,8 @@ void PlatformContextSkia::prepareForSoftwareDraw() const
readbackHardwareToSoftware();
m_backingStoreState = Software;
}
+ } else if (m_backingStoreState == None) {
+ m_backingStoreState = Software;
}
}
diff --git a/WebCore/platform/graphics/win/FontCustomPlatformDataCairo.cpp b/WebCore/platform/graphics/win/FontCustomPlatformDataCairo.cpp
index 35839f5..02c5b99 100644
--- a/WebCore/platform/graphics/win/FontCustomPlatformDataCairo.cpp
+++ b/WebCore/platform/graphics/win/FontCustomPlatformDataCairo.cpp
@@ -27,12 +27,12 @@
namespace WebCore {
-FontCustomPlatformDataCairo::~FontCustomPlatformDataCairo()
+FontCustomPlatformData::~FontCustomPlatformData()
{
cairo_font_face_destroy(m_fontFace);
}
-FontPlatformData FontCustomPlatformDataCairo::fontPlatformData(int size, bool bold, bool italic)
+FontPlatformData FontCustomPlatformData::fontPlatformData(int size, bool bold, bool italic)
{
return FontPlatformData(m_fontFace, size, bold, italic);
}
@@ -42,7 +42,7 @@ static void releaseData(void* data)
static_cast<SharedBuffer*>(data)->deref();
}
-FontCustomPlatformDataCairo* createFontCustomPlatformData(SharedBuffer* buffer)
+FontCustomPlatformData* createFontCustomPlatformData(SharedBuffer* buffer)
{
ASSERT_ARG(buffer, buffer);
@@ -55,7 +55,7 @@ FontCustomPlatformDataCairo* createFontCustomPlatformData(SharedBuffer* buffer)
static cairo_user_data_key_t bufferKey;
cairo_font_face_set_user_data(fontFace, &bufferKey, buffer, releaseData);
- return new FontCustomPlatformDataCairo(fontFace);
+ return new FontCustomPlatformData(fontFace);
}
bool FontCustomPlatformData::supportsFormat(const String& format)
diff --git a/WebCore/platform/graphics/win/FontCustomPlatformDataCairo.h b/WebCore/platform/graphics/win/FontCustomPlatformDataCairo.h
index 2dbea51..525957f 100644
--- a/WebCore/platform/graphics/win/FontCustomPlatformDataCairo.h
+++ b/WebCore/platform/graphics/win/FontCustomPlatformDataCairo.h
@@ -1,5 +1,6 @@
/*
* Copyright (C) 2007 Apple Computer, Inc.
+ * Copyright (C) 2010 Brent Fulgham <bfulgham@webkit.org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
@@ -31,12 +32,12 @@ namespace WebCore {
class FontPlatformData;
class SharedBuffer;
-struct FontCustomPlatformDataCairo : Noncopyable {
- FontCustomPlatformDataCairo(cairo_font_face_t* fontFace)
+struct FontCustomPlatformData : Noncopyable {
+ FontCustomPlatformData(cairo_font_face_t* fontFace)
: m_fontFace(fontFace)
{
}
- ~FontCustomPlatformDataCairo();
+ ~FontCustomPlatformData();
FontPlatformData fontPlatformData(int size, bool bold, bool italic);
@@ -45,7 +46,7 @@ struct FontCustomPlatformDataCairo : Noncopyable {
cairo_font_face_t* m_fontFace;
};
-FontCustomPlatformDataCairo* createFontCustomPlatformData(SharedBuffer*);
+FontCustomPlatformData* createFontCustomPlatformData(SharedBuffer*);
}
diff --git a/WebCore/platform/graphics/win/WKCACFLayer.cpp b/WebCore/platform/graphics/win/WKCACFLayer.cpp
index b5f3427..bbe5883 100644
--- a/WebCore/platform/graphics/win/WKCACFLayer.cpp
+++ b/WebCore/platform/graphics/win/WKCACFLayer.cpp
@@ -44,6 +44,24 @@ namespace WebCore {
using namespace std;
+#ifndef NDEBUG
+void WKCACFLayer::internalCheckLayerConsistency()
+{
+ ASSERT(layer());
+ size_t n = sublayerCount();
+ for (size_t i = 0; i < n; ++i) {
+ // This will ASSERT in internalSublayerAtIndex if this entry doesn't have proper user data
+ WKCACFLayer* sublayer = internalSublayerAtIndex(i);
+
+ // Make sure we don't have any null entries in the list
+ ASSERT(sublayer);
+
+ // Make sure the each layer has a corresponding CACFLayer
+ ASSERT(sublayer->layer());
+ }
+}
+#endif
+
static void displayCallback(CACFLayerRef layer, CGContextRef context)
{
ASSERT_ARG(layer, WKCACFLayer::layer(layer));
@@ -161,7 +179,14 @@ WKCACFLayer::~WKCACFLayer()
// Our superlayer should be holding a reference to us, so there should be no way for us to be destroyed while we still have a superlayer.
ASSERT(!superlayer());
+ // Get rid of the children so we don't have any dangling references around
+ removeAllSublayers();
+
+#ifndef NDEBUG
+ CACFLayerSetUserData(layer(), reinterpret_cast<void*>(0xDEADBEEF));
+#else
CACFLayerSetUserData(layer(), 0);
+#endif
CACFLayerSetDisplayCallback(layer(), 0);
}
@@ -192,10 +217,11 @@ void WKCACFLayer::addSublayer(PassRefPtr<WKCACFLayer> sublayer)
void WKCACFLayer::internalInsertSublayer(PassRefPtr<WKCACFLayer> sublayer, size_t index)
{
- index = min(index, sublayerCount());
+ index = min(index, sublayerCount() + 1);
sublayer->removeFromSuperlayer();
CACFLayerInsertSublayer(layer(), sublayer->layer(), index);
setNeedsCommit();
+ checkLayerConsistency();
}
void WKCACFLayer::insertSublayerAboveLayer(PassRefPtr<WKCACFLayer> sublayer, const WKCACFLayer* reference)
@@ -268,12 +294,14 @@ void WKCACFLayer::adoptSublayers(WKCACFLayer* source)
sublayers.append(source->internalSublayerAtIndex(i));
setSublayers(sublayers);
+ source->checkLayerConsistency();
}
void WKCACFLayer::removeFromSuperlayer()
{
WKCACFLayer* superlayer = this->superlayer();
CACFLayerRemoveFromSuperlayer(layer());
+ checkLayerConsistency();
if (superlayer)
superlayer->setNeedsCommit();
diff --git a/WebCore/platform/graphics/win/WKCACFLayer.h b/WebCore/platform/graphics/win/WKCACFLayer.h
index abc04c8..7243508 100644
--- a/WebCore/platform/graphics/win/WKCACFLayer.h
+++ b/WebCore/platform/graphics/win/WKCACFLayer.h
@@ -60,7 +60,11 @@ public:
BottomLeft, BottomRight, Resize, ResizeAspect, ResizeAspectFill };
static PassRefPtr<WKCACFLayer> create(LayerType);
- static WKCACFLayer* layer(CACFLayerRef layer) { return static_cast<WKCACFLayer*>(CACFLayerGetUserData(layer)); }
+ static WKCACFLayer* layer(CACFLayerRef layer)
+ {
+ ASSERT(CACFLayerGetUserData(layer) != reinterpret_cast<void*>(0xDEADBEEF));
+ return static_cast<WKCACFLayer*>(CACFLayerGetUserData(layer));
+ }
virtual ~WKCACFLayer();
@@ -133,7 +137,11 @@ public:
void adoptSublayers(WKCACFLayer* source);
void removeAllSublayers() { internalRemoveAllSublayers(); }
- void setSublayers(const Vector<RefPtr<WKCACFLayer> >& sublayers) { internalSetSublayers(sublayers); }
+ void setSublayers(const Vector<RefPtr<WKCACFLayer> >& sublayers)
+ {
+ internalSetSublayers(sublayers);
+ checkLayerConsistency();
+ }
void insertSublayer(PassRefPtr<WKCACFLayer> layer, size_t index) { internalInsertSublayer(layer, index); }
@@ -244,6 +252,13 @@ protected:
// This should only be called from removeFromSuperlayer.
void removeSublayer(const WKCACFLayer*);
+ void checkLayerConsistency()
+ {
+#ifndef NDEBUG
+ internalCheckLayerConsistency();
+#endif
+ }
+
// Methods to be overridden for sublayer and rendering management
virtual WKCACFLayer* internalSublayerAtIndex(int) const;
@@ -259,6 +274,10 @@ protected:
virtual void internalSetNeedsDisplay(const CGRect* dirtyRect);
#ifndef NDEBUG
+ virtual void internalCheckLayerConsistency();
+#endif
+
+#ifndef NDEBUG
// Print this layer and its children to the console
void printLayer(int indent) const;
#endif
diff --git a/WebCore/platform/graphics/win/WebTiledLayer.cpp b/WebCore/platform/graphics/win/WebTiledLayer.cpp
index d8c02d2..01dd6ae 100755
--- a/WebCore/platform/graphics/win/WebTiledLayer.cpp
+++ b/WebCore/platform/graphics/win/WebTiledLayer.cpp
@@ -36,6 +36,26 @@ namespace WebCore {
using namespace std;
+#ifndef NDEBUG
+void WebTiledLayer::internalCheckLayerConsistency()
+{
+ WKCACFLayer::internalCheckLayerConsistency();
+
+ // Additionally make sure the tiled parent is valid
+ CFArrayRef sublayers = CACFLayerGetSublayers(layer());
+
+ // Make sure there is a tile parent and it is the same as we remember
+ size_t n = CFArrayGetCount(sublayers);
+ ASSERT(n > 0);
+ const void* element = CFArrayGetValueAtIndex(sublayers, 0);
+ ASSERT(m_tileParent.get() == element);
+
+ // Make sure the tile parent doesn't have user data. If it does, it is probably
+ // a WKCACFLayer in the wrong place.
+ ASSERT(!layer(m_tileParent.get()));
+}
+#endif
+
void WebTiledLayer::tileDisplayCallback(CACFLayerRef layer, CGContextRef context)
{
static_cast<WebTiledLayer*>(CACFLayerGetUserData(layer))->drawTile(layer, context);
diff --git a/WebCore/platform/graphics/win/WebTiledLayer.h b/WebCore/platform/graphics/win/WebTiledLayer.h
index fdf0205..b8ae320 100644
--- a/WebCore/platform/graphics/win/WebTiledLayer.h
+++ b/WebCore/platform/graphics/win/WebTiledLayer.h
@@ -56,6 +56,10 @@ protected:
virtual void internalSetNeedsDisplay(const CGRect* dirtyRect);
+#ifndef NDEBUG
+ virtual void internalCheckLayerConsistency();
+#endif
+
private:
static void tileDisplayCallback(CACFLayerRef, CGContextRef);
void drawTile(CACFLayerRef, CGContextRef);