Skip to content

Commit

Permalink
Provide what looks like the minimal platform specific interface for s…
Browse files Browse the repository at this point in the history
…kia. This will undoubtedly grow in the future.

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@1513 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
erg@google.com committed Aug 28, 2008
1 parent a03a3b2 commit 96ffd0f
Show file tree
Hide file tree
Showing 10 changed files with 237 additions and 4 deletions.
13 changes: 9 additions & 4 deletions base/gfx/SConscript
Original file line number Diff line number Diff line change
Expand Up @@ -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)
6 changes: 6 additions & 0 deletions base/gfx/bitmap_platform_device.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
44 changes: 44 additions & 0 deletions base/gfx/bitmap_platform_device_linux.cc
Original file line number Diff line number Diff line change
@@ -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
31 changes: 31 additions & 0 deletions base/gfx/bitmap_platform_device_linux.h
Original file line number Diff line number Diff line change
@@ -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_
3 changes: 3 additions & 0 deletions base/gfx/platform_canvas.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
46 changes: 46 additions & 0 deletions base/gfx/platform_canvas_linux.cc
Original file line number Diff line number Diff line change
@@ -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
53 changes: 53 additions & 0 deletions base/gfx/platform_canvas_linux.h
Original file line number Diff line number Diff line change
@@ -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_
6 changes: 6 additions & 0 deletions base/gfx/platform_device.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
18 changes: 18 additions & 0 deletions base/gfx/platform_device_linux.cc
Original file line number Diff line number Diff line change
@@ -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
21 changes: 21 additions & 0 deletions base/gfx/platform_device_linux.h
Original file line number Diff line number Diff line change
@@ -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_

0 comments on commit 96ffd0f

Please sign in to comment.