summaryrefslogtreecommitdiffstats
path: root/base
diff options
context:
space:
mode:
Diffstat (limited to 'base')
-rw-r--r--base/gfx/SConscript13
-rw-r--r--base/gfx/bitmap_platform_device.h6
-rw-r--r--base/gfx/bitmap_platform_device_linux.cc44
-rw-r--r--base/gfx/bitmap_platform_device_linux.h31
-rw-r--r--base/gfx/platform_canvas.h3
-rw-r--r--base/gfx/platform_canvas_linux.cc46
-rw-r--r--base/gfx/platform_canvas_linux.h53
-rw-r--r--base/gfx/platform_device.h6
-rw-r--r--base/gfx/platform_device_linux.cc18
-rw-r--r--base/gfx/platform_device_linux.h21
10 files changed, 237 insertions, 4 deletions
diff --git a/base/gfx/SConscript b/base/gfx/SConscript
index 37939f8..e7687a3 100644
--- a/base/gfx/SConscript
+++ b/base/gfx/SConscript
@@ -87,10 +87,15 @@ if env['PLATFORM'] == 'win32':
if env['PLATFORM'] == 'win32':
input_files.extend([
- 'bitmap_platform_device_win.cc',
- 'platform_canvas_win.cc',
- 'platform_device_win.cc',
-
+ 'bitmap_platform_device_win.cc',
+ 'platform_canvas_win.cc',
+ 'platform_device_win.cc',
+ ])
+elif env['PLATFORM'] == 'posix':
+ input_files.extend([
+ 'bitmap_platform_device_linux.cc',
+ 'platform_canvas_linux.cc',
+ 'platform_device_linux.cc',
])
env.ChromeStaticLibrary('base_gfx', input_files)
diff --git a/base/gfx/bitmap_platform_device.h b/base/gfx/bitmap_platform_device.h
index 9b4ecd7..83b74df 100644
--- a/base/gfx/bitmap_platform_device.h
+++ b/base/gfx/bitmap_platform_device.h
@@ -6,11 +6,17 @@
// that can be used by upper-level classes that just need to pass a reference
// around.
+namespace gfx {
+
#if defined(OS_WIN)
class BitmapPlatformDeviceWin;
typedef BitmapPlatformDeviceWin BitmapPlatformDevice;
#elif defined(OS_MACOSX)
class BitmapPlatformDeviceMac;
typedef BitmapPlatformDeviceMac BitmapPlatformDevice;
+#elif defined(OS_LINUX)
+class BitmapPlatformDeviceLinux;
+typedef BitmapPlatformDeviceLinux BitmapPlatformDevice;
#endif
+} // namespace gfx
diff --git a/base/gfx/bitmap_platform_device_linux.cc b/base/gfx/bitmap_platform_device_linux.cc
new file mode 100644
index 0000000..1211a15
--- /dev/null
+++ b/base/gfx/bitmap_platform_device_linux.cc
@@ -0,0 +1,44 @@
+// 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 "base/gfx/bitmap_platform_device_linux.h"
+
+#include "base/logging.h"
+
+#include <time.h>
+
+namespace gfx {
+
+// 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) {
+ SkBitmap bitmap;
+ bitmap.setConfig(SkBitmap::kARGB_8888_Config, width, height);
+ 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
+ }
+
+ // The device object will take ownership of the graphics context.
+ return new BitmapPlatformDeviceLinux(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.
+BitmapPlatformDeviceLinux::BitmapPlatformDeviceLinux(const SkBitmap& bitmap)
+ : PlatformDeviceLinux(bitmap) {
+}
+
+BitmapPlatformDeviceLinux::~BitmapPlatformDeviceLinux() {
+}
+
+} // namespace gfx
diff --git a/base/gfx/bitmap_platform_device_linux.h b/base/gfx/bitmap_platform_device_linux.h
new file mode 100644
index 0000000..d8504dc
--- /dev/null
+++ b/base/gfx/bitmap_platform_device_linux.h
@@ -0,0 +1,31 @@
+// 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 BASE_GFX_BITMAP_PLATFORM_DEVICE_LINUX_H_
+#define BASE_GFX_BITMAP_PLATFORM_DEVICE_LINUX_H_
+
+#include "base/gfx/platform_device_linux.h"
+#include "base/ref_counted.h"
+
+namespace gfx {
+
+// I'm trying to get away with defining as little as possible on this. Right
+// now, we don't do anything.
+class BitmapPlatformDeviceLinux : public PlatformDeviceLinux {
+ 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.
+ BitmapPlatformDeviceLinux(const SkBitmap& other);
+ virtual ~BitmapPlatformDeviceLinux();
+};
+
+} // namespace gfx
+
+#endif // BASE_GFX_BITMAP_PLATFORM_DEVICE_LINUX_H_
diff --git a/base/gfx/platform_canvas.h b/base/gfx/platform_canvas.h
index 3219a7a..d7433cd 100644
--- a/base/gfx/platform_canvas.h
+++ b/base/gfx/platform_canvas.h
@@ -16,6 +16,9 @@ typedef PlatformCanvasWin PlatformCanvas;
#elif defined(OS_MACOSX)
class PlatformCanvasMac;
typedef PlatformCanvasMac PlatformCanvas;
+#elif defined(OS_LINUX)
+class PlatformCanvasLinux;
+typedef PlatformCanvasLinux PlatformCanvas;
#endif
} // namespace gfx
diff --git a/base/gfx/platform_canvas_linux.cc b/base/gfx/platform_canvas_linux.cc
new file mode 100644
index 0000000..71bc8f08
--- /dev/null
+++ b/base/gfx/platform_canvas_linux.cc
@@ -0,0 +1,46 @@
+// 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 "base/gfx/platform_canvas_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() {
+ initialize(width, height, is_opaque);
+}
+
+PlatformCanvasLinux::~PlatformCanvasLinux() {
+}
+
+void PlatformCanvasLinux::initialize(int width, int height, bool is_opaque) {
+ SkDevice* device = createPlatformDevice(width, height, is_opaque);
+ setDevice(device);
+ device->unref(); // was created with refcount 1, and setDevice also refs
+}
+
+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, int width,
+ int height, bool is_opaque) {
+ 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/base/gfx/platform_canvas_linux.h b/base/gfx/platform_canvas_linux.h
new file mode 100644
index 0000000..4030a55
--- /dev/null
+++ b/base/gfx/platform_canvas_linux.h
@@ -0,0 +1,53 @@
+// 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 BASE_GFX_PLATFORM_CANVAS_LINUX_H_
+#define BASE_GFX_PLATFORM_CANVAS_LINUX_H_
+
+#include "base/gfx/platform_device_linux.h"
+#include "base/basictypes.h"
+
+#import "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 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
+ void 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);
+
+ // 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);
+};
+
+} // namespace gfx
+
+#endif // BASE_GFX_PLATFORM_CANVAS_MAC_H_
diff --git a/base/gfx/platform_device.h b/base/gfx/platform_device.h
index 644e89d..796eec8 100644
--- a/base/gfx/platform_device.h
+++ b/base/gfx/platform_device.h
@@ -6,11 +6,17 @@
// that can be used by upper-level classes that just need to pass a reference
// around.
+namespace gfx {
+
#if defined(OS_WIN)
class PlatformDeviceWin;
typedef PlatformDeviceWin PlatformDevice;
#elif defined(OS_MACOSX)
class PlatformDeviceMac;
typedef PlatformDeviceMac PlatformDevice;
+#elif defined(OS_LINUX)
+class PlatformDeviceLinux;
+typedef PlatformDeviceLinux PlatformDevice;
#endif
+} // namespace gfx
diff --git a/base/gfx/platform_device_linux.cc b/base/gfx/platform_device_linux.cc
new file mode 100644
index 0000000..1f948b1
--- /dev/null
+++ b/base/gfx/platform_device_linux.cc
@@ -0,0 +1,18 @@
+// 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 "base/gfx/platform_device_linux.h"
+
+#include "base/logging.h"
+#include "SkMatrix.h"
+#include "SkPath.h"
+#include "SkUtils.h"
+
+namespace gfx {
+
+PlatformDeviceLinux::PlatformDeviceLinux(const SkBitmap& bitmap)
+ : SkDevice(bitmap) {
+}
+
+} // namespace gfx
diff --git a/base/gfx/platform_device_linux.h b/base/gfx/platform_device_linux.h
new file mode 100644
index 0000000..52fbfae
--- /dev/null
+++ b/base/gfx/platform_device_linux.h
@@ -0,0 +1,21 @@
+// 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 BASE_GFX_PLATFORM_DEVICE_LINUX_H_
+#define BASE_GFX_PLATFORM_DEVICE_LINUX_H_
+
+#include "SkDevice.h"
+
+namespace gfx {
+
+// Blindly copying the mac hierarchy.
+class PlatformDeviceLinux : public SkDevice {
+ protected:
+ // Forwards |bitmap| to SkDevice's constructor.
+ PlatformDeviceLinux(const SkBitmap& bitmap);
+};
+
+} // namespace gfx
+
+#endif // BASE_GFX_PLATFORM_DEVICE_LINUX_H_