diff options
author | brettw@google.com <brettw@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-11-18 16:20:51 +0000 |
---|---|---|
committer | brettw@google.com <brettw@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-11-18 16:20:51 +0000 |
commit | 3c821ebabce6a3e287968170565e1da0be3fa1cd (patch) | |
tree | 9318b2b54e0db02daefb3288ca3db615c1062768 /webkit | |
parent | e0a89d9555ffb8575be21c3a96564d59aeb44c82 (diff) | |
download | chromium_src-3c821ebabce6a3e287968170565e1da0be3fa1cd.zip chromium_src-3c821ebabce6a3e287968170565e1da0be3fa1cd.tar.gz chromium_src-3c821ebabce6a3e287968170565e1da0be3fa1cd.tar.bz2 |
Remove most base dependencies from ImageSkia.
Review URL: http://codereview.chromium.org/11411
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@5609 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit')
-rw-r--r-- | webkit/glue/chromium_bridge_impl.cc | 74 | ||||
-rw-r--r-- | webkit/port/platform/chromium/ChromiumBridge.h | 6 | ||||
-rw-r--r-- | webkit/port/platform/graphics/ImageSkia.cpp | 95 |
3 files changed, 95 insertions, 80 deletions
diff --git a/webkit/glue/chromium_bridge_impl.cc b/webkit/glue/chromium_bridge_impl.cc index b817d95c..5d6514c 100644 --- a/webkit/glue/chromium_bridge_impl.cc +++ b/webkit/glue/chromium_bridge_impl.cc @@ -5,6 +5,8 @@ #include "config.h" #include "ChromiumBridge.h" +#include "BitmapImage.h" +#include "BitmapImageSingleFrameSkia.h" #include "ClipboardUtilitiesChromium.h" #include "Cursor.h" #include "Frame.h" @@ -16,6 +18,7 @@ #include "PasteboardPrivate.h" #include "PlatformString.h" #include "PlatformWidget.h" +#include "ScrollbarTheme.h" #include "ScrollView.h" #include "Widget.h" @@ -24,6 +27,7 @@ #include "base/stats_counters.h" #include "base/string_util.h" #include "base/trace_event.h" +#include "build/build_config.h" #if USE(V8) #include <v8.h> #endif @@ -32,9 +36,17 @@ #include "webkit/glue/scoped_clipboard_writer_glue.h" #include "webkit/glue/webcursor.h" #include "webkit/glue/webkit_glue.h" +#include "webkit/glue/webkit_resources.h" #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" +#endif + namespace { PlatformWidget ToPlatform(WebCore::Widget* widget) { @@ -266,6 +278,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 a2a2834..548b024 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; @@ -97,6 +99,9 @@ namespace WebCore { // Protocol ----------------------------------------------------------- static String uiResourceProtocol(); + // Resources ---------------------------------------------------------- + static PassRefPtr<Image> loadPlatformImageResource(const char* name); + // Screen ------------------------------------------------------------- static int screenDepth(Widget*); static int screenDepthPerComponent(Widget*); @@ -120,7 +125,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..5213660 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 < @@ -253,6 +242,7 @@ void paintSkBitmap(PlatformContextSkia* platformContext, const SkPorterDuff::Mode& compOp) { SkPaint paint; + paint.setAntiAlias(true); paint.setPorterDuffXfermode(compOp); gfx::PlatformCanvas* canvas = platformContext->canvas(); @@ -265,10 +255,13 @@ 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); + paint.setFilterBitmap(!canvas->getTotalMatrix().rectStaysRect() || + resampling == RESAMPLE_LINEAR); canvas->drawBitmapRect(bitmap, &srcRect, destRect, &paint); } } @@ -295,34 +288,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 +299,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 +409,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 +453,4 @@ PassRefPtr<BitmapImageSingleFrameSkia> BitmapImageSingleFrameSkia::create( return image.release(); } -} // namespace WebCore +} // namespace WebCore |