summaryrefslogtreecommitdiffstats
path: root/webkit
diff options
context:
space:
mode:
authorericroman@google.com <ericroman@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2008-10-11 01:45:44 +0000
committerericroman@google.com <ericroman@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2008-10-11 01:45:44 +0000
commitc0df724c57a63471d97df1db8c109060cdfb4d70 (patch)
treeff310a7665c8bd4f68fa6ac77788321d837c8375 /webkit
parentbb47d7f8aba97f861a52ccda69b7878d5103af9e (diff)
downloadchromium_src-c0df724c57a63471d97df1db8c109060cdfb4d70.zip
chromium_src-c0df724c57a63471d97df1db8c109060cdfb4d70.tar.gz
chromium_src-c0df724c57a63471d97df1db8c109060cdfb4d70.tar.bz2
Fix problem with how Image is created for ImageBuffer, that was causing some canvas layout tests to fail.
The problem is that serializing to a BMP and then deserializing is a lossy sequence -- for example if the BMP was fully transparent BMPImageReader has a hack to re-write it as fully opaque (this transformation is what caused canvas-resize-reset.html to be full black). Review URL: http://codereview.chromium.org/7057 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@3266 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit')
-rw-r--r--webkit/port/platform/graphics/BitmapImageSingleFrameSkia.h62
-rw-r--r--webkit/port/platform/graphics/ImageBufferSkia.cpp8
-rw-r--r--webkit/port/platform/graphics/ImageSkia.cpp30
-rw-r--r--webkit/port/platform/graphics/NativeImageSkia.cpp3
-rw-r--r--webkit/port/platform/graphics/SkiaUtils.cpp54
-rw-r--r--webkit/port/platform/graphics/SkiaUtils.h3
-rw-r--r--webkit/tools/layout_tests/test_lists/tests_fixable.txt4
7 files changed, 91 insertions, 73 deletions
diff --git a/webkit/port/platform/graphics/BitmapImageSingleFrameSkia.h b/webkit/port/platform/graphics/BitmapImageSingleFrameSkia.h
new file mode 100644
index 0000000..1739a59
--- /dev/null
+++ b/webkit/port/platform/graphics/BitmapImageSingleFrameSkia.h
@@ -0,0 +1,62 @@
+// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef BitmapImageSingleFrameSkia_h
+#define BitmapImageSingleFrameSkia_h
+
+#include "Image.h"
+#include "NativeImageSkia.h"
+
+namespace WebCore {
+
+// This image class can be used in places which need an Image, but have
+// raw pixel data rather than undecoded image data.
+// The Image is simpler than a BitmapImage, as it does not have image
+// observers, animation, multiple frames, or non-decoded data.
+// Therefore trimming the decoded data (destroyDecodedData()) has no effect.
+//
+// The difficulty with putting this in BitmapImage::create(NativeImagePtr)
+// 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& bitmap);
+
+ virtual bool isBitmapImage() const { return true; }
+
+ virtual IntSize size() const
+ {
+ return IntSize(m_nativeImage.width(), m_nativeImage.height());
+ }
+
+ // Do nothing, as we only have the one representation of data (decoded).
+ virtual void destroyDecodedData(bool) { }
+
+ virtual unsigned decodedSize() const
+ {
+ return m_nativeImage.decodedSize();
+ }
+
+ // We only have a single frame.
+ virtual NativeImagePtr nativeImageForCurrentFrame()
+ {
+ return &m_nativeImage;
+ }
+
+protected:
+ virtual void draw(GraphicsContext* ctxt, const FloatRect& dstRect,
+ const FloatRect& srcRect, CompositeOperator compositeOp);
+
+private:
+ NativeImageSkia m_nativeImage;
+
+ // Use create().
+ BitmapImageSingleFrameSkia() { }
+};
+
+} // namespace WebCore
+
+#endif // BitmapImageSingleFrameSkia_h
diff --git a/webkit/port/platform/graphics/ImageBufferSkia.cpp b/webkit/port/platform/graphics/ImageBufferSkia.cpp
index e1d9c90..a9f77d0 100644
--- a/webkit/port/platform/graphics/ImageBufferSkia.cpp
+++ b/webkit/port/platform/graphics/ImageBufferSkia.cpp
@@ -31,6 +31,7 @@
#include "ImageBuffer.h"
#include "BitmapImage.h"
+#include "BitmapImageSingleFrameSkia.h"
#include "GraphicsContext.h"
#include "ImageData.h"
#include "NotImplemented.h"
@@ -58,12 +59,7 @@ Image* ImageBuffer::image() const
// the GraphicsContext must be done.
ASSERT(context());
const SkBitmap* bitmap = context()->platformContext()->bitmap();
- m_image = BitmapImage::create();
- // TODO(tc): This is inefficient because we serialize then re-interpret
- // the image. If this matters for performance, we should add another
- // BitmapImage::create method that takes a SkBitmap (similar to what
- // CoreGraphics does).
- m_image->setData(SerializeSkBitmap(*bitmap), true);
+ m_image = BitmapImageSingleFrameSkia::create(*bitmap);
}
return m_image.get();
}
diff --git a/webkit/port/platform/graphics/ImageSkia.cpp b/webkit/port/platform/graphics/ImageSkia.cpp
index 2c5911c..0a5b7a2 100644
--- a/webkit/port/platform/graphics/ImageSkia.cpp
+++ b/webkit/port/platform/graphics/ImageSkia.cpp
@@ -33,6 +33,7 @@
#include <vssym32.h>
#include "AffineTransform.h"
#include "BitmapImage.h"
+#include "BitmapImageSingleFrameSkia.h"
#include "FloatRect.h"
#include "GraphicsContext.h"
#include "Logging.h"
@@ -86,8 +87,6 @@ void TransformDimensions(const SkMatrix& matrix,
// WebCore/rendering/RenderLayer.cpp).
static PassRefPtr<Image> GetTextAreaResizeCorner()
{
- RefPtr<Image> image = BitmapImage::create();
-
// Get the size of the resizer.
const int width = PlatformScrollbar::verticalScrollbarWidth();
const int height = PlatformScrollbar::horizontalScrollbarHeight();
@@ -103,8 +102,7 @@ static PassRefPtr<Image> GetTextAreaResizeCorner()
gfx::NativeTheme::instance()->PaintStatusGripper(hdc, SP_GRIPPER, 0, 0,
&widgetRect);
device.postProcessGDI(0, 0, width, height);
- image->setData(SerializeSkBitmap(device.accessBitmap(false)), true);
- return image.release();
+ return BitmapImageSingleFrameSkia::create(device.accessBitmap(false));
}
} // namespace
@@ -324,4 +322,28 @@ void BitmapImage::draw(GraphicsContext* ctxt, const FloatRect& dstRect,
startAnimation();
}
+void BitmapImageSingleFrameSkia::draw(GraphicsContext* ctxt,
+ const FloatRect& dstRect,
+ const FloatRect& srcRect,
+ CompositeOperator compositeOp)
+{
+ if (srcRect.isEmpty() || dstRect.isEmpty())
+ return; // Nothing to draw.
+
+ ctxt->platformContext()->paintSkBitmap(
+ m_nativeImage,
+ enclosingIntRect(srcRect),
+ enclosingIntRect(dstRect),
+ WebCoreCompositeToSkiaComposite(compositeOp));
+}
+
+PassRefPtr<BitmapImageSingleFrameSkia> BitmapImageSingleFrameSkia::create(
+ const SkBitmap& bitmap)
+{
+ RefPtr<BitmapImageSingleFrameSkia> image(new BitmapImageSingleFrameSkia());
+ if (!bitmap.copyTo(&image->m_nativeImage, bitmap.config()))
+ return 0;
+ return image.release();
+}
+
} // namespace WebCore
diff --git a/webkit/port/platform/graphics/NativeImageSkia.cpp b/webkit/port/platform/graphics/NativeImageSkia.cpp
index 8518d81..fb765eb 100644
--- a/webkit/port/platform/graphics/NativeImageSkia.cpp
+++ b/webkit/port/platform/graphics/NativeImageSkia.cpp
@@ -43,8 +43,7 @@ NativeImageSkia::NativeImageSkia()
}
int NativeImageSkia::decodedSize() const {
- return (width() * height()) +
- (m_resizedImage.width() * m_resizedImage.height());
+ return getSize() + m_resizedImage.getSize();
}
bool NativeImageSkia::hasResizedBitmap(int w, int h) const {
diff --git a/webkit/port/platform/graphics/SkiaUtils.cpp b/webkit/port/platform/graphics/SkiaUtils.cpp
index 422f24a..b8570c5 100644
--- a/webkit/port/platform/graphics/SkiaUtils.cpp
+++ b/webkit/port/platform/graphics/SkiaUtils.cpp
@@ -229,57 +229,3 @@ bool SkPathContainsPoint(SkPath* orig_path, WebCore::FloatPoint point, SkPath::F
orig_path->setFillType(orig_ft); // restore
return contains;
}
-
-#if defined(OS_MACOSX)
-PassRefPtr<WebCore::SharedBuffer> SerializeSkBitmap(const SkBitmap& bitmap)
-{
- // TODO(playmobil): implement.
- ASSERT_NOT_REACHED();
- RefPtr<WebCore::SharedBuffer> buffer(NULL);
- return buffer;
-}
-#elif defined(OS_WIN)
-PassRefPtr<WebCore::SharedBuffer> SerializeSkBitmap(const SkBitmap& bitmap)
-{
- int width = bitmap.width();
- int height = bitmap.height();
-
- // Create a BMP v4 header that we can serialize.
- BITMAPV4HEADER v4Header;
- gfx::CreateBitmapV4Header(width, height, &v4Header);
- v4Header.bV4SizeImage = width * sizeof(uint32_t) * height;
-
- // Serialize the bitmap.
- BITMAPFILEHEADER fileHeader;
- fileHeader.bfType = 0x4d42; // "BM" header
- fileHeader.bfOffBits = sizeof(BITMAPFILEHEADER) + v4Header.bV4Size;
- fileHeader.bfSize = fileHeader.bfOffBits + v4Header.bV4SizeImage;
- fileHeader.bfReserved1 = fileHeader.bfReserved2 = 0;
-
- // Write BITMAPFILEHEADER
- RefPtr<WebCore::SharedBuffer> buffer(WebCore::SharedBuffer::create(
- reinterpret_cast<const char*>(&fileHeader),
- sizeof(BITMAPFILEHEADER)));
-
- // Write BITMAPINFOHEADER
- buffer->append(reinterpret_cast<const char*>(&v4Header),
- sizeof(BITMAPV4HEADER));
-
- // Write the image body.
- SkAutoLockPixels bitmap_lock(bitmap);
- unsigned header_size = buffer->size();
- const uint32_t* src_image_data = bitmap.getAddr32(0, 0);
- buffer->append(reinterpret_cast<const char*>(src_image_data),
- v4Header.bV4SizeImage);
- uint32_t* dest_image_data =
- reinterpret_cast<uint32_t*>(const_cast<char*>(buffer->data()) +
- header_size);
-
- // Skia stores colors pre-multiplied, BMP doesn't. Need to convert the
- // colors.
- for (int i = width * height - 1; i >= 0; --i)
- dest_image_data[i] = SkPMColorToColor(src_image_data[i]);
-
- return buffer;
-}
-#endif
diff --git a/webkit/port/platform/graphics/SkiaUtils.h b/webkit/port/platform/graphics/SkiaUtils.h
index dbe2a37..2d2af31 100644
--- a/webkit/port/platform/graphics/SkiaUtils.h
+++ b/webkit/port/platform/graphics/SkiaUtils.h
@@ -50,7 +50,4 @@ void ClipRectToCanvas(const SkCanvas& canvas, const SkRect& src_rect,
// Determine if a given WebKit point is contained in a path
bool SkPathContainsPoint(SkPath* orig_path, WebCore::FloatPoint point, SkPath::FillType ft);
-// Constructs a BMP V4 bitmap from an SkBitmap.
-PassRefPtr<WebCore::SharedBuffer> SerializeSkBitmap(const SkBitmap&);
-
#endif // SkiaUtils_h
diff --git a/webkit/tools/layout_tests/test_lists/tests_fixable.txt b/webkit/tools/layout_tests/test_lists/tests_fixable.txt
index 15ce3a3..d756398 100644
--- a/webkit/tools/layout_tests/test_lists/tests_fixable.txt
+++ b/webkit/tools/layout_tests/test_lists/tests_fixable.txt
@@ -991,15 +991,11 @@ V8 | KJS # LayoutTests/fast/backgrounds/svg-as-background-5.html = FAIL
V8 | KJS # LayoutTests/fast/block/float/float-avoidance.html = FAIL
V8 | KJS # LayoutTests/fast/borders/svg-as-border-image-2.html = FAIL
V8 | KJS # LayoutTests/fast/borders/svg-as-border-image.html = FAIL
-V8 | KJS # LayoutTests/fast/canvas/canvas-composite.html = FAIL
-V8 | KJS # LayoutTests/fast/canvas/canvas-resize-reset.html = FAIL
-V8 | KJS # LayoutTests/fast/canvas/canvas-transform-skewed.html = FAIL
V8 | KJS # LayoutTests/fast/canvas/canvasDrawingIntoSelf.html = FAIL
V8 | KJS # LayoutTests/fast/canvas/drawImage.html = FAIL
V8 | KJS # LayoutTests/fast/canvas/fill-stroke-clip-reset-path.html = FAIL
V8 | KJS # LayoutTests/fast/canvas/fillrect_gradient.html = FAIL
V8 | KJS # LayoutTests/fast/canvas/gradient-add-second-start-end-stop.html = FAIL
-V8 | KJS # LayoutTests/fast/canvas/image-object-in-canvas.html = FAIL
// Flaky
V8 | KJS # LayoutTests/fast/canvas/patternfill-repeat.html = FAIL | CRASH
V8 | KJS # LayoutTests/fast/css-generated-content/table-row-group-to-inline.html = FAIL