summaryrefslogtreecommitdiffstats
path: root/webkit
diff options
context:
space:
mode:
authorbrettw@google.com <brettw@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2008-11-18 21:08:02 +0000
committerbrettw@google.com <brettw@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2008-11-18 21:08:02 +0000
commitd055d8e56a5704b9e3104f5aa527d103815a093a (patch)
tree0afc7c91a4b487de77cc5536bc70678a1f141ad8 /webkit
parent01f73451f5c113ea960e2cbd7ae574943e4cff9b (diff)
downloadchromium_src-d055d8e56a5704b9e3104f5aa527d103815a093a.zip
chromium_src-d055d8e56a5704b9e3104f5aa527d103815a093a.tar.gz
chromium_src-d055d8e56a5704b9e3104f5aa527d103815a093a.tar.bz2
Remove most base dependencies from ImageSkia. Poke through the resource getting to the ChromiumBridge.
Review URL: http://codereview.chromium.org/11450 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@5635 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit')
-rw-r--r--webkit/glue/chromium_bridge_impl.cc74
-rw-r--r--webkit/port/platform/chromium/ChromiumBridge.h6
-rw-r--r--webkit/port/platform/graphics/ImageSkia.cpp91
3 files changed, 92 insertions, 79 deletions
diff --git a/webkit/glue/chromium_bridge_impl.cc b/webkit/glue/chromium_bridge_impl.cc
index c73d998..2e7300f 100644
--- a/webkit/glue/chromium_bridge_impl.cc
+++ b/webkit/glue/chromium_bridge_impl.cc
@@ -5,6 +5,7 @@
#include "config.h"
#include "ChromiumBridge.h"
+#include "BitmapImage.h"
#include "ClipboardUtilitiesChromium.h"
#include "Cursor.h"
#include "Frame.h"
@@ -28,6 +29,7 @@
#include "base/stats_counters.h"
#include "base/string_util.h"
#include "base/trace_event.h"
+#include "build/build_config.h"
#include "net/base/mime_util.h"
#if USE(V8)
#include <v8.h>
@@ -42,6 +44,16 @@
#include "webkit/glue/webview_impl.h"
#include "webkit/glue/webview_delegate.h"
+#if defined(OS_WIN)
+#include <windows.h>
+#include <vssym32.h>
+
+#include "base/gfx/native_theme.h"
+
+// This is only needed on Windows right now.
+#include "BitmapImageSingleFrameSkia.h"
+#endif
+
namespace {
PlatformWidget ToPlatform(WebCore::Widget* widget) {
@@ -312,6 +324,68 @@ String ChromiumBridge::uiResourceProtocol() {
return webkit_glue::StdStringToString(webkit_glue::GetUIResourceProtocol());
}
+
+// Resources ------------------------------------------------------------------
+
+#if defined(OS_WIN)
+// Creates an Image for the text area resize corner. We do this by drawing the
+// theme native control into a memory buffer then converting the memory buffer
+// into an image. We don't bother caching this image because the caller holds
+// onto a static copy (see WebCore/rendering/RenderLayer.cpp).
+static PassRefPtr<Image> GetTextAreaResizeCorner() {
+ // Get the size of the resizer.
+ const int thickness = ScrollbarTheme::nativeTheme()->scrollbarThickness();
+
+ // Setup a memory buffer.
+ gfx::PlatformCanvasWin canvas(thickness, thickness, false);
+ gfx::PlatformDeviceWin& device = canvas.getTopPlatformDevice();
+ device.prepareForGDI(0, 0, thickness, thickness);
+ HDC hdc = device.getBitmapDC();
+ RECT widgetRect = { 0, 0, thickness, thickness };
+
+ // Do the drawing.
+ gfx::NativeTheme::instance()->PaintStatusGripper(hdc, SP_GRIPPER, 0, 0,
+ &widgetRect);
+ device.postProcessGDI(0, 0, thickness, thickness);
+ return BitmapImageSingleFrameSkia::create(device.accessBitmap(false));
+}
+#endif
+
+PassRefPtr<Image> ChromiumBridge::loadPlatformImageResource(const char* name) {
+ // Some need special handling.
+ if (!strcmp(name, "textAreaResizeCorner")) {
+#if defined(OS_WIN)
+ return GetTextAreaResizeCorner();
+#else
+ DLOG(WARNING) << "This needs implementing on other platforms.";
+ return Image::nullImage();
+#endif
+ }
+
+ // The rest get converted to a resource ID that we can pass to the glue.
+ int resource_id = 0;
+ if (!strcmp(name, "missingImage")) {
+ resource_id = IDR_BROKENIMAGE;
+ } else if (!strcmp(name, "tickmarkDash")) {
+ resource_id = IDR_TICKMARK_DASH;
+ } else if (!strcmp(name, "deleteButton") ||
+ !strcmp(name, "deleteButtonPressed")) {
+ NOTREACHED() << "Image resource " << name << " does not exist yet.";
+ return Image::nullImage();
+ } else {
+ NOTREACHED() << "Unknown image resource " << name;
+ return Image::nullImage();
+ }
+
+ std::string data = webkit_glue::GetDataResource(resource_id);
+ RefPtr<SharedBuffer> buffer(
+ SharedBuffer::create(data.empty() ? "" : data.data(),
+ data.length()));
+ RefPtr<Image> image = BitmapImage::create();
+ image->setData(buffer, true);
+ return image;
+}
+
// Screen ---------------------------------------------------------------------
int ChromiumBridge::screenDepth(Widget* widget) {
diff --git a/webkit/port/platform/chromium/ChromiumBridge.h b/webkit/port/platform/chromium/ChromiumBridge.h
index 9f19d8b..3599bb7 100644
--- a/webkit/port/platform/chromium/ChromiumBridge.h
+++ b/webkit/port/platform/chromium/ChromiumBridge.h
@@ -33,6 +33,7 @@
#include "config.h"
#include "PasteboardPrivate.h"
+#include "PassRefPtr.h"
#include "PlatformString.h"
class NativeImageSkia;
@@ -45,6 +46,7 @@ namespace WebCore {
class Cursor;
class Document;
class Frame;
+ class Image;
class IntRect;
class KURL;
class String;
@@ -104,6 +106,9 @@ namespace WebCore {
// Protocol -----------------------------------------------------------
static String uiResourceProtocol();
+ // Resources ----------------------------------------------------------
+ static PassRefPtr<Image> loadPlatformImageResource(const char* name);
+
// Screen -------------------------------------------------------------
static int screenDepth(Widget*);
static int screenDepthPerComponent(Widget*);
@@ -127,7 +132,6 @@ namespace WebCore {
// Widget -------------------------------------------------------------
static void widgetSetCursor(Widget*, const Cursor&);
static void widgetSetFocus(Widget*);
-
};
}
diff --git a/webkit/port/platform/graphics/ImageSkia.cpp b/webkit/port/platform/graphics/ImageSkia.cpp
index 47815d4..155b718 100644
--- a/webkit/port/platform/graphics/ImageSkia.cpp
+++ b/webkit/port/platform/graphics/ImageSkia.cpp
@@ -1,10 +1,10 @@
// Copyright (c) 2008, Google Inc.
// All rights reserved.
-//
+//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
-//
+//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
@@ -14,7 +14,7 @@
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
-//
+//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
@@ -28,11 +28,11 @@
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "config.h"
-#include "build/build_config.h"
#include "AffineTransform.h"
#include "BitmapImage.h"
#include "BitmapImageSingleFrameSkia.h"
+#include "ChromiumBridge.h"
#include "FloatRect.h"
#include "GraphicsContext.h"
#include "Logging.h"
@@ -40,22 +40,11 @@
#include "NotImplemented.h"
#include "PlatformContextSkia.h"
#include "PlatformString.h"
-#include "ScrollbarTheme.h"
-
#include "SkiaUtils.h"
#include "SkShader.h"
#include "base/gfx/image_operations.h"
#include "base/gfx/platform_canvas.h"
-#include "webkit/glue/webkit_glue.h"
-#include "webkit/glue/webkit_resources.h"
-
-#if defined(OS_WIN)
-#include <windows.h>
-#include <vssym32.h>
-#include "base/gfx/gdi_util.h"
-#include "base/gfx/native_theme.h"
-#endif
namespace WebCore {
@@ -104,7 +93,7 @@ ResamplingMode computeResamplingMode(const NativeImageSkia& bitmap,
// We don't need to resample if the source and destination are the same.
return RESAMPLE_NONE;
}
-
+
if (srcWidth <= kSmallImageSizeThreshold ||
srcHeight <= kSmallImageSizeThreshold ||
destWidth <= kSmallImageSizeThreshold ||
@@ -113,7 +102,7 @@ ResamplingMode computeResamplingMode(const NativeImageSkia& bitmap,
// rules (think 1x1 images used to make lines).
return RESAMPLE_NONE;
}
-
+
if (srcHeight * kLargeStretch <= destHeight ||
srcWidth * kLargeStretch <= destWidth) {
// Large image detected.
@@ -129,7 +118,7 @@ ResamplingMode computeResamplingMode(const NativeImageSkia& bitmap,
// is slow and doesn't give us very much when growing a lot.
return RESAMPLE_LINEAR;
}
-
+
if ((fabs(destWidth - srcWidth) / srcWidth <
kFractionalChangeThreshold) &&
(fabs(destHeight - srcHeight) / srcHeight <
@@ -265,7 +254,9 @@ void paintSkBitmap(PlatformContextSkia* platformContext,
paint.setFilterBitmap(false);
drawResampledBitmap(*canvas, paint, bitmap, srcRect, destRect);
} else {
- // No resampling necessary, we can just draw the bitmap.
+ // No resampling necessary, we can just draw the bitmap. We want to
+ // filter it if we decided to do linear interpolation above, or if there
+ // is something interesting going on with the matrix (like a rotation).
// Note: for serialization, we will want to subset the bitmap first so
// we don't send extra pixels.
paint.setFilterBitmap(resampling == RESAMPLE_LINEAR);
@@ -295,34 +286,6 @@ void TransformDimensions(const SkMatrix& matrix,
*dest_height = SkScalarToFloat((dest_points[2] - dest_points[0]).length());
}
-#if defined(OS_WIN)
-// Creates an Image for the text area resize corner. We do this by drawing the
-// theme native control into a memory buffer then converting the memory buffer
-// into a BMP byte stream, then feeding it into the Image object. We have to
-// convert the HBITMAP into a BMP file because the Image object doesn't allow
-// us to directly manipulate the image data. We don't bother caching this
-// image because the caller holds onto a static copy (see
-// WebCore/rendering/RenderLayer.cpp).
-static PassRefPtr<Image> GetTextAreaResizeCorner()
-{
- // Get the size of the resizer.
- const int thickness = ScrollbarTheme::nativeTheme()->scrollbarThickness();
-
- // Setup a memory buffer.
- gfx::PlatformCanvasWin canvas(thickness, thickness, false);
- gfx::PlatformDeviceWin& device = canvas.getTopPlatformDevice();
- device.prepareForGDI(0, 0, thickness, thickness);
- HDC hdc = device.getBitmapDC();
- RECT widgetRect = { 0, 0, thickness, thickness };
-
- // Do the drawing.
- gfx::NativeTheme::instance()->PaintStatusGripper(hdc, SP_GRIPPER, 0, 0,
- &widgetRect);
- device.postProcessGDI(0, 0, thickness, thickness);
- return BitmapImageSingleFrameSkia::create(device.accessBitmap(false));
-}
-#endif
-
} // namespace
void FrameData::clear()
@@ -334,37 +297,9 @@ void FrameData::clear()
// properties like frame durations without re-decoding.
}
-static inline PassRefPtr<Image> loadImageWithResourceId(int resourceId)
-{
- RefPtr<Image> image = BitmapImage::create();
- // Load the desired resource.
- std::string data(webkit_glue::GetDataResource(resourceId));
- RefPtr<SharedBuffer> buffer(SharedBuffer::create(data.data(), data.length()));
- image->setData(buffer, true);
- return image.release();
-}
-
-// static
PassRefPtr<Image> Image::loadPlatformResource(const char *name)
{
- if (!strcmp(name, "missingImage"))
- return loadImageWithResourceId(IDR_BROKENIMAGE);
- if (!strcmp(name, "tickmarkDash"))
- return loadImageWithResourceId(IDR_TICKMARK_DASH);
- // TODO(port): Need to make this portable.
- if (!strcmp(name, "textAreaResizeCorner"))
-#if defined(OS_WIN)
- return GetTextAreaResizeCorner();
-#else
- notImplemented();
-#endif
- if (!strcmp(name, "deleteButton") || !strcmp(name, "deleteButtonPressed")) {
- LOG(NotYetImplemented, "Image resource %s does not yet exist\n", name);
- return Image::nullImage();
- }
-
- LOG(NotYetImplemented, "Unknown image resource %s requested\n", name);
- return Image::nullImage();
+ return ChromiumBridge::loadPlatformImageResource(name);
}
void Image::drawPattern(GraphicsContext* context,
@@ -472,7 +407,7 @@ void BitmapImage::draw(GraphicsContext* ctxt, const FloatRect& dstRect,
{
if (!m_source.initialized())
return;
-
+
// Spin the animation to the correct frame before we try to draw it, so we
// don't draw an old frame and then immediately need to draw a newer one,
// causing flicker and wasting CPU.
@@ -516,4 +451,4 @@ PassRefPtr<BitmapImageSingleFrameSkia> BitmapImageSingleFrameSkia::create(
return image.release();
}
-} // namespace WebCore
+} // namespace WebCore