diff options
author | brettw@google.com <brettw@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-11-21 20:32:45 +0000 |
---|---|---|
committer | brettw@google.com <brettw@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-11-21 20:32:45 +0000 |
commit | 98abd85558e19788d971df47690bcb4eb4dd8d98 (patch) | |
tree | 3639cbd4ce1324ce34be603ed36fec0022a438d7 /webkit | |
parent | 21ba9918905c5f3f66e3a075944587618da2d52d (diff) | |
download | chromium_src-98abd85558e19788d971df47690bcb4eb4dd8d98.zip chromium_src-98abd85558e19788d971df47690bcb4eb4dd8d98.tar.gz chromium_src-98abd85558e19788d971df47690bcb4eb4dd8d98.tar.bz2 |
Move the platform files form port to skia for Mac only. Hopefully this won't affect other platforms.
Review URL: http://codereview.chromium.org/11357
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@5845 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit')
11 files changed, 3 insertions, 829 deletions
diff --git a/webkit/SConscript.port b/webkit/SConscript.port index ac4f785..7f3132d 100644 --- a/webkit/SConscript.port +++ b/webkit/SConscript.port @@ -147,9 +147,6 @@ if env['PLATFORM'] == 'darwin': '$PORT_DIR/platform/chromium/ScrollbarThemeChromium.cpp', '$PORT_DIR/platform/graphics/FontCustomPlatformData.cpp', '$PORT_DIR/platform/graphics/ImageSkia.cpp', - - '$PORT_DIR/platform/graphics/skia/public/PlatformCanvasMac.cpp', - '$PORT_DIR/platform/graphics/skia/public/PlatformDeviceMac.cpp', ] for remove in remove_files: input_files.remove(remove) diff --git a/webkit/port/platform/graphics/skia/public/BitmapPlatformDevice.h b/webkit/port/platform/graphics/skia/public/BitmapPlatformDevice.h index dd1f87d..1f933a4 100644 --- a/webkit/port/platform/graphics/skia/public/BitmapPlatformDevice.h +++ b/webkit/port/platform/graphics/skia/public/BitmapPlatformDevice.h @@ -14,7 +14,7 @@ typedef BitmapPlatformDeviceWin BitmapPlatformDevice; } // namespace gfx #elif defined(__APPLE__) -#include "BitmapPlatformDeviceMac.h" +#include "skia/ext/bitmap_platform_device_mac.h" namespace gfx { typedef BitmapPlatformDeviceMac BitmapPlatformDevice; diff --git a/webkit/port/platform/graphics/skia/public/BitmapPlatformDeviceMac.cpp b/webkit/port/platform/graphics/skia/public/BitmapPlatformDeviceMac.cpp deleted file mode 100755 index b52090c..0000000 --- a/webkit/port/platform/graphics/skia/public/BitmapPlatformDeviceMac.cpp +++ /dev/null @@ -1,291 +0,0 @@ -// 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. - -#include "config.h" - -#include <time.h> - -#include "SkMatrix.h" -#include "SkRegion.h" -#include "SkUtils.h" - -#include "base/gfx/bitmap_platform_device_mac.h" -#include "base/gfx/skia_utils_mac.h" -#include "base/logging.h" - -namespace gfx { - -namespace { - -// Constrains position and size to fit within available_size. If |size| is -1, -// all the |available_size| is used. Returns false if the position is out of -// |available_size|. -bool Constrain(int available_size, int* position, int *size) { - if (*size < -2) - return false; - - if (*position < 0) { - if (*size != -1) - *size += *position; - *position = 0; - } - if (*size == 0 || *position >= available_size) - return false; - - if (*size > 0) { - int overflow = (*position + *size) - available_size; - if (overflow > 0) { - *size -= overflow; - } - } else { - // Fill up available size. - *size = available_size - *position; - } - return true; -} - -} // namespace - -class BitmapPlatformDeviceMac::BitmapPlatformDeviceMacData - : public base::RefCounted<BitmapPlatformDeviceMacData> { - public: - explicit BitmapPlatformDeviceMacData(CGContextRef bitmap); - - // Create/destroy CoreGraphics context for our bitmap data. - CGContextRef GetBitmapContext() { - LoadConfig(); - return bitmap_context_; - } - - void ReleaseBitmapContext() { - DCHECK(bitmap_context_); - CGContextRelease(bitmap_context_); - bitmap_context_ = NULL; - } - - // Sets the transform and clip operations. This will not update the CGContext, - // but will mark the config as dirty. The next call of LoadConfig will - // pick up these changes. - void SetMatrixClip(const SkMatrix& transform, const SkRegion& region); - - // Loads the current transform and clip into the DC. Can be called even when - // |bitmap_context_| is NULL (will be a NOP). - void LoadConfig(); - - // Lazily-created graphics context used to draw into the bitmap. - CGContextRef bitmap_context_; - - // True when there is a transform or clip that has not been set to the - // CGContext. The CGContext is retrieved for every text operation, and the - // transform and clip do not change as much. We can save time by not loading - // the clip and transform for every one. - bool config_dirty_; - - // Translation assigned to the CGContext: we need to keep track of this - // separately so it can be updated even if the CGContext isn't created yet. - SkMatrix transform_; - - // The current clipping - SkRegion clip_region_; - - private: - friend class base::RefCounted<BitmapPlatformDeviceMacData>; - ~BitmapPlatformDeviceMacData() { - if (bitmap_context_) - CGContextRelease(bitmap_context_); - } - - DISALLOW_COPY_AND_ASSIGN(BitmapPlatformDeviceMacData); -}; - -BitmapPlatformDeviceMac::\ - BitmapPlatformDeviceMacData::BitmapPlatformDeviceMacData( - CGContextRef bitmap) - : bitmap_context_(bitmap), - config_dirty_(true) { // Want to load the config next time. - DCHECK(bitmap_context_); - // Initialize the clip region to the entire bitmap. - - SkIRect rect; - rect.set(0, 0, - CGBitmapContextGetWidth(bitmap_context_), - CGBitmapContextGetHeight(bitmap_context_)); - clip_region_ = SkRegion(rect); - transform_.reset(); - CGContextRetain(bitmap_context_); -} - -void BitmapPlatformDeviceMac::BitmapPlatformDeviceMacData::SetMatrixClip( - const SkMatrix& transform, - const SkRegion& region) { - transform_ = transform; - clip_region_ = region; - config_dirty_ = true; -} - -void BitmapPlatformDeviceMac::BitmapPlatformDeviceMacData::LoadConfig() { - if (!config_dirty_ || !bitmap_context_) - return; // Nothing to do. - config_dirty_ = false; - - // Transform. - SkMatrix t(transform_); - LoadTransformToCGContext(bitmap_context_, t); - t.setTranslateX(-t.getTranslateX()); - t.setTranslateY(-t.getTranslateY()); - LoadClippingRegionToCGContext(bitmap_context_, clip_region_, t); -} - - -// We use this static factory function instead of the regular constructor so -// that we can create the pixel data before calling the constructor. This is -// required so that we can call the base class' constructor with the pixel -// data. -BitmapPlatformDeviceMac* BitmapPlatformDeviceMac::Create(CGContextRef context, - int width, - int height, - bool is_opaque) { - void* data = malloc(height * width * 4); - if (!data) return NULL; - - SkBitmap bitmap; - bitmap.setConfig(SkBitmap::kARGB_8888_Config, width, height); - bitmap.setPixels(data); - - // Note: The Windows implementation clears the Bitmap later on. - // This bears mentioning since removal of this line makes the - // unit tests only fail periodically (or when MallocPreScribble is set). - bitmap.eraseARGB(0, 0, 0, 0); - - bitmap.setIsOpaque(is_opaque); - - if (is_opaque) { -#ifndef NDEBUG - // To aid in finding bugs, we set the background color to something - // obviously wrong so it will be noticable when it is not cleared - bitmap.eraseARGB(255, 0, 255, 128); // bright bluish green -#endif - } - - CGColorSpaceRef color_space = - CGColorSpaceCreateWithName(kCGColorSpaceGenericRGB); - // allocate a bitmap context with 4 components per pixel (RGBA): - CGContextRef bitmap_context = - CGBitmapContextCreate(data, width, height, 8, width*4, - color_space, kCGImageAlphaPremultipliedLast); - - // Change the coordinate system to match WebCore's - CGContextTranslateCTM(bitmap_context, 0, height); - CGContextScaleCTM(bitmap_context, 1.0, -1.0); - CGColorSpaceRelease(color_space); - - // The device object will take ownership of the graphics context. - return new BitmapPlatformDeviceMac( - new BitmapPlatformDeviceMacData(bitmap_context), bitmap); -} - -// The device will own the bitmap, which corresponds to also owning the pixel -// data. Therefore, we do not transfer ownership to the SkDevice's bitmap. -BitmapPlatformDeviceMac::BitmapPlatformDeviceMac( - BitmapPlatformDeviceMacData* data, const SkBitmap& bitmap) - : PlatformDeviceMac(bitmap), - data_(data) { -} - -// The copy constructor just adds another reference to the underlying data. -// We use a const cast since the default Skia definitions don't define the -// proper constedness that we expect (accessBitmap should really be const). -BitmapPlatformDeviceMac::BitmapPlatformDeviceMac( - const BitmapPlatformDeviceMac& other) - : PlatformDeviceMac( - const_cast<BitmapPlatformDeviceMac&>(other).accessBitmap(true)), - data_(other.data_) { -} - -BitmapPlatformDeviceMac::~BitmapPlatformDeviceMac() { -} - -BitmapPlatformDeviceMac& BitmapPlatformDeviceMac::operator=( - const BitmapPlatformDeviceMac& other) { - data_ = other.data_; - return *this; -} - -CGContextRef BitmapPlatformDeviceMac::GetBitmapContext() { - return data_->GetBitmapContext(); -} - -void BitmapPlatformDeviceMac::setMatrixClip(const SkMatrix& transform, - const SkRegion& region) { - data_->SetMatrixClip(transform, region); -} - -void BitmapPlatformDeviceMac::DrawToContext(CGContextRef context, int x, int y, - const CGRect* src_rect) { - bool created_dc = false; - if (!data_->bitmap_context_) { - created_dc = true; - GetBitmapContext(); - } - - // this should not make a copy of the bits, since we're not doing - // anything to trigger copy on write - CGImageRef image = CGBitmapContextCreateImage(data_->bitmap_context_); - CGRect bounds; - if (src_rect) { - bounds = *src_rect; - bounds.origin.x = x; - bounds.origin.y = y; - CGImageRef sub_image = CGImageCreateWithImageInRect(image, *src_rect); - CGContextDrawImage(context, bounds, sub_image); - CGImageRelease(sub_image); - } else { - bounds.origin.x = 0; - bounds.origin.y = 0; - bounds.size.width = width(); - bounds.size.height = height(); - CGContextDrawImage(context, bounds, image); - } - CGImageRelease(image); - - if (created_dc) - data_->ReleaseBitmapContext(); -} - -// Returns the color value at the specified location. -SkColor BitmapPlatformDeviceMac::getColorAt(int x, int y) { - const SkBitmap& bitmap = accessBitmap(true); - SkAutoLockPixels lock(bitmap); - uint32_t* data = bitmap.getAddr32(0, 0); - return static_cast<SkColor>(data[x + y * width()]); -} - -void BitmapPlatformDeviceMac::onAccessBitmap(SkBitmap*) { - // Not needed in CoreGraphics -} - -void BitmapPlatformDeviceMac::processPixels(int x, int y, - int width, int height, - adjustAlpha adjustor) { - const SkBitmap& bitmap = accessBitmap(true); - SkMatrix& matrix = data_->transform_; - int bitmap_start_x = SkScalarRound(matrix.getTranslateX()) + x; - int bitmap_start_y = SkScalarRound(matrix.getTranslateY()) + y; - - SkAutoLockPixels lock(bitmap); - if (Constrain(bitmap.width(), &bitmap_start_x, &width) && - Constrain(bitmap.height(), &bitmap_start_y, &height)) { - uint32_t* data = bitmap.getAddr32(0, 0); - size_t row_words = bitmap.rowBytes() / 4; - for (int i = 0; i < height; i++) { - size_t offset = (i + bitmap_start_y) * row_words + bitmap_start_x; - for (int j = 0; j < width; j++) { - adjustor(data + offset + j); - } - } - } -} - -} // namespace gfx - diff --git a/webkit/port/platform/graphics/skia/public/BitmapPlatformDeviceMac.h b/webkit/port/platform/graphics/skia/public/BitmapPlatformDeviceMac.h deleted file mode 100755 index 04383d7..0000000 --- a/webkit/port/platform/graphics/skia/public/BitmapPlatformDeviceMac.h +++ /dev/null @@ -1,95 +0,0 @@ -// 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 BitmapPlatformDeviceMac_h -#define BitmapPlatformDeviceMac_h - -#include "base/gfx/platform_device_mac.h" -#include "base/ref_counted.h" - -namespace gfx { - -// A device is basically a wrapper around SkBitmap that provides a surface for -// SkCanvas to draw into. Our device provides a surface CoreGraphics can also -// write to. BitmapPlatformDeviceMac creates a bitmap using -// CGCreateBitmapContext() in a format that Skia supports and can then use this -// to draw text into, etc. This pixel data is provided to the bitmap that the -// device contains so that it can be shared. -// -// The device owns the pixel data, when the device goes away, the pixel data -// also becomes invalid. THIS IS DIFFERENT THAN NORMAL SKIA which uses -// reference counting for the pixel data. In normal Skia, you could assign -// another bitmap to this device's bitmap and everything will work properly. -// For us, that other bitmap will become invalid as soon as the device becomes -// invalid, which may lead to subtle bugs. Therefore, DO NOT ASSIGN THE -// DEVICE'S PIXEL DATA TO ANOTHER BITMAP, make sure you copy instead. -class BitmapPlatformDeviceMac : public PlatformDeviceMac { - public: - // Factory function. The screen DC is used to create the bitmap, and will not - // be stored beyond this function. is_opaque should be set if the caller - // knows the bitmap will be completely opaque and allows some optimizations. - // - // The shared_section parameter is optional (pass NULL for default behavior). - // If shared_section is non-null, then it must be a handle to a file-mapping - // object returned by CreateFileMapping. See CreateDIBSection for details. - static BitmapPlatformDeviceMac* Create(CGContextRef context, - int width, - int height, - bool is_opaque); - - // Copy constructor. When copied, devices duplicate their internal data, so - // stay linked. This is because their implementation is very heavyweight - // (lots of memory and CoreGraphics state). If a device has been copied, both - // clip rects and other state will stay in sync. - // - // This means it will NOT work to duplicate a device and assign it to a - // canvas, because the two canvases will each set their own clip rects, and - // the resulting CoreGraphics drawing state will be unpredictable. - // - // Copy constucting and "=" is designed for saving the device or passing it - // around to another routine willing to deal with the bitmap data directly. - BitmapPlatformDeviceMac(const BitmapPlatformDeviceMac& other); - virtual ~BitmapPlatformDeviceMac(); - - // See warning for copy constructor above. - BitmapPlatformDeviceMac& operator=(const BitmapPlatformDeviceMac& other); - - virtual CGContextRef GetBitmapContext(); - virtual void setMatrixClip(const SkMatrix& transform, const SkRegion& region); - - virtual void DrawToContext(CGContextRef context, int x, int y, - const CGRect* src_rect); - virtual bool IsVectorial() { return false; } - virtual void fixupAlphaBeforeCompositing() { }; - - // Returns the color value at the specified location. This does not - // consider any transforms that may be set on the device. - SkColor getColorAt(int x, int y); - - protected: - // Reference counted data that can be shared between multiple devices. This - // allows copy constructors and operator= for devices to work properly. The - // bitmaps used by the base device class are already refcounted and copyable. - class BitmapPlatformDeviceMacData; - - BitmapPlatformDeviceMac(BitmapPlatformDeviceMacData* data, - const SkBitmap& bitmap); - - // Flushes the CoreGraphics context so that the pixel data can be accessed - // directly by Skia. Overridden from SkDevice, this is called when Skia - // starts accessing pixel data. - virtual void onAccessBitmap(SkBitmap*); - - // Data associated with this device, guaranteed non-null. - scoped_refptr<BitmapPlatformDeviceMacData> data_; - - virtual void processPixels(int x, int y, - int width, int height, - adjustAlpha adjustor); -}; - -} // namespace gfx - -#endif // BitmapPlatformDeviceMac_h - diff --git a/webkit/port/platform/graphics/skia/public/PlatformCanvas.h b/webkit/port/platform/graphics/skia/public/PlatformCanvas.h index 9fdfd68..162bf3e 100644 --- a/webkit/port/platform/graphics/skia/public/PlatformCanvas.h +++ b/webkit/port/platform/graphics/skia/public/PlatformCanvas.h @@ -14,7 +14,7 @@ typedef PlatformCanvasWin PlatformCanvas; } // namespace gfx #elif defined(__APPLE__) -#include "PlatformCanvasMac.h" +#include "skia/ext/platform_canvas_mac.h" namespace gfx { typedef PlatformCanvasMac PlatformCanvas; diff --git a/webkit/port/platform/graphics/skia/public/PlatformCanvasMac.cpp b/webkit/port/platform/graphics/skia/public/PlatformCanvasMac.cpp deleted file mode 100755 index fc026e8..0000000 --- a/webkit/port/platform/graphics/skia/public/PlatformCanvasMac.cpp +++ /dev/null @@ -1,82 +0,0 @@ -// 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. - -#include "config.h" - -#include "PlatformCanvasMac.h" - -#include "base/gfx/bitmap_platform_device_mac.h" -#include "base/logging.h" - -namespace gfx { - -PlatformCanvasMac::PlatformCanvasMac() : SkCanvas() { -} - -PlatformCanvasMac::PlatformCanvasMac(int width, int height, bool is_opaque) - : SkCanvas() { - initialize(width, height, is_opaque); -} - -PlatformCanvasMac::PlatformCanvasMac(int width, - int height, - bool is_opaque, - CGContextRef context) - : SkCanvas() { - initialize(width, height, is_opaque); -} - -PlatformCanvasMac::~PlatformCanvasMac() { -} - -bool PlatformCanvasMac::initialize(int width, - int height, - bool is_opaque) { - SkDevice* device = createPlatformDevice(width, height, is_opaque, NULL); - if (!device) - return false; - - setDevice(device); - device->unref(); // was created with refcount 1, and setDevice also refs - return true; -} - -CGContextRef PlatformCanvasMac::beginPlatformPaint() { - return getTopPlatformDevice().GetBitmapContext(); -} - -void PlatformCanvasMac::endPlatformPaint() { - // flushing will be done in onAccessBitmap -} - -PlatformDeviceMac& PlatformCanvasMac::getTopPlatformDevice() const { - // All of our devices should be our special PlatformDeviceMac. - SkCanvas::LayerIter iter(const_cast<PlatformCanvasMac*>(this), false); - return *static_cast<PlatformDeviceMac*>(iter.device()); -} - -SkDevice* PlatformCanvasMac::createDevice(SkBitmap::Config config, - int width, - int height, - bool is_opaque, bool isForLayer) { - DCHECK(config == SkBitmap::kARGB_8888_Config); - return createPlatformDevice(width, height, is_opaque, NULL); -} - -SkDevice* PlatformCanvasMac::createPlatformDevice(int width, - int height, - bool is_opaque, - CGContextRef context) { - SkDevice* device = BitmapPlatformDeviceMac::Create(context, width, height, - is_opaque); - return device; -} - -SkDevice* PlatformCanvasMac::setBitmapDevice(const SkBitmap&) { - NOTREACHED(); - return NULL; -} - -} // namespace gfx - diff --git a/webkit/port/platform/graphics/skia/public/PlatformCanvasMac.h b/webkit/port/platform/graphics/skia/public/PlatformCanvasMac.h deleted file mode 100755 index 8a39637..0000000 --- a/webkit/port/platform/graphics/skia/public/PlatformCanvasMac.h +++ /dev/null @@ -1,88 +0,0 @@ -// 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 PlatformCanvasMac_h -#define PlatformCanvasMac_h - -#include "PlatformDeviceMac.h" - -#include "SkCanvas.h" - -namespace gfx { - -// This class is a specialization of the regular SkCanvas that is designed to -// work with a gfx::PlatformDevice to manage platform-specific drawing. It -// allows using both Skia operations and platform-specific operations. -class PlatformCanvasMac : public SkCanvas { - public: - // Set is_opaque if you are going to erase the bitmap and not use - // tranparency: this will enable some optimizations. The shared_section - // parameter is passed to gfx::PlatformDevice::create. See it for details. - // - // If you use the version with no arguments, you MUST call initialize() - PlatformCanvasMac(); - PlatformCanvasMac(int width, int height, bool is_opaque); - PlatformCanvasMac(int width, int height, bool is_opaque, CGContextRef context); - virtual ~PlatformCanvasMac(); - - // For two-part init, call if you use the no-argument constructor above - bool initialize(int width, int height, bool is_opaque); - - // These calls should surround calls to platform drawing routines. The CG - // context returned by beginPlatformPaint is the one that can be used to - // draw into. - // Call endPlatformPaint when you are done and want to use Skia operations - // again; this will synchronize the bitmap. - virtual CGContextRef beginPlatformPaint(); - virtual void endPlatformPaint(); - - // Returns the platform device pointer of the topmost rect with a non-empty - // clip. In practice, this is usually either the top layer or nothing, since - // we usually set the clip to new layers when we make them. - // - // If there is no layer that is not all clipped out, this will return a - // dummy device so callers do not have to check. If you are concerned about - // performance, check the clip before doing any painting. - // - // This is different than SkCanvas' getDevice, because that returns the - // bottommost device. - // - // Danger: the resulting device should not be saved. It will be invalidated - // by the next call to save() or restore(). - PlatformDeviceMac& getTopPlatformDevice() const; - - // Allow callers to see the non-virtual function even though we have an - // override of a virtual one. - using SkCanvas::clipRect; - - protected: - // Creates a device store for use by the canvas. We override this so that - // the device is always our own so we know that we can use GDI operations - // on it. Simply calls into createPlatformDevice(). - virtual SkDevice* createDevice(SkBitmap::Config, int width, int height, - bool is_opaque, bool isForLayer); - - // Creates a device store for use by the canvas. By default, it creates a - // BitmapPlatformDevice object. Can be overridden to change the object type. - virtual SkDevice* createPlatformDevice(int width, int height, bool is_opaque, - CGContextRef context); - - private: - // Unimplemented. This is to try to prevent people from calling this function - // on SkCanvas. SkCanvas' version is not virtual, so we can't prevent this - // 100%, but hopefully this will make people notice and not use the function. - // Calling SkCanvas' version will create a new device which is not compatible - // with us and we will crash if somebody tries to draw into it with - // CoreGraphics. - SkDevice* setBitmapDevice(const SkBitmap& bitmap); - - // Disallow copy and assign. - PlatformCanvasMac(const PlatformCanvasMac&); - PlatformCanvasMac& operator=(const PlatformCanvasMac&); -}; - -} // namespace gfx - -#endif // PlatformCanvasMac_h - diff --git a/webkit/port/platform/graphics/skia/public/PlatformDevice.h b/webkit/port/platform/graphics/skia/public/PlatformDevice.h index 3072e08..a381fd1 100644 --- a/webkit/port/platform/graphics/skia/public/PlatformDevice.h +++ b/webkit/port/platform/graphics/skia/public/PlatformDevice.h @@ -9,7 +9,7 @@ #if defined(WIN32) #include "PlatformDeviceWin.h" #elif defined(__APPLE__) -#include "PlatformDeviceMac.h" +#include "skia/ext/platform_device_mac.h" #elif defined(__linux__) #include "PlatformDeviceLinux.h" #endif diff --git a/webkit/port/platform/graphics/skia/public/PlatformDeviceMac.cpp b/webkit/port/platform/graphics/skia/public/PlatformDeviceMac.cpp deleted file mode 100755 index f2f4cb6..0000000 --- a/webkit/port/platform/graphics/skia/public/PlatformDeviceMac.cpp +++ /dev/null @@ -1,163 +0,0 @@ -// 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. - -#include "config.h" - -#include "PlatformDeviceMac.h" - -#include "base/logging.h" -#include "base/gfx/skia_utils_mac.h" -#include "SkMatrix.h" -#include "SkPath.h" -#include "SkUtils.h" - -namespace gfx { - -namespace { - -// Constrains position and size to fit within available_size. -bool constrain(int available_size, int* position, int *size) { - if (*position < 0) { - *size += *position; - *position = 0; - } - if (*size > 0 && *position < available_size) { - int overflow = (*position + *size) - available_size; - if (overflow > 0) { - *size -= overflow; - } - return true; - } - return false; -} - -// Sets the opacity of the specified value to 0xFF. -void makeOpaqueAlphaAdjuster(uint32_t* pixel) { - *pixel |= 0xFF000000; -} - -} // namespace - -PlatformDeviceMac::PlatformDeviceMac(const SkBitmap& bitmap) - : SkDevice(bitmap) { -} - -void PlatformDeviceMac::makeOpaque(int x, int y, int width, int height) { - processPixels(x, y, width, height, makeOpaqueAlphaAdjuster); -} - -// Set up the CGContextRef for peaceful coexistence with Skia -void PlatformDeviceMac::InitializeCGContext(CGContextRef context) { - // CG defaults to the same settings as Skia -} - -// static -void PlatformDeviceMac::LoadPathToCGContext(CGContextRef context, - const SkPath& path) { - // instead of a persistent attribute of the context, CG specifies the fill - // type per call, so we just have to load up the geometry. - CGContextBeginPath(context); - - SkPoint points[4] = { {0, 0}, {0, 0}, {0, 0}, {0, 0} }; - SkPath::Iter iter(path, false); - for (SkPath::Verb verb = iter.next(points); verb != SkPath::kDone_Verb; - verb = iter.next(points)) { - switch (verb) { - case SkPath::kMove_Verb: { // iter.next returns 1 point - CGContextMoveToPoint(context, points[0].fX, points[0].fY); - break; - } - case SkPath::kLine_Verb: { // iter.next returns 2 points - CGContextAddLineToPoint(context, points[1].fX, points[1].fY); - break; - } - case SkPath::kQuad_Verb: { // iter.next returns 3 points - CGContextAddQuadCurveToPoint(context, points[1].fX, points[1].fY, - points[2].fX, points[2].fY); - break; - } - case SkPath::kCubic_Verb: { // iter.next returns 4 points - CGContextAddCurveToPoint(context, points[1].fX, points[1].fY, - points[2].fX, points[2].fY, - points[3].fX, points[3].fY); - break; - } - case SkPath::kClose_Verb: { // iter.next returns 1 point (the last point) - break; - } - case SkPath::kDone_Verb: // iter.next returns 0 points - default: { - NOTREACHED(); - break; - } - } - } - CGContextClosePath(context); -} - -// static -void PlatformDeviceMac::LoadTransformToCGContext(CGContextRef context, - const SkMatrix& matrix) { - // CoreGraphics can concatenate transforms, but not reset the current one. - // So in order to get the required behavior here, we need to first make - // the current transformation matrix identity and only then load the new one. - - // Reset matrix to identity. - CGAffineTransform orig_cg_matrix = CGContextGetCTM(context); - CGAffineTransform orig_cg_matrix_inv = CGAffineTransformInvert(orig_cg_matrix); - CGContextConcatCTM(context, orig_cg_matrix_inv); - - // assert that we have indeed returned to the identity Matrix. - DCHECK(CGAffineTransformIsIdentity(CGContextGetCTM(context))); - - // Convert xform to CG-land. - // Our coordinate system is flipped to match WebKit's so we need to modify - // the xform to match that. - SkMatrix transformed_matrix = matrix; - SkScalar sy = matrix.getScaleY() * (SkScalar)-1; - transformed_matrix.setScaleY(sy); - size_t height = CGBitmapContextGetHeight(context); - SkScalar ty = -matrix.getTranslateY(); // y axis is flipped. - transformed_matrix.setTranslateY(ty + (SkScalar)height); - - CGAffineTransform cg_matrix = SkMatrixToCGAffineTransform(transformed_matrix); - - // Load final transform into context. - CGContextConcatCTM(context, cg_matrix); -} - -// static -void PlatformDeviceMac::LoadClippingRegionToCGContext( - CGContextRef context, - const SkRegion& region, - const SkMatrix& transformation) { - if (region.isEmpty()) { - // region can be empty, in which case everything will be clipped. - SkRect rect; - rect.setEmpty(); - CGContextClipToRect(context, SkRectToCGRect(rect)); - } else if (region.isRect()) { - // Do the transformation. - SkRect rect; - rect.set(region.getBounds()); - transformation.mapRect(&rect); - SkIRect irect; - rect.round(&irect); - CGContextClipToRect(context, SkIRectToCGRect(irect)); - } else { - // It is complex. - SkPath path; - region.getBoundaryPath(&path); - // Clip. Note that windows clipping regions are not affected by the - // transform so apply it manually. - path.transform(transformation); - // TODO(playmobil): Implement. - NOTREACHED(); - // LoadPathToDC(context, path); - // hrgn = PathToRegion(context); - } -} - -} // namespace gfx - diff --git a/webkit/port/platform/graphics/skia/public/PlatformDeviceMac.h b/webkit/port/platform/graphics/skia/public/PlatformDeviceMac.h deleted file mode 100755 index 0e1dc61..0000000 --- a/webkit/port/platform/graphics/skia/public/PlatformDeviceMac.h +++ /dev/null @@ -1,86 +0,0 @@ -// 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 PlatformDeviceMac_h -#define PlatformDeviceMac_h - -#import <ApplicationServices/ApplicationServices.h> -#include "SkDevice.h" - -class SkMatrix; -class SkPath; -class SkRegion; - -namespace gfx { - -// A device is basically a wrapper around SkBitmap that provides a surface for -// SkCanvas to draw into. Our device provides a surface CoreGraphics can also -// write to. It also provides functionality to play well with CG drawing -// functions. -// This class is abstract and must be subclassed. It provides the basic -// interface to implement it either with or without a bitmap backend. -class PlatformDeviceMac : public SkDevice { - public: - // The CGContext that corresponds to the bitmap, used for CoreGraphics - // operations drawing into the bitmap. This is possibly heavyweight, so it - // should exist only during one pass of rendering. - virtual CGContextRef GetBitmapContext() = 0; - - // Draws to the given graphics context. If the bitmap context doesn't exist, - // this will temporarily create it. However, if you have created the bitmap - // context, it will be more efficient if you don't free it until after this - // call so it doesn't have to be created twice. If src_rect is null, then - // the entirety of the source device will be copied. - virtual void DrawToContext(CGContextRef context, int x, int y, - const CGRect* src_rect) = 0; - - // Sets the opacity of each pixel in the specified region to be opaque. - void makeOpaque(int x, int y, int width, int height); - - // Returns if the preferred rendering engine is vectorial or bitmap based. - virtual bool IsVectorial() = 0; - - // On platforms where the native rendering API does not support rendering - // into bitmaps with a premultiplied alpha channel, this call is responsible - // for doing any fixup necessary. It is not used on the Mac, since - // CoreGraphics can handle premultiplied alpha just fine. - virtual void fixupAlphaBeforeCompositing() = 0; - - // Initializes the default settings and colors in a device context. - static void InitializeCGContext(CGContextRef context); - - // Loads a SkPath into the CG context. The path can there after be used for - // clipping or as a stroke. - static void LoadPathToCGContext(CGContextRef context, const SkPath& path); - - // Loads a SkRegion into the CG context. - static void LoadClippingRegionToCGContext(CGContextRef context, - const SkRegion& region, - const SkMatrix& transformation); - - protected: - // Forwards |bitmap| to SkDevice's constructor. - PlatformDeviceMac(const SkBitmap& bitmap); - - // Loads the specified Skia transform into the device context - static void LoadTransformToCGContext(CGContextRef context, - const SkMatrix& matrix); - - // Function pointer used by the processPixels method for setting the alpha - // value of a particular pixel. - typedef void (*adjustAlpha)(uint32_t* pixel); - - // Loops through each of the pixels in the specified range, invoking - // adjustor for the alpha value of each pixel. - virtual void processPixels(int x, - int y, - int width, - int height, - adjustAlpha adjustor) = 0; -}; - -} // namespace gfx - -#endif // PlatformDeviceMac_h - diff --git a/webkit/webkit.xcodeproj/project.pbxproj b/webkit/webkit.xcodeproj/project.pbxproj index 3b5dfb7..50094c7 100644 --- a/webkit/webkit.xcodeproj/project.pbxproj +++ b/webkit/webkit.xcodeproj/project.pbxproj @@ -74,9 +74,6 @@ 4D2A644A0EBBC16700B55603 /* V8HTMLMediaElement.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4D2A64450EBBC16700B55603 /* V8HTMLMediaElement.cpp */; }; 4D2A644B0EBBC16700B55603 /* V8HTMLSourceElement.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4D2A64470EBBC16700B55603 /* V8HTMLSourceElement.cpp */; }; 4D329F8C0EB908A40041FB7E /* V8MessageChannel.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4D329F8A0EB908A40041FB7E /* V8MessageChannel.cpp */; }; - 4D35546E0ED499E000FB28B1 /* BitmapPlatformDeviceMac.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4D3554660ED499E000FB28B1 /* BitmapPlatformDeviceMac.cpp */; }; - 4D35546F0ED499E000FB28B1 /* PlatformCanvasMac.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4D3554690ED499E000FB28B1 /* PlatformCanvasMac.cpp */; }; - 4D3554700ED499E000FB28B1 /* PlatformDeviceMac.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4D35546C0ED499E000FB28B1 /* PlatformDeviceMac.cpp */; }; 4D35557D0ED4ACF600FB28B1 /* dtoa.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4D35557B0ED4ACF600FB28B1 /* dtoa.cpp */; }; 4D7B071F0E9DAE56009A6919 /* GraphicsContextStub.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4D7B071E0E9DAE56009A6919 /* GraphicsContextStub.cpp */; }; 4DB043A40EB1577900A5633C /* webcursor.cc in Sources */ = {isa = PBXBuildFile; fileRef = 825405300D92E3DA0006B936 /* webcursor.cc */; }; @@ -1547,14 +1544,8 @@ 4D329F8A0EB908A40041FB7E /* V8MessageChannel.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = V8MessageChannel.cpp; sourceTree = "<group>"; }; 4D329F8B0EB908A40041FB7E /* V8MessageChannel.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = V8MessageChannel.h; sourceTree = "<group>"; }; 4D3554650ED499E000FB28B1 /* BitmapPlatformDevice.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BitmapPlatformDevice.h; sourceTree = "<group>"; }; - 4D3554660ED499E000FB28B1 /* BitmapPlatformDeviceMac.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = BitmapPlatformDeviceMac.cpp; sourceTree = "<group>"; }; - 4D3554670ED499E000FB28B1 /* BitmapPlatformDeviceMac.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BitmapPlatformDeviceMac.h; sourceTree = "<group>"; }; 4D3554680ED499E000FB28B1 /* PlatformCanvas.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PlatformCanvas.h; sourceTree = "<group>"; }; - 4D3554690ED499E000FB28B1 /* PlatformCanvasMac.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = PlatformCanvasMac.cpp; sourceTree = "<group>"; }; - 4D35546A0ED499E000FB28B1 /* PlatformCanvasMac.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PlatformCanvasMac.h; sourceTree = "<group>"; }; 4D35546B0ED499E000FB28B1 /* PlatformDevice.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PlatformDevice.h; sourceTree = "<group>"; }; - 4D35546C0ED499E000FB28B1 /* PlatformDeviceMac.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = PlatformDeviceMac.cpp; sourceTree = "<group>"; }; - 4D35546D0ED499E000FB28B1 /* PlatformDeviceMac.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PlatformDeviceMac.h; sourceTree = "<group>"; }; 4D3554710ED499EF00FB28B1 /* VectorCanvas.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = VectorCanvas.cpp; sourceTree = "<group>"; }; 4D3554720ED499EF00FB28B1 /* VectorCanvas.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = VectorCanvas.h; sourceTree = "<group>"; }; 4D3554730ED499EF00FB28B1 /* VectorDevice.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = VectorDevice.cpp; sourceTree = "<group>"; }; @@ -4413,14 +4404,8 @@ isa = PBXGroup; children = ( 4D3554650ED499E000FB28B1 /* BitmapPlatformDevice.h */, - 4D3554660ED499E000FB28B1 /* BitmapPlatformDeviceMac.cpp */, - 4D3554670ED499E000FB28B1 /* BitmapPlatformDeviceMac.h */, 4D3554680ED499E000FB28B1 /* PlatformCanvas.h */, - 4D3554690ED499E000FB28B1 /* PlatformCanvasMac.cpp */, - 4D35546A0ED499E000FB28B1 /* PlatformCanvasMac.h */, 4D35546B0ED499E000FB28B1 /* PlatformDevice.h */, - 4D35546C0ED499E000FB28B1 /* PlatformDeviceMac.cpp */, - 4D35546D0ED499E000FB28B1 /* PlatformDeviceMac.h */, 4D3554710ED499EF00FB28B1 /* VectorCanvas.cpp */, 4D3554720ED499EF00FB28B1 /* VectorCanvas.h */, 4D3554730ED499EF00FB28B1 /* VectorDevice.cpp */, @@ -9357,7 +9342,6 @@ 93BF8E990EA6B0E50030F05C /* AuthenticationChallengeChromium.cpp in Sources */, E4006ABA0EC235870055B38E /* AXObjectCacheChromium.cpp in Sources */, E45627EF0E2694B8005E4685 /* BackForwardList.cpp in Sources */, - 4D35546E0ED499E000FB28B1 /* BitmapPlatformDeviceMac.cpp in Sources */, E45627EA0E2694B8005E4685 /* BMPImageDecoder.cpp in Sources */, E45627E90E2694B8005E4685 /* BMPImageReader.cpp in Sources */, E45627EE0E2694B8005E4685 /* CachedPage.cpp in Sources */, @@ -9397,9 +9381,7 @@ E48A07280E3F95A000172919 /* NativeImageSkia.cpp in Sources */, 93BF8E9C0EA6B0F30030F05C /* NetworkStateNotifierChromium.cpp in Sources */, 532E351C0ECA0F290097577C /* PasteboardChromium.cpp in Sources */, - 4D35546F0ED499E000FB28B1 /* PlatformCanvasMac.cpp in Sources */, E4E4C8560E7832E2009A687C /* PlatformContextSkia.cpp in Sources */, - 4D3554700ED499E000FB28B1 /* PlatformDeviceMac.cpp in Sources */, E473F6530EAE002F006C2098 /* PlatformKeyboardEventChromium.cpp in Sources */, E40FB28F0EAFF0BC006F380A /* PlatformScreenMac.mm in Sources */, B507F51C0E9BE98B00D16D77 /* PluginStubsMac.cpp in Sources */, |