diff options
Diffstat (limited to 'WebCore/platform/graphics/skia')
6 files changed, 57 insertions, 105 deletions
diff --git a/WebCore/platform/graphics/skia/GraphicsContext3DSkia.cpp b/WebCore/platform/graphics/skia/GraphicsContext3DSkia.cpp index 61039f2..c503307 100644 --- a/WebCore/platform/graphics/skia/GraphicsContext3DSkia.cpp +++ b/WebCore/platform/graphics/skia/GraphicsContext3DSkia.cpp @@ -44,28 +44,40 @@ bool GraphicsContext3D::getImageData(Image* image, bool premultiplyAlpha, Vector<uint8_t>& outputVector) { - if (!image || !image->data()) + if (!image) return false; - ImageSource decoder(false); - decoder.setData(image->data(), true); - if (!decoder.frameCount() || !decoder.frameIsCompleteAtIndex(0)) - return false; - 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) + OwnPtr<NativeImageSkia> pixels; + NativeImageSkia* skiaImage = 0; + AlphaOp neededAlphaOp = kAlphaDoNothing; + if (image->data()) { + ImageSource decoder(false); + decoder.setData(image->data(), true); + if (!decoder.frameCount() || !decoder.frameIsCompleteAtIndex(0)) + return false; + bool hasAlpha = decoder.frameHasAlphaAtIndex(0); + 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; + skiaImage = pixels.get(); + if (hasAlpha && premultiplyAlpha) + neededAlphaOp = kAlphaDoPremultiply; + } else { + // This is a special case for texImage2D with HTMLCanvasElement input. + skiaImage = image->nativeImageForCurrentFrame(); + if (!premultiplyAlpha) + neededAlphaOp = kAlphaDoUnmultiply; + } + if (!skiaImage) return false; - SkBitmap& skiaImageRef = *pixels; + SkBitmap& skiaImageRef = *skiaImage; SkAutoLockPixels lock(skiaImageRef); - ASSERT(pixels->rowBytes() == pixels->width() * 4); - outputVector.resize(pixels->rowBytes() * pixels->height()); - AlphaOp neededAlphaOp = kAlphaDoNothing; - if (hasAlpha && premultiplyAlpha) - neededAlphaOp = kAlphaDoPremultiply; - return packPixels(reinterpret_cast<const uint8_t*>(pixels->getPixels()), - kSourceFormatBGRA8, pixels->width(), pixels->height(), 0, + ASSERT(skiaImage->rowBytes() == skiaImage->width() * 4); + outputVector.resize(skiaImage->rowBytes() * skiaImage->height()); + return packPixels(reinterpret_cast<const uint8_t*>(skiaImage->getPixels()), + kSourceFormatBGRA8, skiaImage->width(), skiaImage->height(), 0, format, type, neededAlphaOp, outputVector.data()); } diff --git a/WebCore/platform/graphics/skia/GraphicsContextSkia.cpp b/WebCore/platform/graphics/skia/GraphicsContextSkia.cpp index 1b20e26..1c80d49 100644 --- a/WebCore/platform/graphics/skia/GraphicsContextSkia.cpp +++ b/WebCore/platform/graphics/skia/GraphicsContextSkia.cpp @@ -34,6 +34,7 @@ #include "AffineTransform.h" #include "Color.h" #include "FloatRect.h" +#include "GLES2Canvas.h" #include "Gradient.h" #include "GraphicsContextPlatformPrivate.h" #include "GraphicsContextPrivate.h" @@ -55,10 +56,6 @@ #include <wtf/MathExtras.h> #include <wtf/UnusedParam.h> -#if USE(GLES2_RENDERING) -#include "GLES2Canvas.h" -#endif - using namespace std; namespace WebCore { @@ -248,10 +245,8 @@ void GraphicsContext::savePlatformState() if (paintingDisabled()) return; -#if USE(GLES2_RENDERING) if (platformContext()->useGPU()) platformContext()->gpuCanvas()->save(); -#endif // Save our private State. platformContext()->save(); @@ -262,10 +257,8 @@ void GraphicsContext::restorePlatformState() if (paintingDisabled()) return; -#if USE(GLES2_RENDERING) if (platformContext()->useGPU()) platformContext()->gpuCanvas()->restore(); -#endif // Restore our private State. platformContext()->restore(); @@ -345,13 +338,11 @@ void GraphicsContext::clearRect(const FloatRect& rect) if (paintingDisabled()) return; -#if USE(GLES2_RENDERING) if (platformContext()->useGPU()) { platformContext()->prepareForHardwareDraw(); platformContext()->gpuCanvas()->clearRect(rect); return; } -#endif platformContext()->prepareForSoftwareDraw(); @@ -459,10 +450,8 @@ void GraphicsContext::concatCTM(const AffineTransform& affine) if (paintingDisabled()) return; -#if USE(GLES2_RENDERING) if (platformContext()->useGPU()) platformContext()->gpuCanvas()->concatCTM(affine); -#endif platformContext()->canvas()->concat(affine); } @@ -626,9 +615,7 @@ void GraphicsContext::drawLine(const IntPoint& point1, const IntPoint& point2) platformContext()->canvas()->drawPoints(SkCanvas::kLines_PointMode, 2, pts, paint); } -void GraphicsContext::drawLineForMisspellingOrBadGrammar(const IntPoint& pt, - int width, - bool grammar) +void GraphicsContext::drawLineForTextChecking(const IntPoint& pt, int width, TextCheckingLineStyle style) { if (paintingDisabled()) return; @@ -780,13 +767,11 @@ void GraphicsContext::fillRect(const FloatRect& rect) ClipRectToCanvas(*platformContext()->canvas(), r, &r); } -#if USE(GLES2_RENDERING) if (platformContext()->useGPU() && !m_common->state.fillPattern && !m_common->state.fillGradient && !platformContext()->getDrawLooper()) { platformContext()->prepareForHardwareDraw(); platformContext()->gpuCanvas()->fillRect(rect); return; } -#endif platformContext()->save(); @@ -804,13 +789,11 @@ void GraphicsContext::fillRect(const FloatRect& rect, const Color& color, ColorS if (paintingDisabled()) return; -#if USE(GLES2_RENDERING) if (platformContext()->useGPU() && !m_common->state.fillPattern && !m_common->state.fillGradient) { platformContext()->prepareForHardwareDraw(); platformContext()->gpuCanvas()->fillRect(rect, color, colorSpace); return; } -#endif platformContext()->prepareForSoftwareDraw(); @@ -932,10 +915,8 @@ void GraphicsContext::scale(const FloatSize& size) if (paintingDisabled()) return; -#if USE(GLES2_RENDERING) if (platformContext()->useGPU()) platformContext()->gpuCanvas()->scale(size); -#endif platformContext()->canvas()->scale(WebCoreFloatToSkScalar(size.width()), WebCoreFloatToSkScalar(size.height())); @@ -945,10 +926,10 @@ void GraphicsContext::setAlpha(float alpha) { if (paintingDisabled()) return; -#if USE(GLES2_RENDERING) + if (platformContext()->useGPU()) platformContext()->gpuCanvas()->setAlpha(alpha); -#endif + platformContext()->setAlpha(alpha); } @@ -956,10 +937,10 @@ void GraphicsContext::setCompositeOperation(CompositeOperator op) { if (paintingDisabled()) return; -#if USE(GLES2_RENDERING) + if (platformContext()->useGPU()) platformContext()->gpuCanvas()->setCompositeOperation(op); -#endif + platformContext()->setXfermodeMode(WebCoreCompositeToSkiaComposite(op)); } @@ -1046,10 +1027,9 @@ void GraphicsContext::setPlatformFillColor(const Color& color, ColorSpace colorS { if (paintingDisabled()) return; -#if USE(GLES2_RENDERING) + if (platformContext()->useGPU()) platformContext()->gpuCanvas()->setFillColor(color, colorSpace); -#endif platformContext()->setFillColor(color.rgb()); } @@ -1241,10 +1221,8 @@ void GraphicsContext::rotate(float angleInRadians) if (paintingDisabled()) return; -#if USE(GLES2_RENDERING) if (platformContext()->useGPU()) platformContext()->gpuCanvas()->rotate(angleInRadians); -#endif platformContext()->canvas()->rotate(WebCoreFloatToSkScalar( angleInRadians * (180.0f / 3.14159265f))); @@ -1255,10 +1233,8 @@ void GraphicsContext::translate(float w, float h) if (paintingDisabled()) return; -#if USE(GLES2_RENDERING) if (platformContext()->useGPU()) platformContext()->gpuCanvas()->translate(w, h); -#endif platformContext()->canvas()->translate(WebCoreFloatToSkScalar(w), WebCoreFloatToSkScalar(h)); @@ -1266,19 +1242,12 @@ void GraphicsContext::translate(float w, float h) void GraphicsContext::setGraphicsContext3D(GraphicsContext3D* context3D, const IntSize& size) { -#if USE(GLES2_RENDERING) platformContext()->setGraphicsContext3D(context3D, size); -#else - UNUSED_PARAM(context3D); - UNUSED_PARAM(size); -#endif } void GraphicsContext::syncSoftwareCanvas() { -#if USE(GLES2_RENDERING) platformContext()->syncSoftwareCanvas(); -#endif } } // namespace WebCore diff --git a/WebCore/platform/graphics/skia/ImageSkia.cpp b/WebCore/platform/graphics/skia/ImageSkia.cpp index 1ff87cc..aed289f 100644 --- a/WebCore/platform/graphics/skia/ImageSkia.cpp +++ b/WebCore/platform/graphics/skia/ImageSkia.cpp @@ -36,22 +36,20 @@ #include "ChromiumBridge.h" #include "FloatConversion.h" #include "FloatRect.h" +#include "GLES2Canvas.h" +#include "GLES2Context.h" #include "GraphicsContext.h" #include "Logging.h" #include "NativeImageSkia.h" #include "PlatformContextSkia.h" #include "PlatformString.h" -#include "SkiaUtils.h" +#include "SkPixelRef.h" #include "SkRect.h" #include "SkShader.h" +#include "SkiaUtils.h" #include "skia/ext/image_operations.h" #include "skia/ext/platform_canvas.h" -#if USE(GLES2_RENDERING) -#include "GLES2Canvas.h" -#include "GLES2Context.h" -#include "SkPixelRef.h" -#endif namespace WebCore { @@ -409,23 +407,21 @@ void Image::drawPattern(GraphicsContext* context, context->platformContext()->paintSkPaint(destRect, paint); } -#if USE(GLES2_RENDERING) static void drawBitmapGLES2(GraphicsContext* ctxt, NativeImageSkia* bitmap, const FloatRect& srcRect, const FloatRect& dstRect, ColorSpace styleColorSpace, CompositeOperator compositeOp) { ctxt->platformContext()->prepareForHardwareDraw(); GLES2Canvas* gpuCanvas = ctxt->platformContext()->gpuCanvas(); - GLES2Texture* texture = gpuCanvas->getTexture(bitmap); + Texture* texture = gpuCanvas->getTexture(bitmap); if (!texture) { ASSERT(bitmap->config() == SkBitmap::kARGB_8888_Config); ASSERT(bitmap->rowBytes() == bitmap->width() * 4); - texture = gpuCanvas->createTexture(bitmap, GLES2Texture::BGRA8, bitmap->width(), bitmap->height()); + texture = gpuCanvas->createTexture(bitmap, Texture::BGRA8, bitmap->width(), bitmap->height()); SkAutoLockPixels lock(*bitmap); ASSERT(bitmap->getPixels()); texture->load(bitmap->getPixels()); } gpuCanvas->drawTexturedRect(texture, srcRect, dstRect, styleColorSpace, compositeOp); } -#endif // ================================================ // BitmapImage Class @@ -472,12 +468,11 @@ void BitmapImage::draw(GraphicsContext* ctxt, const FloatRect& dstRect, if (normSrcRect.isEmpty() || normDstRect.isEmpty()) return; // Nothing to draw. -#if USE(GLES2_RENDERING) if (ctxt->platformContext()->useGPU()) { drawBitmapGLES2(ctxt, bm, normSrcRect, normDstRect, colorSpace, compositeOp); return; } -#endif + ctxt->platformContext()->prepareForSoftwareDraw(); paintSkBitmap(ctxt->platformContext(), @@ -501,12 +496,10 @@ void BitmapImageSingleFrameSkia::draw(GraphicsContext* ctxt, if (normSrcRect.isEmpty() || normDstRect.isEmpty()) return; // Nothing to draw. -#if USE(GLES2_RENDERING) if (ctxt->platformContext()->useGPU()) { drawBitmapGLES2(ctxt, &m_nativeImage, srcRect, dstRect, styleColorSpace, compositeOp); return; } -#endif ctxt->platformContext()->prepareForSoftwareDraw(); diff --git a/WebCore/platform/graphics/skia/PlatformContextSkia.cpp b/WebCore/platform/graphics/skia/PlatformContextSkia.cpp index b9de0a2..3b1d015 100644 --- a/WebCore/platform/graphics/skia/PlatformContextSkia.cpp +++ b/WebCore/platform/graphics/skia/PlatformContextSkia.cpp @@ -34,11 +34,13 @@ #include "AffineTransform.h" #include "CanvasLayerChromium.h" +#include "GLES2Canvas.h" #include "GraphicsContext.h" +#include "GraphicsContext3D.h" #include "ImageBuffer.h" #include "NativeImageSkia.h" -#include "PlatformContextSkia.h" #include "SkiaUtils.h" +#include "Texture.h" #include "TilingData.h" #include "skia/ext/image_operations.h" @@ -46,14 +48,8 @@ #include "SkBitmap.h" #include "SkColorPriv.h" -#include "SkShader.h" #include "SkDashPathEffect.h" - -#if USE(GLES2_RENDERING) -#include "GraphicsContext3D.h" -#include "GLES2Canvas.h" -#include "GLES2Texture.h" -#endif +#include "SkShader.h" #include <wtf/MathExtras.h> #include <wtf/OwnArrayPtr.h> @@ -210,11 +206,9 @@ PlatformContextSkia::PlatformContextSkia(skia::PlatformCanvas* canvas) #if OS(WINDOWS) , m_drawingToImageBuffer(false) #endif -#if USE(GLES2_RENDERING) , m_useGPU(false) , m_gpuCanvas(0) , m_backingStoreState(None) -#endif { m_stateStack.append(State()); m_state = &m_stateStack.last(); @@ -222,7 +216,7 @@ PlatformContextSkia::PlatformContextSkia(skia::PlatformCanvas* canvas) PlatformContextSkia::~PlatformContextSkia() { -#if USE(GLES2_RENDERING) && USE(ACCELERATED_COMPOSITING) +#if USE(ACCELERATED_COMPOSITING) if (m_gpuCanvas) { CanvasLayerChromium* layer = static_cast<CanvasLayerChromium*>(m_gpuCanvas->context()->platformLayer()); layer->setPrepareTextureCallback(0); @@ -684,7 +678,6 @@ void PlatformContextSkia::applyAntiAliasedClipPaths(WTF::Vector<SkPath>& paths) m_canvas->restore(); } -#if USE(GLES2_RENDERING) #if USE(ACCELERATED_COMPOSITING) class PrepareTextureCallbackImpl : public CanvasLayerChromium::PrepareTextureCallback { public: @@ -793,7 +786,7 @@ void PlatformContextSkia::uploadSoftwareToHardware(CompositeOperator op) const SkAutoLockPixels lock(bitmap); GraphicsContext3D* context = m_gpuCanvas->context(); if (!m_uploadTexture || m_uploadTexture->tiles().totalSizeX() < bitmap.width() || m_uploadTexture->tiles().totalSizeY() < bitmap.height()) - m_uploadTexture = GLES2Texture::create(context, GLES2Texture::BGRA8, bitmap.width(), bitmap.height()); + m_uploadTexture = Texture::create(context, Texture::BGRA8, bitmap.width(), bitmap.height()); m_uploadTexture->load(bitmap.getPixels()); IntRect rect(0, 0, bitmap.width(), bitmap.height()); AffineTransform identity; @@ -823,5 +816,4 @@ void PlatformContextSkia::readbackHardwareToSoftware() const } } -#endif } // namespace WebCore diff --git a/WebCore/platform/graphics/skia/PlatformContextSkia.h b/WebCore/platform/graphics/skia/PlatformContextSkia.h index 6c84797..82edc16 100644 --- a/WebCore/platform/graphics/skia/PlatformContextSkia.h +++ b/WebCore/platform/graphics/skia/PlatformContextSkia.h @@ -35,22 +35,20 @@ #include "Noncopyable.h" #include "SkDashPathEffect.h" -#include "SkDrawLooper.h" #include "SkDeque.h" -#include "skia/ext/platform_canvas.h" +#include "SkDrawLooper.h" #include "SkPaint.h" #include "SkPath.h" +#include "skia/ext/platform_canvas.h" #include <wtf/Vector.h> namespace WebCore { -#if USE(GLES2_RENDERING) enum CompositeOperator; class GLES2Canvas; -class GLES2Texture; +class Texture; class GraphicsContext3D; -#endif // This class holds the platform-specific state for GraphicsContext. We put // most of our Skia wrappers on this class. In theory, a lot of this stuff could @@ -182,24 +180,16 @@ public: void setImageResamplingHint(const IntSize& srcSize, const FloatSize& dstSize); void clearImageResamplingHint(); bool hasImageResamplingHint() const; -#if USE(GLES2_RENDERING) bool useGPU() { return m_useGPU; } void setGraphicsContext3D(GraphicsContext3D*, const IntSize&); GLES2Canvas* gpuCanvas() const { return m_gpuCanvas.get(); } -#endif -#if USE(GLES2_RENDERING) // Call these before making a call that manipulates the underlying // skia::PlatformCanvas or WebCore::GLES2Canvas void prepareForSoftwareDraw() const; void prepareForHardwareDraw() const; // Call to force the skia::PlatformCanvas to contain all rendering results. void syncSoftwareCanvas() const; -#else - void prepareForSoftwareDraw() const {} - void prepareForHardwareDraw() const {} - void syncSoftwareCanvas() const {} -#endif private: #if OS(LINUX) || OS(WINDOWS) @@ -209,10 +199,8 @@ private: #endif void applyAntiAliasedClipPaths(WTF::Vector<SkPath>& paths); -#if USE(GLES2_RENDERING) void uploadSoftwareToHardware(CompositeOperator) const; void readbackHardwareToSoftware() const; -#endif // Defines drawing style. struct State; @@ -237,12 +225,10 @@ private: #if OS(WINDOWS) bool m_drawingToImageBuffer; #endif -#if USE(GLES2_RENDERING) bool m_useGPU; OwnPtr<GLES2Canvas> m_gpuCanvas; mutable enum { None, Software, Mixed, Hardware } m_backingStoreState; - mutable RefPtr<GLES2Texture> m_uploadTexture; -#endif + mutable RefPtr<Texture> m_uploadTexture; }; } diff --git a/WebCore/platform/graphics/skia/SkiaFontWin.cpp b/WebCore/platform/graphics/skia/SkiaFontWin.cpp index 44003bb..9edb775 100644 --- a/WebCore/platform/graphics/skia/SkiaFontWin.cpp +++ b/WebCore/platform/graphics/skia/SkiaFontWin.cpp @@ -222,11 +222,11 @@ void SkiaWinOutlineCache::removePathsForFont(HFONT hfont) bool windowsCanHandleDrawTextShadow(GraphicsContext *context) { - FloatSize shadowSize; + FloatSize shadowOffset; float shadowBlur; Color shadowColor; - bool hasShadow = context->getShadow(shadowSize, shadowBlur, shadowColor); + bool hasShadow = context->getShadow(shadowOffset, shadowBlur, shadowColor); return (hasShadow && (shadowBlur == 0) && (shadowColor.alpha() == 255) && (context->fillColor().alpha() == 255)); } |