summaryrefslogtreecommitdiffstats
path: root/WebCore/platform/graphics/wince/GraphicsContextWinCE.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'WebCore/platform/graphics/wince/GraphicsContextWinCE.cpp')
-rw-r--r--WebCore/platform/graphics/wince/GraphicsContextWinCE.cpp161
1 files changed, 66 insertions, 95 deletions
diff --git a/WebCore/platform/graphics/wince/GraphicsContextWinCE.cpp b/WebCore/platform/graphics/wince/GraphicsContextWinCE.cpp
index a91b988..a0c10fc 100644
--- a/WebCore/platform/graphics/wince/GraphicsContextWinCE.cpp
+++ b/WebCore/platform/graphics/wince/GraphicsContextWinCE.cpp
@@ -1,5 +1,6 @@
/*
* Copyright (C) 2007-2009 Torch Mobile Inc.
+ * Copyright (C) 2010 Patrick Gansterer <paroga@paroga.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
@@ -24,6 +25,7 @@
#include "AffineTransform.h"
#include "CharacterNames.h"
#include "Font.h"
+#include "GDIExtras.h"
#include "GlyphBuffer.h"
#include "Gradient.h"
#include "GraphicsContextPrivate.h"
@@ -322,8 +324,7 @@ public:
if (hdc == m_dc)
return;
-#if !defined(NO_ALPHABLEND)
- if (alphaPaint == AlphaPaintOther) {
+ if (alphaPaint == AlphaPaintOther && hasAlphaBlendSupport()) {
ASSERT(bmp && bmp->bytes() && bmp->is32bit());
unsigned* pixels = (unsigned*)bmp->bytes();
const unsigned* const pixelsEnd = pixels + bmp->bitmapInfo().numPixels();
@@ -332,13 +333,13 @@ public:
++pixels;
}
}
- if (m_opacity < 1. || alphaPaint == AlphaPaintOther) {
+ if ((m_opacity < 1. || alphaPaint == AlphaPaintOther) && hasAlphaBlendSupport()) {
const BLENDFUNCTION blend = { AC_SRC_OVER, 0
, m_opacity >= 1. ? 255 : (BYTE)(m_opacity * 255)
, alphaPaint == AlphaPaintNone ? 0 : AC_SRC_ALPHA };
- AlphaBlend(m_dc, origRect.x(), origRect.y(), origRect.width(), origRect.height(), hdc, 0, 0, bmpRect.right, bmpRect.bottom, blend);
+ bool success = alphaBlendIfSupported(m_dc, origRect.x(), origRect.y(), origRect.width(), origRect.height(), hdc, 0, 0, bmpRect.right, bmpRect.bottom, blend);
+ ASSERT_UNUSED(success, success);
} else
-#endif
StretchBlt(m_dc, origRect.x(), origRect.y(), origRect.width(), origRect.height(), hdc, 0, 0, bmpRect.right, bmpRect.bottom, SRCCOPY);
}
@@ -347,7 +348,7 @@ public:
Vector<GraphicsContextPlatformPrivateData> m_backupData;
};
-static HPEN createPen(const Color& col, double fWidth, StrokeStyle style)
+static PassOwnPtr<HPEN> createPen(const Color& col, double fWidth, StrokeStyle style)
{
int width = stableRound(fWidth);
if (width < 1)
@@ -367,12 +368,12 @@ static HPEN createPen(const Color& col, double fWidth, StrokeStyle style)
break;
}
- return CreatePen(penStyle, width, RGB(col.red(), col.green(), col.blue()));
+ return adoptPtr(CreatePen(penStyle, width, RGB(col.red(), col.green(), col.blue())));
}
-static inline HGDIOBJ createBrush(const Color& col)
+static inline PassOwnPtr<HBRUSH> createBrush(const Color& col)
{
- return CreateSolidBrush(RGB(col.red(), col.green(), col.blue()));
+ return adoptPtr(CreateSolidBrush(RGB(col.red(), col.green(), col.blue())));
}
template <typename PixelType, bool Is16bit> static void _rotateBitmap(SharedBitmap* destBmp, const SharedBitmap* sourceBmp, const RotationTransform& transform)
@@ -644,41 +645,33 @@ void GraphicsContext::drawRect(const IntRect& rect)
return;
trRect.move(transparentDC.toShift());
- HGDIOBJ brush = 0;
+ OwnPtr<HBRUSH> brush;
HGDIOBJ oldBrush;
if (fillColor().alpha()) {
brush = createBrush(fillColor());
- oldBrush = SelectObject(dc, brush);
+ oldBrush = SelectObject(dc, brush.get());
} else
- SelectObject(dc, GetStockObject(NULL_BRUSH));
+ oldBrush = SelectObject(dc, GetStockObject(NULL_BRUSH));
- HGDIOBJ pen = 0;
+ OwnPtr<HPEN> pen;
HGDIOBJ oldPen;
if (strokeStyle() != NoStroke) {
pen = createPen(strokeColor(), strokeThickness(), strokeStyle());
- oldPen = SelectObject(dc, pen);
+ oldPen = SelectObject(dc, pen.get());
} else
- SelectObject(dc, GetStockObject(NULL_PEN));
+ oldPen = SelectObject(dc, GetStockObject(NULL_PEN));
- if (!brush && !pen)
- return;
-
- if (trRect.width() <= 0)
- trRect.setWidth(1);
- if (trRect.height() <= 0)
- trRect.setHeight(1);
-
- Rectangle(dc, trRect.x(), trRect.y(), trRect.right(), trRect.bottom());
+ if (brush || pen) {
+ if (trRect.width() <= 0)
+ trRect.setWidth(1);
+ if (trRect.height() <= 0)
+ trRect.setHeight(1);
- if (pen) {
- SelectObject(dc, oldPen);
- DeleteObject(pen);
+ Rectangle(dc, trRect.x(), trRect.y(), trRect.right(), trRect.bottom());
}
- if (brush) {
- SelectObject(dc, oldBrush);
- DeleteObject(brush);
- }
+ SelectObject(dc, oldPen);
+ SelectObject(dc, oldBrush);
}
void GraphicsContext::drawLine(const IntPoint& point1, const IntPoint& point2)
@@ -702,14 +695,13 @@ void GraphicsContext::drawLine(const IntPoint& point1, const IntPoint& point2)
trPoint1 += transparentDC.toShift();
trPoint2 += transparentDC.toShift();
- HGDIOBJ pen = createPen(strokeColor(), strokeThickness(), strokeStyle());
- HGDIOBJ oldPen = SelectObject(dc, pen);
+ OwnPtr<HPEN> pen = createPen(strokeColor(), strokeThickness(), strokeStyle());
+ HGDIOBJ oldPen = SelectObject(dc, pen.get());
MoveToEx(dc, trPoint1.x(), trPoint1.y(), 0);
LineTo(dc, trPoint2.x(), trPoint2.y());
SelectObject(dc, oldPen);
- DeleteObject(pen);
}
void GraphicsContext::drawEllipse(const IntRect& rect)
@@ -728,32 +720,27 @@ void GraphicsContext::drawEllipse(const IntRect& rect)
return;
trRect.move(transparentDC.toShift());
- HGDIOBJ brush = 0;
+ OwnPtr<HBRUSH> brush;
HGDIOBJ oldBrush;
if (fillColor().alpha()) {
brush = createBrush(fillColor());
- oldBrush = SelectObject(dc, brush);
+ oldBrush = SelectObject(dc, brush.get());
} else
- SelectObject(dc, GetStockObject(NULL_BRUSH));
- HGDIOBJ pen = 0;
- HGDIOBJ oldPen;
+ oldBrush = SelectObject(dc, GetStockObject(NULL_BRUSH));
+
+ OwnPtr<HPEN> pen;
+ HGDIOBJ oldPen = 0;
if (strokeStyle() != NoStroke) {
pen = createPen(strokeColor(), strokeThickness(), strokeStyle());
- oldPen = SelectObject(dc, pen);
+ oldPen = SelectObject(dc, pen.get());
} else
- SelectObject(dc, GetStockObject(NULL_PEN));
-
- Ellipse(dc, trRect.x(), trRect.y(), trRect.right(), trRect.bottom());
+ oldPen = SelectObject(dc, GetStockObject(NULL_PEN));
- if (pen) {
- SelectObject(dc, oldPen);
- DeleteObject(pen);
- }
+ if (brush || pen)
+ Ellipse(dc, trRect.x(), trRect.y(), trRect.right(), trRect.bottom());
- if (brush) {
- SelectObject(dc, oldBrush);
- DeleteObject(brush);
- }
+ SelectObject(dc, oldPen);
+ SelectObject(dc, oldBrush);
}
static inline bool equalAngle(double a, double b)
@@ -815,8 +802,8 @@ void GraphicsContext::strokeArc(const IntRect& rect, int startAngle, int angleSp
return;
trRect.move(transparentDC.toShift());
- HGDIOBJ pen = createPen(strokeColor(), strokeThickness(), strokeStyle());
- HGDIOBJ oldPen = SelectObject(dc, pen);
+ OwnPtr<HPEN> pen = createPen(strokeColor(), strokeThickness(), strokeStyle());
+ HGDIOBJ oldPen = SelectObject(dc, pen.get());
double a = trRect.width() * 0.5;
double b = trRect.height() * 0.5;
@@ -872,7 +859,6 @@ void GraphicsContext::strokeArc(const IntRect& rect, int startAngle, int angleSp
SelectClipRgn(dc, clipRgn.get());
SelectObject(dc, oldPen);
- DeleteObject(pen);
}
void GraphicsContext::drawConvexPolygon(size_t npoints, const FloatPoint* points, bool shouldAntialias)
@@ -916,36 +902,27 @@ void GraphicsContext::drawConvexPolygon(size_t npoints, const FloatPoint* points
winPoints[i].y += transparentDC.toShift().height();
}
- HGDIOBJ brush = 0;
+ OwnPtr<HBRUSH> brush;
HGDIOBJ oldBrush;
if (fillColor().alpha()) {
brush = createBrush(fillColor());
- oldBrush = SelectObject(dc, brush);
+ oldBrush = SelectObject(dc, brush.get());
} else
- SelectObject(dc, GetStockObject(NULL_BRUSH));
+ oldBrush = SelectObject(dc, GetStockObject(NULL_BRUSH));
- HGDIOBJ pen = 0;
+ OwnPtr<HPEN> pen;
HGDIOBJ oldPen;
if (strokeStyle() != NoStroke) {
pen = createPen(strokeColor(), strokeThickness(), strokeStyle());
- oldPen = SelectObject(dc, pen);
+ oldPen = SelectObject(dc, pen.get());
} else
- SelectObject(dc, GetStockObject(NULL_PEN));
-
- if (!brush && !pen)
- return;
-
- Polygon(dc, winPoints.data(), npoints);
+ oldPen = SelectObject(dc, GetStockObject(NULL_PEN));
- if (pen) {
- SelectObject(dc, oldPen);
- DeleteObject(pen);
- }
+ if (brush || pen)
+ Polygon(dc, winPoints.data(), npoints);
- if (brush) {
- SelectObject(dc, oldBrush);
- DeleteObject(brush);
- }
+ SelectObject(dc, oldPen);
+ SelectObject(dc, oldBrush);
}
void GraphicsContext::clipConvexPolygon(size_t numPoints, const FloatPoint* points, bool antialiased)
@@ -1104,7 +1081,7 @@ void GraphicsContext::clearRect(const FloatRect& rect)
return;
}
- fillRect(rect, Color(Color::white), DeviceColorSpace);
+ fillRect(rect, Color(Color::white), ColorSpaceDeviceRGB);
}
void GraphicsContext::strokeRect(const FloatRect& rect, float width)
@@ -1124,8 +1101,8 @@ void GraphicsContext::strokeRect(const FloatRect& rect, float width)
return;
trRect.move(transparentDC.toShift());
- HGDIOBJ pen = createPen(strokeColor(), strokeThickness(), strokeStyle());
- HGDIOBJ oldPen = SelectObject(dc, pen);
+ OwnPtr<HPEN> pen = createPen(strokeColor(), strokeThickness(), strokeStyle());
+ HGDIOBJ oldPen = SelectObject(dc, pen.get());
int right = trRect.right() - 1;
int bottom = trRect.bottom() - 1;
@@ -1141,7 +1118,6 @@ void GraphicsContext::strokeRect(const FloatRect& rect, float width)
Polyline(dc, intPoints, 5);
SelectObject(dc, oldPen);
- DeleteObject(pen);
}
void GraphicsContext::beginTransparencyLayer(float opacity)
@@ -1286,9 +1262,9 @@ void GraphicsContext::fillRoundedRect(const IntRect& fillRect, const IntSize& to
RECT rectWin = dstRect;
- HGDIOBJ brush = createBrush(shadowColor);
- HGDIOBJ oldBrush = SelectObject(dc, brush);
-
+ OwnPtr<HBRUSH> brush = createBrush(shadowColor);
+ HGDIOBJ oldBrush = SelectObject(dc, brush.get());
+
SelectObject(dc, GetStockObject(NULL_PEN));
IntPoint centerPoint = rectCenterPoint(rectWin);
@@ -1324,7 +1300,6 @@ void GraphicsContext::fillRoundedRect(const IntRect& fillRect, const IntSize& to
drawRoundCorner(needsNewClip, clipRect, rectWin, dc, stableRound(newBottomRight.width() * 2), stableRound(newBottomRight.height() * 2));
SelectObject(dc, oldBrush);
- DeleteObject(brush);
}
@@ -1382,8 +1357,9 @@ void GraphicsContext::fillPath()
if (!m_data->m_dc)
return;
+ OwnPtr<HBRUSH> brush = createBrush(c);
+
if (m_data->m_opacity < 1.0f || m_data->hasAlpha()) {
- HGDIOBJ brush = createBrush(c);
for (Vector<Path>::const_iterator i = m_data->m_paths.begin(); i != m_data->m_paths.end(); ++i) {
IntRect trRect = enclosingIntRect(m_data->mapRect(i->boundingRect()));
trRect.inflate(1);
@@ -1396,19 +1372,16 @@ void GraphicsContext::fillPath()
tr.translate(transparentDC.toShift().width(), transparentDC.toShift().height());
SelectObject(dc, GetStockObject(NULL_PEN));
- HGDIOBJ oldBrush = SelectObject(dc, brush);
+ HGDIOBJ oldBrush = SelectObject(dc, brush.get());
i->platformPath()->fillPath(dc, &tr);
SelectObject(dc, oldBrush);
}
- DeleteObject(brush);
} else {
SelectObject(m_data->m_dc, GetStockObject(NULL_PEN));
- HGDIOBJ brush = createBrush(c);
- HGDIOBJ oldBrush = SelectObject(m_data->m_dc, brush);
+ HGDIOBJ oldBrush = SelectObject(m_data->m_dc, brush.get());
for (Vector<Path>::const_iterator i = m_data->m_paths.begin(); i != m_data->m_paths.end(); ++i)
i->platformPath()->fillPath(m_data->m_dc, &m_data->m_transform);
SelectObject(m_data->m_dc, oldBrush);
- DeleteObject(brush);
}
}
@@ -1422,8 +1395,9 @@ void GraphicsContext::strokePath()
if (!m_data->m_dc)
return;
+ OwnPtr<HPEN> pen = createPen(strokeColor(), strokeThickness(), strokeStyle());
+
if (m_data->m_opacity < 1.0f || m_data->hasAlpha()) {
- HGDIOBJ pen = createPen(strokeColor(), strokeThickness(), strokeStyle());
for (Vector<Path>::const_iterator i = m_data->m_paths.begin(); i != m_data->m_paths.end(); ++i) {
IntRect trRect = enclosingIntRect(m_data->mapRect(i->boundingRect()));
trRect.inflate(1);
@@ -1436,19 +1410,16 @@ void GraphicsContext::strokePath()
tr.translate(transparentDC.toShift().width(), transparentDC.toShift().height());
SelectObject(dc, GetStockObject(NULL_BRUSH));
- HGDIOBJ oldPen = SelectObject(dc, pen);
+ HGDIOBJ oldPen = SelectObject(dc, pen.get());
i->platformPath()->strokePath(dc, &tr);
SelectObject(dc, oldPen);
}
- DeleteObject(pen);
} else {
SelectObject(m_data->m_dc, GetStockObject(NULL_BRUSH));
- HGDIOBJ pen = createPen(strokeColor(), strokeThickness(), strokeStyle());
- HGDIOBJ oldPen = SelectObject(m_data->m_dc, pen);
+ HGDIOBJ oldPen = SelectObject(m_data->m_dc, pen.get());
for (Vector<Path>::const_iterator i = m_data->m_paths.begin(); i != m_data->m_paths.end(); ++i)
i->platformPath()->strokePath(m_data->m_dc, &m_data->m_transform);
SelectObject(m_data->m_dc, oldPen);
- DeleteObject(pen);
}
}
@@ -1465,7 +1436,7 @@ void GraphicsContext::fillRect(const FloatRect& r, const Gradient* gradient)
if (numStops == 1) {
const Gradient::ColorStop& stop = stops.first();
Color color(stop.red, stop.green, stop.blue, stop.alpha);
- fillRect(r, color, DeviceColorSpace);
+ fillRect(r, color, ColorSpaceDeviceRGB);
return;
}
@@ -1555,7 +1526,7 @@ void GraphicsContext::fillRect(const FloatRect& rect)
if (m_common->state.fillGradient)
fillRect(rect, m_common->state.fillGradient.get());
else
- fillRect(rect, fillColor(), DeviceColorSpace);
+ fillRect(rect, fillColor(), ColorSpaceDeviceRGB);
restorePlatformState();
}