Skip to content
Permalink
Browse files
2011-04-12 Alok Priyadarshi <alokp@chromium.org>
        Reviewed by James Robinson.

        Remove dependency on chromium skia::PlatformCanvas
        https://bugs.webkit.org/show_bug.cgi?id=57563

        This patch does not change any functionality, just the type of object skia::PlatformCanvas -> SkCanvas.
        The object is still being created by a factory method skia::CreateBitmapCanvas defined in Chromium.
        We will eventually define an API that every port using skia will define.

        * platform/graphics/chromium/FontChromiumWin.cpp:
        (WebCore::TransparencyAwareFontPainter::TransparencyAwareFontPainter::initializeForGDI):
        (WebCore::TransparencyAwareFontPainter::TransparencyAwareFontPainter::~TransparencyAwareFontPainter):
        (WebCore::Font::drawComplexText):
        * platform/graphics/chromium/ImageBufferData.h:
        * platform/graphics/chromium/LayerChromium.h:
        * platform/graphics/chromium/LayerRendererChromium.h:
        * platform/graphics/chromium/PlatformCanvas.cpp:
        (WebCore::PlatformCanvas::resize):
        * platform/graphics/chromium/PlatformCanvas.h:
        * platform/graphics/chromium/TransparencyWin.cpp:
        (WebCore::TransparencyWin::compositeTextComposite):
        (WebCore::TransparencyWin::makeLayerOpaque):
        * platform/graphics/skia/ImageBufferSkia.cpp:
        (WebCore::ImageBuffer::ImageBuffer):
        * platform/graphics/skia/ImageSkia.cpp:
        (WebCore::paintSkBitmap):
        (WebCore::Image::drawPattern):
        * platform/graphics/skia/PlatformContextSkia.cpp:
        (WebCore::PlatformContextSkia::PlatformContextSkia):
        (WebCore::PlatformContextSkia::setCanvas):
        (WebCore::PlatformContextSkia::isNativeFontRenderingAllowed):
        * platform/graphics/skia/PlatformContextSkia.h:
        (WebCore::PlatformContextSkia::canvas):
        (WebCore::PlatformContextSkia::printing):
        (WebCore::PlatformContextSkia::setPrinting):
2011-04-12  Alok Priyadarshi  <alokp@chromium.org>

        Reviewed by James Robinson.

        Remove dependency on chromium skia::PlatformCanvas
        https://bugs.webkit.org/show_bug.cgi?id=57563

        * public/WebCanvas.h:
        * src/WebFrameImpl.cpp:
        (WebKit::WebFrameImpl::printPage):
        * tests/TransparencyWinTest.cpp:
        (WebCore::drawNativeRect):
        (WebCore::getPixelAt):
        (WebCore::clearTopLayerAlphaChannel):
        (WebCore::clearTopLayerAlphaPixel):
        (WebCore::TEST):

Canonical link: https://commits.webkit.org/73409@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@83649 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
webkit-commit-queue committed Apr 12, 2011
1 parent 61996e5 commit ecdc78fa771170e46486ab924d4a534d7edf188b
Showing 16 changed files with 113 additions and 59 deletions.
@@ -1,3 +1,41 @@
2011-04-12 Alok Priyadarshi <alokp@chromium.org>

Reviewed by James Robinson.

Remove dependency on chromium skia::PlatformCanvas
https://bugs.webkit.org/show_bug.cgi?id=57563

This patch does not change any functionality, just the type of object skia::PlatformCanvas -> SkCanvas.
The object is still being created by a factory method skia::CreateBitmapCanvas defined in Chromium.
We will eventually define an API that every port using skia will define.

* platform/graphics/chromium/FontChromiumWin.cpp:
(WebCore::TransparencyAwareFontPainter::TransparencyAwareFontPainter::initializeForGDI):
(WebCore::TransparencyAwareFontPainter::TransparencyAwareFontPainter::~TransparencyAwareFontPainter):
(WebCore::Font::drawComplexText):
* platform/graphics/chromium/ImageBufferData.h:
* platform/graphics/chromium/LayerChromium.h:
* platform/graphics/chromium/LayerRendererChromium.h:
* platform/graphics/chromium/PlatformCanvas.cpp:
(WebCore::PlatformCanvas::resize):
* platform/graphics/chromium/PlatformCanvas.h:
* platform/graphics/chromium/TransparencyWin.cpp:
(WebCore::TransparencyWin::compositeTextComposite):
(WebCore::TransparencyWin::makeLayerOpaque):
* platform/graphics/skia/ImageBufferSkia.cpp:
(WebCore::ImageBuffer::ImageBuffer):
* platform/graphics/skia/ImageSkia.cpp:
(WebCore::paintSkBitmap):
(WebCore::Image::drawPattern):
* platform/graphics/skia/PlatformContextSkia.cpp:
(WebCore::PlatformContextSkia::PlatformContextSkia):
(WebCore::PlatformContextSkia::setCanvas):
(WebCore::PlatformContextSkia::isNativeFontRenderingAllowed):
* platform/graphics/skia/PlatformContextSkia.h:
(WebCore::PlatformContextSkia::canvas):
(WebCore::PlatformContextSkia::printing):
(WebCore::PlatformContextSkia::setPrinting):

2011-04-11 Stephanie Lewis <slewis@apple.com>

Reviewed by Oliver Hunt.
@@ -165,7 +165,7 @@ void TransparencyAwareFontPainter::initializeForGDI()

// Set up the DC, using the one from the transparency helper.
if (m_transparency.platformContext()) {
m_hdc = m_transparency.platformContext()->canvas()->beginPlatformPaint();
m_hdc = skia::BeginPlatformPaint(m_transparency.platformContext()->canvas());
SetTextColor(m_hdc, skia::SkColorToCOLORREF(color));
SetBkMode(m_hdc, TRANSPARENT);
}
@@ -179,7 +179,7 @@ TransparencyAwareFontPainter::~TransparencyAwareFontPainter()
if (m_createdTransparencyLayer)
m_graphicsContext->endTransparencyLayer();
m_graphicsContext->restore();
m_platformContext->canvas()->endPlatformPaint();
skia::EndPlatformPaint(m_platformContext->canvas());
}

// Specialization for simple GlyphBuffer painting.
@@ -542,7 +542,7 @@ void Font::drawComplexText(GraphicsContext* graphicsContext,
// the baseline, so we have to subtract off the ascent.
state.draw(graphicsContext, hdc, lroundf(point.x()), lroundf(point.y() - fontMetrics().ascent()), from, to);

context->canvas()->endPlatformPaint();
skia::EndPlatformPaint(context->canvas());
}

void Font::drawEmphasisMarksForComplexText(GraphicsContext* /* context */, const TextRun& /* run */, const AtomicString& /* mark */, const FloatPoint& /* point */, int /* from */, int /* to */) const
@@ -33,15 +33,13 @@

#include "PlatformContextSkia.h"

#include "skia/ext/platform_canvas.h"

namespace WebCore {

class ImageBufferData {
public:
ImageBufferData(const IntSize&);

skia::PlatformCanvas m_canvas;
OwnPtr<SkCanvas> m_canvas;
PlatformContextSkia m_platformContext;
};

@@ -50,11 +50,6 @@
#include <wtf/text/StringHash.h>
#include <wtf/text/WTFString.h>


namespace skia {
class PlatformCanvas;
}

namespace WebCore {

class CCLayerImpl;
@@ -194,7 +194,7 @@ class LayerRendererChromium : public RefCounted<LayerRendererChromium> {
bool m_compositeOffscreen;

#if USE(SKIA)
OwnPtr<skia::PlatformCanvas> m_rootLayerCanvas;
OwnPtr<SkCanvas> m_rootLayerCanvas;
OwnPtr<PlatformContextSkia> m_rootLayerSkiaContext;
OwnPtr<GraphicsContext> m_rootLayerGraphicsContext;
#elif PLATFORM(CG)
@@ -52,7 +52,7 @@ void PlatformCanvas::resize(const IntSize& size)
{
m_size = size;
#if USE(SKIA)
m_skiaCanvas = new skia::PlatformCanvas(size.width(), size.height(), false);
m_skiaCanvas = skia::CreateBitmapCanvas(size.width(), size.height(), false);
#elif PLATFORM(CG)
size_t bufferSize = size.width() * size.height() * 4;
m_pixelData = adoptArrayPtr(new uint8_t[bufferSize]);
@@ -39,8 +39,8 @@
#endif

#if USE(SKIA)
namespace skia { class PlatformCanvas; }
class SkBitmap;
class SkCanvas;
#endif

namespace WebCore {
@@ -97,7 +97,7 @@ class PlatformCanvas {

private:
#if USE(SKIA)
OwnPtr<skia::PlatformCanvas> m_skiaCanvas;
OwnPtr<SkCanvas> m_skiaCanvas;
#elif PLATFORM(CG)
OwnArrayPtr<uint8_t> m_pixelData;
#endif
@@ -49,14 +49,14 @@ namespace {
// into. Buffers larger than this will be destroyed when we're done with them.
const int maxCachedBufferPixelSize = 65536;

inline skia::PlatformCanvas* canvasForContext(const GraphicsContext& context)
inline SkCanvas* canvasForContext(const GraphicsContext& context)
{
return context.platformContext()->canvas();
}

inline const SkBitmap& bitmapForContext(const GraphicsContext& context)
{
return canvasForContext(context)->getTopPlatformDevice().accessBitmap(false);
return canvasForContext(context)->getTopDevice()->accessBitmap(false);
}

void compositeToCopy(const GraphicsContext& sourceLayers,
@@ -466,7 +466,7 @@ void TransparencyWin::compositeTextComposite()
if (!m_validLayer)
return;

const SkBitmap& bitmap = m_layerBuffer->context()->platformContext()->canvas()->getTopPlatformDevice().accessBitmap(true);
const SkBitmap& bitmap = m_layerBuffer->context()->platformContext()->canvas()->getTopDevice()->accessBitmap(true);
SkColor textColor = m_textCompositeColor.rgb();
for (int y = 0; y < m_layerSize.height(); y++) {
uint32_t* row = bitmap.getAddr32(0, y);
@@ -502,7 +502,7 @@ void TransparencyWin::makeLayerOpaque()
return;

SkBitmap& bitmap = const_cast<SkBitmap&>(m_drawContext->platformContext()->
canvas()->getTopPlatformDevice().accessBitmap(true));
canvas()->getTopDevice()->accessBitmap(true));
for (int y = 0; y < m_layerSize.height(); y++) {
uint32_t* row = bitmap.getAddr32(0, y);
for (int x = 0; x < m_layerSize.width(); x++)
@@ -66,19 +66,21 @@ ImageBuffer::ImageBuffer(const IntSize& size, ColorSpace, RenderingMode, bool& s
: m_data(size)
, m_size(size)
{
if (!m_data.m_canvas.initialize(size.width(), size.height(), false)) {
SkCanvas* canvas = skia::CreateBitmapCanvas(size.width(), size.height(), false);
if (!canvas) {
success = false;
return;
}

m_data.m_platformContext.setCanvas(&m_data.m_canvas);
m_data.m_canvas = canvas;
m_data.m_platformContext.setCanvas(m_data.m_canvas.get());
m_context.set(new GraphicsContext(&m_data.m_platformContext));
m_context->platformContext()->setDrawingToImageBuffer(true);

// Make the background transparent. It would be nice if this wasn't
// required, but the canvas is currently filled with the magic transparency
// color. Can we have another way to manage this?
m_data.m_canvas.drawARGB(0, 0, 0, 0, SkXfermode::kClear_Mode);
m_data.m_canvas->drawARGB(0, 0, 0, 0, SkXfermode::kClear_Mode);
success = true;
}

@@ -262,12 +262,17 @@ static void paintSkBitmap(PlatformContextSkia* platformContext, const NativeImag
paint.setAlpha(platformContext->getNormalizedAlpha());
paint.setLooper(platformContext->getDrawLooper());

skia::PlatformCanvas* canvas = platformContext->canvas();
SkCanvas* canvas = platformContext->canvas();

ResamplingMode resampling = platformContext->isPrinting() ? RESAMPLE_NONE :
ResamplingMode resampling;
#if ENABLE(SKIA_GPU)
resampling = RESAMPLE_LINEAR;
#else
resampling = platformContext->printing() ? RESAMPLE_NONE :
computeResamplingMode(platformContext, bitmap, srcRect.width(), srcRect.height(),
SkScalarToFloat(destRect.width()),
SkScalarToFloat(destRect.height()));
#endif
if (resampling == RESAMPLE_AWESOME) {
drawResampledBitmap(*canvas, paint, bitmap, srcRect, destRect);
} else {
@@ -363,13 +368,17 @@ void Image::drawPattern(GraphicsContext* context,

// Compute the resampling mode.
ResamplingMode resampling;
if (context->platformContext()->isPrinting())
#if ENABLE(SKIA_GPU)
resampling = RESAMPLE_LINEAR;
#else
if (context->platformContext()->printing())
resampling = RESAMPLE_LINEAR;
else {
resampling = computeResamplingMode(context->platformContext(), *bitmap,
srcRect.width(), srcRect.height(),
destBitmapWidth, destBitmapHeight);
}
#endif

// Load the transform WebKit requested.
SkMatrix matrix(patternTransform);
@@ -213,8 +213,9 @@ SkColor PlatformContextSkia::State::applyAlpha(SkColor c) const
// PlatformContextSkia ---------------------------------------------------------

// Danger: canvas can be NULL.
PlatformContextSkia::PlatformContextSkia(skia::PlatformCanvas* canvas)
PlatformContextSkia::PlatformContextSkia(SkCanvas* canvas)
: m_canvas(canvas)
, m_printing(false)
, m_drawingToImageBuffer(false)
, m_useGPU(false)
#if ENABLE(ACCELERATED_2D_CANVAS)
@@ -240,7 +241,7 @@ PlatformContextSkia::~PlatformContextSkia()
#endif
}

void PlatformContextSkia::setCanvas(skia::PlatformCanvas* canvas)
void PlatformContextSkia::setCanvas(SkCanvas* canvas)
{
m_canvas = canvas;
}
@@ -609,21 +610,12 @@ const SkBitmap* PlatformContextSkia::bitmap() const
return &m_canvas->getDevice()->accessBitmap(false);
}

bool PlatformContextSkia::isPrinting()
{
#if ENABLE(SKIA_GPU)
return true;
#else
return m_canvas->getTopPlatformDevice().IsVectorial();
#endif
}

bool PlatformContextSkia::isNativeFontRenderingAllowed()
{
#if ENABLE(SKIA_GPU)
return false;
#else
return m_canvas->getTopPlatformDevice().IsNativeFontRenderingAllowed();
return skia::SupportsPlatformPaint(m_canvas);
#endif
}

@@ -72,12 +72,12 @@ class PlatformContextSkia {
public:
// For printing, there shouldn't be any canvas. canvas can be NULL. If you
// supply a NULL canvas, you can also call setCanvas later.
PlatformContextSkia(skia::PlatformCanvas*);
PlatformContextSkia(SkCanvas*);
~PlatformContextSkia();

// Sets the canvas associated with this context. Use when supplying NULL
// to the constructor.
void setCanvas(skia::PlatformCanvas*);
void setCanvas(SkCanvas*);

// If false we're rendering to a GraphicsContext for a web page, if false
// we're not (as is the case when rendering to a canvas object).
@@ -147,7 +147,7 @@ class PlatformContextSkia {
SkColor effectiveStrokeColor() const;

// Returns the canvas used for painting, NOT guaranteed to be non-null.
skia::PlatformCanvas* canvas() { return m_canvas; }
SkCanvas* canvas() { return m_canvas; }

InterpolationQuality interpolationQuality() const;
void setInterpolationQuality(InterpolationQuality interpolationQuality);
@@ -163,7 +163,8 @@ class PlatformContextSkia {
// Returns if the context is a printing context instead of a display
// context. Bitmap shouldn't be resampled when printing to keep the best
// possible quality.
bool isPrinting();
bool printing() const { return m_printing; }
void setPrinting(bool p) { m_printing = p; }

// Returns if the context allows rendering of fonts using native platform
// APIs. If false is returned font rendering is performed using the skia
@@ -185,10 +186,10 @@ class PlatformContextSkia {
GLES2Canvas* gpuCanvas() const { return 0; }
#endif
// Call these before making a call that manipulates the underlying
// skia::PlatformCanvas or WebCore::GLES2Canvas
// SkCanvas or WebCore::GLES2Canvas
void prepareForSoftwareDraw() const;
void prepareForHardwareDraw() const;
// Call to force the skia::PlatformCanvas to contain all rendering results.
// Call to force the SkCanvas to contain all rendering results.
void syncSoftwareCanvas() const;
void markDirtyRect(const IntRect& rect);

@@ -205,7 +206,7 @@ class PlatformContextSkia {
struct State;

// NULL indicates painting is disabled. Never delete this object.
skia::PlatformCanvas* m_canvas;
SkCanvas* m_canvas;

// States stack. Enables local drawing state change with save()/restore()
// calls.
@@ -218,6 +219,7 @@ class PlatformContextSkia {
// Values are used in ImageSkia.cpp
IntSize m_imageResamplingHintSrcSize;
FloatSize m_imageResamplingHintDstSize;
bool m_printing;
bool m_drawingToImageBuffer;
bool m_useGPU;
#if ENABLE(ACCELERATED_2D_CANVAS)
@@ -1,3 +1,20 @@
2011-04-12 Alok Priyadarshi <alokp@chromium.org>

Reviewed by James Robinson.

Remove dependency on chromium skia::PlatformCanvas
https://bugs.webkit.org/show_bug.cgi?id=57563

* public/WebCanvas.h:
* src/WebFrameImpl.cpp:
(WebKit::WebFrameImpl::printPage):
* tests/TransparencyWinTest.cpp:
(WebCore::drawNativeRect):
(WebCore::getPixelAt):
(WebCore::clearTopLayerAlphaChannel):
(WebCore::clearTopLayerAlphaPixel):
(WebCore::TEST):

2011-04-12 Adam Barth <abarth@webkit.org>

Revert unintentional changes to WebKit.
@@ -34,15 +34,15 @@
#include "WebCommon.h"

#if WEBKIT_USING_SKIA
namespace skia { class PlatformCanvas; }
class SkCanvas;
#elif WEBKIT_USING_CG
struct CGContext;
#endif

namespace WebKit {

#if WEBKIT_USING_SKIA
typedef skia::PlatformCanvas WebCanvas;
typedef SkCanvas WebCanvas;
#elif WEBKIT_USING_CG
typedef struct CGContext WebCanvas;
#else
@@ -1409,7 +1409,13 @@ float WebFrameImpl::printPage(int page, WebCanvas* canvas)
return 0;
}

return m_printContext->spoolPage(GraphicsContextBuilder(canvas).context(), page);
GraphicsContextBuilder builder(canvas);
GraphicsContext& gc = builder.context();
#if WEBKIT_USING_SKIA
gc.platformContext()->setPrinting(true);
#endif

return m_printContext->spoolPage(gc, page);
}

void WebFrameImpl::printEnd()

0 comments on commit ecdc78f

Please sign in to comment.