Diff
Modified: trunk/Source/WebCore/ChangeLog (112669 => 112670)
--- trunk/Source/WebCore/ChangeLog 2012-03-30 15:47:04 UTC (rev 112669)
+++ trunk/Source/WebCore/ChangeLog 2012-03-30 15:57:26 UTC (rev 112670)
@@ -1,3 +1,39 @@
+2012-03-30 Malcolm MacLeod <[email protected]>
+
+ [wx] Implement Gradient and ImageBuffer support.
+ https://bugs.webkit.org/show_bug.cgi?id=82710
+
+ Reviewed by Kevin Ollivier.
+
+ * platform/graphics/BitmapImage.h:
+ (BitmapImage):
+ (WebCore::BitmapImage::create):
+ * platform/graphics/Gradient.h:
+ * platform/graphics/wx/GradientWx.cpp:
+ (WebCore::Gradient::platformDestroy):
+ (WebCore::Gradient::platformGradient):
+ (WebCore::Gradient::fill):
+ * platform/graphics/wx/ImageBufferDataWx.h:
+ (ImageBufferData):
+ * platform/graphics/wx/ImageBufferWx.cpp:
+ (WebCore):
+ (WebCore::ImageBufferData::ImageBufferData):
+ (WebCore::ImageBufferData::~ImageBufferData):
+ (WebCore::ImageBuffer::ImageBuffer):
+ (WebCore::ImageBuffer::~ImageBuffer):
+ (WebCore::ImageBuffer::context):
+ (WebCore::ImageBuffer::toDataURL):
+ (WebCore::ImageBuffer::copyImage):
+ (WebCore::ImageBuffer::clip):
+ (WebCore::ImageBuffer::draw):
+ (WebCore::ImageBuffer::drawPattern):
+ * platform/graphics/wx/ImageWx.cpp:
+ (WebCore::BitmapImage::BitmapImage):
+ (WebCore):
+ (WebCore::BitmapImage::draw):
+ * platform/wx/LocalDC.h:
+ (WebCore):
+
2012-03-30 Allan Sandfeld Jensen <[email protected]>
[Qt] Find zoomable area using area-based hit-testing
Modified: trunk/Source/WebCore/platform/graphics/BitmapImage.h (112669 => 112670)
--- trunk/Source/WebCore/platform/graphics/BitmapImage.h 2012-03-30 15:47:04 UTC (rev 112669)
+++ trunk/Source/WebCore/platform/graphics/BitmapImage.h 2012-03-30 15:57:26 UTC (rev 112670)
@@ -41,6 +41,10 @@
typedef struct HBITMAP__ *HBITMAP;
#endif
+#if PLATFORM(WX)
+class wxBitmap;
+#endif
+
namespace WebCore {
struct FrameData;
}
@@ -142,6 +146,12 @@
#if PLATFORM(WIN) || (PLATFORM(QT) && OS(WINDOWS))
static PassRefPtr<BitmapImage> create(HBITMAP);
#endif
+#if PLATFORM(WX)
+ static PassRefPtr<BitmapImage> create(const wxBitmap& bitmap)
+ {
+ return adoptRef(new BitmapImage(bitmap));
+ }
+#endif
#if PLATFORM(WIN)
virtual bool getHBITMAP(HBITMAP);
virtual bool getHBITMAPOfSize(HBITMAP, LPSIZE);
@@ -168,6 +178,9 @@
BitmapImage(NativeImagePtr, ImageObserver* = 0);
BitmapImage(ImageObserver* = 0);
+#if PLATFORM(WX)
+ BitmapImage(const wxBitmap&);
+#endif
#if PLATFORM(WIN)
virtual void drawFrameMatchingSourceSize(GraphicsContext*, const FloatRect& dstRect, const IntSize& srcSize, ColorSpace styleColorSpace, CompositeOperator);
Modified: trunk/Source/WebCore/platform/graphics/Gradient.h (112669 => 112670)
--- trunk/Source/WebCore/platform/graphics/Gradient.h 2012-03-30 15:47:04 UTC (rev 112669)
+++ trunk/Source/WebCore/platform/graphics/Gradient.h 2012-03-30 15:57:26 UTC (rev 112670)
@@ -61,6 +61,9 @@
class SkShader;
typedef class SkShader* PlatformGradient;
typedef class SkShader* PlatformPattern;
+#elif PLATFORM(WX)
+class wxGraphicsBrush;
+typedef wxGraphicsBrush* PlatformGradient;
#else
typedef void* PlatformGradient;
#endif
Modified: trunk/Source/WebCore/platform/graphics/wx/GradientWx.cpp (112669 => 112670)
--- trunk/Source/WebCore/platform/graphics/wx/GradientWx.cpp 2012-03-30 15:47:04 UTC (rev 112669)
+++ trunk/Source/WebCore/platform/graphics/wx/GradientWx.cpp 2012-03-30 15:57:26 UTC (rev 112670)
@@ -27,24 +27,81 @@
#include "Gradient.h"
#include "CSSParser.h"
+#include "GraphicsContext.h"
#include "NotImplemented.h"
+#include <algorithm>
+
+#include <wx/dc.h>
+#include <wx/dcgraph.h>
+#include <wx/graphics.h>
+
+using namespace std;
+
namespace WebCore {
void Gradient::platformDestroy()
{
- notImplemented();
+ delete m_gradient;
}
PlatformGradient Gradient::platformGradient()
{
- notImplemented();
- return 0;
+ if (m_gradient)
+ return m_gradient;
+
+#if wxCHECK_VERSION(2, 9, 1)
+ sortStopsIfNecessary();
+
+ wxGraphicsRenderer* renderer = 0;
+#if wxUSE_CAIRO
+ renderer = wxGraphicsRenderer::GetCairoRenderer();
+#else
+ renderer = wxGraphicsRenderer::GetDefaultRenderer();
+#endif
+ if (renderer) {
+ wxGraphicsGradientStops stops;
+ Vector<ColorStop>::iterator stopIterator = m_stops.begin();
+ int numStops = 0;
+ stops.SetStartColour(wxColour(255*stopIterator->red, 255*stopIterator->green, 255*stopIterator->blue, 255*stopIterator->alpha));
+
+ while (stopIterator != m_stops.end()) {
+ double position = stopIterator->stop;
+ if (m_radial && m_r0)
+ position = min((m_r0 / m_r1+position*(1.0f-m_r0 / m_r1)), 1.0);
+ stops.Add(wxGraphicsGradientStop(wxColour(255*stopIterator->red, 255*stopIterator->green, 255*stopIterator->blue, 255*stopIterator->alpha), position));
+ stopIterator++;
+ numStops++;
+ }
+ stopIterator--;
+ stops.SetEndColour(wxColour(255*stopIterator->red, 255*stopIterator->green, 255*stopIterator->blue, 255*stopIterator->alpha));
+
+ wxGraphicsBrush gradient;
+ if (numStops >= 2) {
+ if (m_radial)
+ gradient = renderer->CreateRadialGradientBrush(m_p1.x(), m_p1.y(), m_p0.x(), m_p0.y(), m_r1, stops);
+ else
+ gradient = renderer->CreateLinearGradientBrush(m_p0.x(), m_p0.y(), m_p1.x(), m_p1.y(), stops);
+ }
+ m_gradient = new wxGraphicsBrush(gradient);
+ }
+#endif
+ return m_gradient;
}
-void Gradient::fill(GraphicsContext*, const FloatRect&)
-{
- notImplemented();
+void Gradient::fill(GraphicsContext* c, const FloatRect& r)
+{
+#if wxCHECK_VERSION(2, 9, 1)
+ wxGCDC* context = dynamic_cast<wxGCDC*>(c->platformContext());
+
+ if (!context)
+ return;
+ wxGraphicsContext* gradientContext = context->GetGraphicsContext();
+
+ gradientContext->SetPen(*wxTRANSPARENT_PEN);
+ gradientContext->SetBrush(*platformGradient());
+ gradientContext->DrawRectangle(r.x(), r.y(), r.width(), r.height());
+#endif
}
} //namespace
Modified: trunk/Source/WebCore/platform/graphics/wx/ImageBufferDataWx.h (112669 => 112670)
--- trunk/Source/WebCore/platform/graphics/wx/ImageBufferDataWx.h 2012-03-30 15:47:04 UTC (rev 112669)
+++ trunk/Source/WebCore/platform/graphics/wx/ImageBufferDataWx.h 2012-03-30 15:57:26 UTC (rev 112670)
@@ -25,6 +25,13 @@
#include <wtf/OwnPtr.h>
+#include <wx/bitmap.h>
+#include <wx/dcmemory.h>
+
+class wxGCDC;
+class wxGraphicsContext;
+class wxMemoryDC;
+
namespace WebCore {
class IntSize;
@@ -32,6 +39,11 @@
class ImageBufferData {
public:
ImageBufferData(const IntSize&);
+ ~ImageBufferData();
+ wxBitmap m_bitmap;
+ wxMemoryDC* m_memDC;
+ wxGCDC* m_gcdc;
+ wxGraphicsContext* m_graphics;
};
} // namespace WebCore
Modified: trunk/Source/WebCore/platform/graphics/wx/ImageBufferWx.cpp (112669 => 112670)
--- trunk/Source/WebCore/platform/graphics/wx/ImageBufferWx.cpp 2012-03-30 15:47:04 UTC (rev 112669)
+++ trunk/Source/WebCore/platform/graphics/wx/ImageBufferWx.cpp 2012-03-30 15:57:26 UTC (rev 112670)
@@ -27,31 +27,96 @@
#include "config.h"
#include "ImageBuffer.h"
+#include "Base64.h"
+#include "BitmapImage.h"
#include "GraphicsContext.h"
+#include "Image.h"
#include "ImageData.h"
#include "NotImplemented.h"
+#include "UnusedParam.h"
+#include <wtf/UnusedParam.h>
+// see http://trac.wxwidgets.org/ticket/11482
+#ifdef __WXMSW__
+# include "wx/msw/winundef.h"
+#endif
+
+#include <wx/defs.h>
+#include <wx/bitmap.h>
+#include <wx/dc.h>
+#include <wx/dcgraph.h>
+#include <wx/dcmemory.h>
+#include <wx/graphics.h>
+#include <wx/image.h>
+#include <wx/rawbmp.h>
+
+
namespace WebCore {
-ImageBufferData::ImageBufferData(const IntSize&)
+ImageBufferData::ImageBufferData(const IntSize& size)
{
+ m_bitmap.Create(size.width(), size.height(), 32);
+ {
+ wxAlphaPixelData pixData(m_bitmap, wxPoint(0, 0), wxSize(size.width(), size.height()));
+ ASSERT(pixData);
+ if (pixData) {
+ wxAlphaPixelData::Iterator p(pixData);
+ for (int y = 0; y < size.height(); y++) {
+ wxAlphaPixelData::Iterator rowStart = p;
+ for (int x = 0; x < size.width(); x++) {
+ p.Red() = 0;
+ p.Blue() = 0;
+ p.Green() = 0;
+ // FIXME: The below should be transparent but cannot be on GDI/GDK (see wxWidgets bugs #10066 and #2474)
+#if wxUSE_CAIRO || defined(__WXMAC__)
+ p.Alpha() = 0;
+#endif
+ ++p;
+ }
+ p = rowStart;
+ p.OffsetY(pixData, 1);
+ }
+ }
+ }
+ // http://www.w3.org/TR/2009/WD-html5-20090212/the-canvas-element.html#canvaspixelarray
+ // "When the canvas is initialized it must be set to fully transparent black."
+
+ m_memDC = new wxMemoryDC(m_bitmap);
+ wxGraphicsRenderer* renderer = wxGraphicsRenderer::GetCairoRenderer();
+ if (!renderer)
+ renderer = wxGraphicsRenderer::GetDefaultRenderer();
+ m_graphics = renderer->CreateContext(*m_memDC);
+ m_gcdc = new wxGCDC(m_graphics);
}
-ImageBuffer::ImageBuffer(const IntSize&, ColorSpace imageColorSpace, RenderingMode, DeferralMode, bool& success) :
- m_data(IntSize())
+ImageBufferData::~ImageBufferData()
{
- notImplemented();
- success = false;
+ delete m_gcdc;
+ delete m_memDC;
}
+ImageBuffer::ImageBuffer(const IntSize& size, ColorSpace colorSpace, RenderingMode, DeferralMode, bool& success)
+ : m_data(size)
+ , m_size(size)
+{
+ // FIXME: colorSpace is not used
+ UNUSED_PARAM(colorSpace);
+
+ if (m_data.m_gcdc->IsOk()) {
+ m_context = adoptPtr(new WebCore::GraphicsContext(m_data.m_gcdc));
+ success = true;
+ } else
+ success = false;
+}
+
ImageBuffer::~ImageBuffer()
{
+
}
GraphicsContext* ImageBuffer::context() const
{
- notImplemented();
- return 0;
+ return m_context.get();
}
PassRefPtr<ByteArray> ImageBuffer::getUnmultipliedImageData(const IntRect& rect) const
@@ -70,8 +135,8 @@
{
notImplemented();
}
-
-String ImageBuffer::toDataURL(const String&, const double*) const
+
+String ImageBuffer::toDataURL(const String& mimeType, const double*) const
{
notImplemented();
return String();
@@ -80,17 +145,17 @@
PassRefPtr<Image> ImageBuffer::copyImage(BackingStoreCopy copyBehavior) const
{
ASSERT(copyBehavior == CopyBackingStore);
- notImplemented();
- return 0;
+
+ RefPtr<BitmapImage> img = BitmapImage::create(m_data.m_bitmap);
+ return img.release();
}
-void ImageBuffer::clip(GraphicsContext*, const FloatRect&) const
+void ImageBuffer::clip(GraphicsContext* context, const FloatRect& rect) const
{
- notImplemented();
+ context->clip(rect);
}
-void ImageBuffer::draw(GraphicsContext* context, ColorSpace styleColorSpace, const FloatRect& destRect, const FloatRect& srcRect,
- CompositeOperator op, bool useLowQualityScale)
+void ImageBuffer::draw(GraphicsContext* context, ColorSpace styleColorSpace, const FloatRect& destRect, const FloatRect& srcRect, CompositeOperator op, bool useLowQualityScale)
{
RefPtr<Image> imageCopy = copyImage(CopyBackingStore);
context->drawImage(imageCopy.get(), styleColorSpace, destRect, srcRect, op, useLowQualityScale);
@@ -99,6 +164,7 @@
void ImageBuffer::drawPattern(GraphicsContext* context, const FloatRect& srcRect, const AffineTransform& patternTransform,
const FloatPoint& phase, ColorSpace styleColorSpace, CompositeOperator op, const FloatRect& destRect)
{
+ ASSERT(context);
RefPtr<Image> imageCopy = copyImage(CopyBackingStore);
imageCopy->drawPattern(context, srcRect, patternTransform, phase, styleColorSpace, op, destRect);
}
Modified: trunk/Source/WebCore/platform/graphics/wx/ImageWx.cpp (112669 => 112670)
--- trunk/Source/WebCore/platform/graphics/wx/ImageWx.cpp 2012-03-30 15:47:04 UTC (rev 112669)
+++ trunk/Source/WebCore/platform/graphics/wx/ImageWx.cpp 2012-03-30 15:57:26 UTC (rev 112670)
@@ -85,13 +85,51 @@
// FIXME: NYI
}
+BitmapImage::BitmapImage(const wxBitmap& bitmap)
+ : Image(0)
+ , m_currentFrame(0)
+ , m_frames(0)
+ , m_frameTimer(0)
+ , m_repetitionCount(cAnimationNone)
+ , m_repetitionCountStatus(Unknown)
+ , m_repetitionsComplete(0)
+ , m_isSolidColor(false)
+ , m_checkedForSolidColor(false)
+ , m_animationFinished(true)
+ , m_allDataReceived(true)
+ , m_haveSize(true)
+ , m_sizeAvailable(true)
+ , m_decodedSize(0)
+ , m_haveFrameCount(true)
+ , m_frameCount(1)
+{
+ initPlatformData();
+
+ m_decodedSize = bitmap.GetWidth() * bitmap.GetHeight() * 4;
+ m_size = IntSize(bitmap.GetWidth(), bitmap.GetHeight());
+
+ wxGraphicsRenderer* renderer = 0;
+#if wxUSE_CAIRO
+ renderer = wxGraphicsRenderer::GetCairoRenderer();
+#else
+ renderer = wxGraphicsRenderer::GetDefaultRenderer();
+#endif
+ if (renderer) {
+ wxGraphicsBitmap* gbmp = new wxGraphicsBitmap(renderer->CreateBitmap(bitmap));
+ ASSERT(!gbmp->IsNull());
+
+ m_frames.grow(1);
+ m_frames[0].m_frame = gbmp;
+ m_frames[0].m_haveMetadata = true;
+ checkForSolidColor();
+ }
+}
+
+
// Drawing Routines
void BitmapImage::draw(GraphicsContext* ctxt, const FloatRect& dst, const FloatRect& src, ColorSpace styleColorSpace, CompositeOperator op)
{
- if (!m_source.initialized())
- return;
-
if (mayFillWithSolidColor()) {
fillWithSolidColor(ctxt, dst, solidColor(), styleColorSpace, op);
return;
Modified: trunk/Source/WebCore/platform/wx/LocalDC.h (112669 => 112670)
--- trunk/Source/WebCore/platform/wx/LocalDC.h 2012-03-30 15:47:04 UTC (rev 112669)
+++ trunk/Source/WebCore/platform/wx/LocalDC.h 2012-03-30 15:57:26 UTC (rev 112670)
@@ -23,20 +23,22 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
+#ifndef LocalDC_h
+#define LocalDC_h
+
#include "IntRect.h"
#include <wtf/Assertions.h>
#include <wx/defs.h>
+#include <wx/bitmap.h>
#include <wx/dc.h>
#include <wx/dcmemory.h>
#include <wx/rawbmp.h>
namespace WebCore {
-wxBitmap* transparentBitmap(int width, int height);
-
class LocalDC {
public:
@@ -102,3 +104,4 @@
}
+#endif // LocalDC_h