forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Provide what looks like the minimal platform specific interface for s…
…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
Showing
10 changed files
with
237 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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_ |