summaryrefslogtreecommitdiffstats
path: root/skia
diff options
context:
space:
mode:
authorbrettw@google.com <brettw@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2008-11-22 00:10:00 +0000
committerbrettw@google.com <brettw@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2008-11-22 00:10:00 +0000
commit8c2fcd19acaa0b3aeeae0aacd0f698d9d0e4b0a4 (patch)
tree9ae4cf3df2df8b9816abbeeefcde36b6dd33a040 /skia
parentfbbb58d4c5cc57c72b84ee4337b155e2a64224e1 (diff)
downloadchromium_src-8c2fcd19acaa0b3aeeae0aacd0f698d9d0e4b0a4.zip
chromium_src-8c2fcd19acaa0b3aeeae0aacd0f698d9d0e4b0a4.tar.gz
chromium_src-8c2fcd19acaa0b3aeeae0aacd0f698d9d0e4b0a4.tar.bz2
Move port/.../skia/public to skia/ext for Linux. Windows & Mac already moved there. This leaves forwarding headers in base/gfx, which I'll clean up in a future pass.
Review URL: http://codereview.chromium.org/11808 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@5873 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'skia')
-rw-r--r--skia/SConscript4
-rw-r--r--skia/ext/bitmap_platform_device.h30
-rw-r--r--skia/ext/bitmap_platform_device_linux.cc94
-rw-r--r--skia/ext/bitmap_platform_device_linux.h91
-rw-r--r--skia/ext/platform_canvas.h30
-rw-r--r--skia/ext/platform_canvas_linux.cc55
-rw-r--r--skia/ext/platform_canvas_linux.h52
-rw-r--r--skia/ext/platform_device_linux.cc13
-rw-r--r--skia/ext/platform_device_linux.h25
9 files changed, 394 insertions, 0 deletions
diff --git a/skia/SConscript b/skia/SConscript
index 97ea1be..0178f38 100644
--- a/skia/SConscript
+++ b/skia/SConscript
@@ -155,6 +155,10 @@ input_files = [
]
if env['PLATFORM'] == 'posix':
+ input_files.append('ext/bitmap_platform_device_linux.cc')
+ input_files.append('ext/platform_canvas_linux.cc')
+ input_files.append('ext/platform_device_linux.cc')
+
# On Linux we use Skia to render fonts with FreeType and fontconfig
input_files.remove('sgl/SkTypeface_fake.cpp')
input_files.remove('ports/SkFontHost_none.cpp')
diff --git a/skia/ext/bitmap_platform_device.h b/skia/ext/bitmap_platform_device.h
new file mode 100644
index 0000000..d33ae73
--- /dev/null
+++ b/skia/ext/bitmap_platform_device.h
@@ -0,0 +1,30 @@
+// 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.
+
+// Declare a platform-neutral name for this platform's bitmap device class
+// that can be used by upper-level classes that just need to pass a reference
+// around.
+
+#if defined(WIN32)
+#include "skia/ext/bitmap_platform_device_win.h"
+namespace gfx {
+
+typedef BitmapPlatformDeviceWin BitmapPlatformDevice;
+
+} // namespace gfx
+#elif defined(__APPLE__)
+#include "skia/ext/bitmap_platform_device_mac.h"
+namespace gfx {
+
+typedef BitmapPlatformDeviceMac BitmapPlatformDevice;
+
+} // namespace gfx
+#elif defined(__linux__)
+#include "skia/ext/bitmap_platform_device_linux.h"
+namespace gfx {
+
+typedef BitmapPlatformDeviceLinux BitmapPlatformDevice;
+
+} // namespace gfx
+#endif
diff --git a/skia/ext/bitmap_platform_device_linux.cc b/skia/ext/bitmap_platform_device_linux.cc
new file mode 100644
index 0000000..4dd322d
--- /dev/null
+++ b/skia/ext/bitmap_platform_device_linux.cc
@@ -0,0 +1,94 @@
+// 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 "skia/ext/bitmap_platform_device_linux.h"
+
+#include <cairo/cairo.h>
+
+#include "base/logging.h"
+
+namespace gfx {
+
+// -----------------------------------------------------------------------------
+// These objects are reference counted and own a Cairo surface. The surface is
+// the backing store for a Skia bitmap and we reference count it so that we can
+// copy BitmapPlatformDeviceLinux objects without having to copy all the image
+// data.
+// -----------------------------------------------------------------------------
+class BitmapPlatformDeviceLinux::BitmapPlatformDeviceLinuxData
+ : public base::RefCounted<BitmapPlatformDeviceLinuxData> {
+ public:
+ explicit BitmapPlatformDeviceLinuxData(cairo_surface_t* surface)
+ : surface_(surface) { }
+
+ cairo_surface_t* surface() const { return surface_; }
+
+ protected:
+ cairo_surface_t *const surface_;
+
+ friend class base::RefCounted<BitmapPlatformDeviceLinuxData>;
+ ~BitmapPlatformDeviceLinuxData() {
+ cairo_surface_destroy(surface_);
+ }
+
+ DISALLOW_EVIL_CONSTRUCTORS(BitmapPlatformDeviceLinuxData);
+};
+
+// 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.
+BitmapPlatformDeviceLinux* BitmapPlatformDeviceLinux::Create(
+ int width, int height, bool is_opaque) {
+ cairo_surface_t* surface =
+ cairo_image_surface_create(CAIRO_FORMAT_ARGB32,
+ width, height);
+
+ SkBitmap bitmap;
+ bitmap.setConfig(SkBitmap::kARGB_8888_Config, width, height,
+ cairo_image_surface_get_stride(surface));
+ bitmap.setPixels(cairo_image_surface_get_data(surface));
+ bitmap.setIsOpaque(is_opaque);
+
+#ifndef NDEBUG
+ if (is_opaque) {
+ bitmap.eraseARGB(255, 0, 255, 128); // bright bluish green
+ }
+#endif
+
+ // The device object will take ownership of the graphics context.
+ return new BitmapPlatformDeviceLinux
+ (bitmap, new BitmapPlatformDeviceLinuxData(surface));
+}
+
+// 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.
+BitmapPlatformDeviceLinux::BitmapPlatformDeviceLinux(
+ const SkBitmap& bitmap,
+ BitmapPlatformDeviceLinuxData* data)
+ : PlatformDeviceLinux(bitmap),
+ data_(data) {
+}
+
+BitmapPlatformDeviceLinux::BitmapPlatformDeviceLinux(
+ const BitmapPlatformDeviceLinux& other)
+ : PlatformDeviceLinux(const_cast<BitmapPlatformDeviceLinux&>(
+ other).accessBitmap(true)),
+ data_(other.data_) {
+}
+
+BitmapPlatformDeviceLinux::~BitmapPlatformDeviceLinux() {
+}
+
+cairo_surface_t* BitmapPlatformDeviceLinux::surface() const {
+ return data_->surface();
+}
+
+BitmapPlatformDeviceLinux& BitmapPlatformDeviceLinux::operator=(
+ const BitmapPlatformDeviceLinux& other) {
+ data_ = other.data_;
+ return *this;
+}
+
+} // namespace gfx
diff --git a/skia/ext/bitmap_platform_device_linux.h b/skia/ext/bitmap_platform_device_linux.h
new file mode 100644
index 0000000..14e4c0c
--- /dev/null
+++ b/skia/ext/bitmap_platform_device_linux.h
@@ -0,0 +1,91 @@
+// 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 SKIA_EXT_BITMAP_PLATFORM_DEVICE_LINUX_H_
+#define SKIA_EXT_BITMAP_PLATFORM_DEVICE_LINUX_H_
+
+#include "base/ref_counted.h"
+#include "skia/ext/platform_device_linux.h"
+
+typedef struct _cairo_surface cairo_surface_t;
+
+// -----------------------------------------------------------------------------
+// Image byte ordering on Linux:
+//
+// Pixels are packed into 32-bit words these days. Even for 24-bit images,
+// often 8-bits will be left unused for alignment reasons. Thus, when you see
+// ARGB as the byte order you have to wonder if that's in memory order or
+// little-endian order. Here I'll write A.R.G.B to specifiy the memory order.
+//
+// GdkPixbuf's provide a nice backing store and defaults to R.G.B.A order.
+// They'll do the needed byte swapping to match the X server when drawn.
+//
+// Skia can be controled in skia/include/corecg/SkUserConfig.h (see bits about
+// SK_R32_SHIFT). For Linux we define it to be ARGB in registers. For little
+// endian machines that means B.G.R.A in memory.
+//
+// The image loaders are controlled in
+// webkit/port/platform/image-decoders/ImageDecoder.h (see setRGBA). These are
+// also configured for ARGB in registers.
+//
+// Cairo's only 32-bit mode is ARGB in registers.
+//
+// X servers commonly have a 32-bit visual with xRGB in registers (since they
+// typically don't do alpha blending of drawables at the user level. Composite
+// extensions aside.)
+//
+// We don't use GdkPixbuf because its byte order differs from the rest. Most
+// importantly, it differs from Cairo which, being a system library, is
+// something that we can't easily change.
+// -----------------------------------------------------------------------------
+
+namespace gfx {
+
+// -----------------------------------------------------------------------------
+// This is the Linux bitmap backing for Skia. We create a Cairo image surface
+// to store the backing buffer. This buffer is BGRA in memory (on little-endian
+// machines).
+//
+// For now we are also using Cairo to paint to the Drawables so we provide an
+// accessor for getting the surface.
+//
+// This is all quite ok for test_shell. In the future we will want to use
+// shared memory between the renderer and the main process at least. In this
+// case we'll probably create the buffer from a precreated region of memory.
+// -----------------------------------------------------------------------------
+class BitmapPlatformDeviceLinux : public PlatformDeviceLinux {
+ // A reference counted cairo surface
+ class BitmapPlatformDeviceLinuxData;
+
+ public:
+ /// Static constructor. I don't understand this, it's just a copy of the mac
+ static BitmapPlatformDeviceLinux* Create(int width, int height,
+ bool is_opaque);
+
+ // Create a BitmapPlatformDeviceLinux from an already constructed bitmap;
+ // you should probably be using Create(). This may become private later if
+ // we ever have to share state between some native drawing UI and Skia, like
+ // the Windows and Mac versions of this class do.
+ //
+ // This object takes ownership of @data.
+ BitmapPlatformDeviceLinux(const SkBitmap& other,
+ BitmapPlatformDeviceLinuxData* data);
+ virtual ~BitmapPlatformDeviceLinux();
+ BitmapPlatformDeviceLinux& operator=(const BitmapPlatformDeviceLinux& other);
+
+ // A stub copy constructor. Needs to be properly implemented.
+ BitmapPlatformDeviceLinux(const BitmapPlatformDeviceLinux& other);
+
+ // Bitmaps aren't vector graphics.
+ virtual bool IsVectorial() { return false; }
+
+ cairo_surface_t* surface() const;
+
+ private:
+ scoped_refptr<BitmapPlatformDeviceLinuxData> data_;
+};
+
+} // namespace gfx
+
+#endif // SKIA_EXT_BITMAP_PLATFORM_DEVICE_LINUX_H_
diff --git a/skia/ext/platform_canvas.h b/skia/ext/platform_canvas.h
new file mode 100644
index 0000000..b1e4310
--- /dev/null
+++ b/skia/ext/platform_canvas.h
@@ -0,0 +1,30 @@
+// 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.
+
+// Declare a platform-neutral name for this platform's canvas class
+// that can be used by upper-level classes that just need to pass a reference
+// around.
+
+#if defined(WIN32)
+#include "skia/ext/platform_canvas_win.h"
+namespace gfx {
+
+typedef PlatformCanvasWin PlatformCanvas;
+
+} // namespace gfx
+#elif defined(__APPLE__)
+#include "skia/ext/platform_canvas_mac.h"
+namespace gfx {
+
+typedef PlatformCanvasMac PlatformCanvas;
+
+} // namespace gfx
+#elif defined(__linux__)
+#include "skia/ext/platform_canvas_linux.h"
+namespace gfx {
+
+typedef PlatformCanvasLinux PlatformCanvas;
+
+} // namespace gfx
+#endif
diff --git a/skia/ext/platform_canvas_linux.cc b/skia/ext/platform_canvas_linux.cc
new file mode 100644
index 0000000..126c7ff
--- /dev/null
+++ b/skia/ext/platform_canvas_linux.cc
@@ -0,0 +1,55 @@
+// 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 "skia/ext/platform_canvas_linux.h"
+
+#include "base/gfx/platform_device_linux.h"
+#include "base/gfx/bitmap_platform_device_linux.h"
+#include "base/logging.h"
+
+namespace gfx {
+
+PlatformCanvasLinux::PlatformCanvasLinux() : SkCanvas() {
+}
+
+PlatformCanvasLinux::PlatformCanvasLinux(int width, int height, bool is_opaque)
+ : SkCanvas() {
+ if (!initialize(width, height, is_opaque))
+ CHECK(false);
+}
+
+PlatformCanvasLinux::~PlatformCanvasLinux() {
+}
+
+bool PlatformCanvasLinux::initialize(int width, int height, bool is_opaque) {
+ SkDevice* device = createPlatformDevice(width, height, is_opaque);
+ if (!device)
+ return false;
+
+ setDevice(device);
+ device->unref(); // was created with refcount 1, and setDevice also refs
+ return true;
+}
+
+PlatformDeviceLinux& PlatformCanvasLinux::getTopPlatformDevice() const {
+ // All of our devices should be our special PlatformDevice.
+ SkCanvas::LayerIter iter(const_cast<PlatformCanvasLinux*>(this), false);
+ return *static_cast<PlatformDeviceLinux*>(iter.device());
+}
+
+SkDevice* PlatformCanvasLinux::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);
+}
+
+SkDevice* PlatformCanvasLinux::createPlatformDevice(int width,
+ int height,
+ bool is_opaque) {
+ return BitmapPlatformDeviceLinux::Create(width, height, is_opaque);
+}
+
+} // namespace gfx
diff --git a/skia/ext/platform_canvas_linux.h b/skia/ext/platform_canvas_linux.h
new file mode 100644
index 0000000..e2153a7
--- /dev/null
+++ b/skia/ext/platform_canvas_linux.h
@@ -0,0 +1,52 @@
+// 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 SKIA_EXT_PLATFORM_CANVAS_LINUX_H_
+#define SKIA_EXT_PLATFORM_CANVAS_LINUX_H_
+
+#include "PlatformDeviceLinux.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 PlatformCanvasLinux : 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()
+ PlatformCanvasLinux();
+ PlatformCanvasLinux(int width, int height, bool is_opaque);
+ virtual ~PlatformCanvasLinux();
+
+ // For two-part init, call if you use the no-argument constructor above
+ bool initialize(int width, int height, bool is_opaque);
+
+ // Returns the platform device pointer of the topmost rect with a non-empty
+ // clip. Both the windows and mac versions have an equivalent of this method;
+ // a Linux version is added for compatibility.
+ PlatformDeviceLinux& getTopPlatformDevice() const;
+
+ 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);
+
+ // Disallow copy and assign.
+ PlatformCanvasLinux(const PlatformCanvasLinux&);
+ PlatformCanvasLinux& operator=(const PlatformCanvasLinux&);
+};
+
+} // namespace gfx
+
+#endif // SKIA_EXT_PLATFORM_CANVAS_LINUX_H_
diff --git a/skia/ext/platform_device_linux.cc b/skia/ext/platform_device_linux.cc
new file mode 100644
index 0000000..f148ed1
--- /dev/null
+++ b/skia/ext/platform_device_linux.cc
@@ -0,0 +1,13 @@
+// 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 "skia/ext/platform_device_linux.h"
+
+namespace gfx {
+
+PlatformDeviceLinux::PlatformDeviceLinux(const SkBitmap& bitmap)
+ : SkDevice(bitmap) {
+}
+
+} // namespace gfx
diff --git a/skia/ext/platform_device_linux.h b/skia/ext/platform_device_linux.h
new file mode 100644
index 0000000..185baf0
--- /dev/null
+++ b/skia/ext/platform_device_linux.h
@@ -0,0 +1,25 @@
+// 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 SKIA_EXT_PLATFORM_DEVICE_LINUX_H_
+#define SKIA_EXT_PLATFORM_DEVICE_LINUX_H_
+
+#include "SkDevice.h"
+
+namespace gfx {
+
+// Blindly copying the mac hierarchy.
+class PlatformDeviceLinux : public SkDevice {
+ public:
+ // Returns if the preferred rendering engine is vectorial or bitmap based.
+ virtual bool IsVectorial() = 0;
+
+ protected:
+ // Forwards |bitmap| to SkDevice's constructor.
+ PlatformDeviceLinux(const SkBitmap& bitmap);
+};
+
+} // namespace gfx
+
+#endif // SKIA_EXT_PLATFORM_DEVICE_LINUX_H_