diff options
author | zhenghao@google.com <zhenghao@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-09-17 06:53:37 +0000 |
---|---|---|
committer | zhenghao@google.com <zhenghao@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-09-17 06:53:37 +0000 |
commit | ac471d2e7f2dc0c31ca385f6905a98ec6aea33f7 (patch) | |
tree | 35317e3d1fb4ac195425b264b4c817ed27d175e7 | |
parent | 4dd687c60a21b7df99aba14b9d715d464ad36724 (diff) | |
download | chromium_src-ac471d2e7f2dc0c31ca385f6905a98ec6aea33f7.zip chromium_src-ac471d2e7f2dc0c31ca385f6905a98ec6aea33f7.tar.gz chromium_src-ac471d2e7f2dc0c31ca385f6905a98ec6aea33f7.tar.bz2 |
Build skia for Android.
Add some files and fix some code to make skia build on Android.
BUG=none
TEST=none
Review URL: http://codereview.chromium.org/7920020
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@101644 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | skia/ext/SkMemory_new_handler.cpp | 8 | ||||
-rw-r--r-- | skia/ext/bitmap_platform_device.cc | 9 | ||||
-rw-r--r-- | skia/ext/bitmap_platform_device.h | 3 | ||||
-rw-r--r-- | skia/ext/bitmap_platform_device_android.cc | 70 | ||||
-rw-r--r-- | skia/ext/bitmap_platform_device_android.h | 51 | ||||
-rw-r--r-- | skia/ext/platform_canvas.h | 4 | ||||
-rw-r--r-- | skia/ext/platform_canvas_linux.cc | 3 | ||||
-rw-r--r-- | skia/ext/platform_device.h | 4 | ||||
-rw-r--r-- | skia/ext/vector_platform_device_skia.cc | 2 | ||||
-rw-r--r-- | skia/ext/vector_platform_device_skia.h | 2 | ||||
-rw-r--r-- | skia/skia.gyp | 11 |
11 files changed, 148 insertions, 19 deletions
diff --git a/skia/ext/SkMemory_new_handler.cpp b/skia/ext/SkMemory_new_handler.cpp index 06bc2c9..b839d04 100644 --- a/skia/ext/SkMemory_new_handler.cpp +++ b/skia/ext/SkMemory_new_handler.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 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. @@ -49,6 +49,10 @@ void sk_free(void* p) { void* sk_malloc_flags(size_t size, unsigned flags) { void* p; +#if defined(ANDROID) + // Android doesn't have std::set_new_handler. + p = malloc(size); +#else if (!(flags & SK_MALLOC_THROW)) { SkAutoMutexAcquire lock(gSkNewHandlerMutex); std::new_handler old_handler = std::set_new_handler(NULL); @@ -57,6 +61,7 @@ void* sk_malloc_flags(size_t size, unsigned flags) { } else { p = malloc(size); } +#endif if (p == NULL) { if (flags & SK_MALLOC_THROW) { sk_throw(); @@ -64,4 +69,3 @@ void* sk_malloc_flags(size_t size, unsigned flags) { } return p; } - diff --git a/skia/ext/bitmap_platform_device.cc b/skia/ext/bitmap_platform_device.cc deleted file mode 100644 index 91b419a..0000000 --- a/skia/ext/bitmap_platform_device.cc +++ /dev/null @@ -1,9 +0,0 @@ -// Copyright (c) 2010 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.h" - -#include "skia/ext/bitmap_platform_device_data.h" -#include "third_party/skia/include/core/SkUtils.h" - diff --git a/skia/ext/bitmap_platform_device.h b/skia/ext/bitmap_platform_device.h index 8063173..52ce651 100644 --- a/skia/ext/bitmap_platform_device.h +++ b/skia/ext/bitmap_platform_device.h @@ -15,7 +15,8 @@ #include "skia/ext/bitmap_platform_device_mac.h" #elif defined(__linux__) || defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__sun) #include "skia/ext/bitmap_platform_device_linux.h" +#elif defined(ANDROID) +#include "skia/ext/bitmap_platform_device_android.h" #endif #endif // SKIA_EXT_BITMAP_PLATFORM_DEVICE_H_ - diff --git a/skia/ext/bitmap_platform_device_android.cc b/skia/ext/bitmap_platform_device_android.cc new file mode 100644 index 0000000..9749e9e --- /dev/null +++ b/skia/ext/bitmap_platform_device_android.cc @@ -0,0 +1,70 @@ +// Copyright (c) 2011 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_android.h" + +namespace skia { + +BitmapPlatformDevice* BitmapPlatformDevice::Create(int width, int height, + bool is_opaque) { + SkBitmap bitmap; + bitmap.setConfig(SkBitmap::kARGB_8888_Config, width, height); + if (bitmap.allocPixels()) { + bitmap.setIsOpaque(is_opaque); + // Follow the logic in SkCanvas::createDevice(), initialize the bitmap if it + // is not opaque. + if (!is_opaque) + bitmap.eraseARGB(0, 0, 0, 0); + return new BitmapPlatformDevice(bitmap); + } + return NULL; +} + +BitmapPlatformDevice* BitmapPlatformDevice::Create(int width, int height, + bool is_opaque, + uint8_t* data) { + SkBitmap bitmap; + bitmap.setConfig(SkBitmap::kARGB_8888_Config, width, height); + if (data) { + bitmap.setPixels(data); + } else { + if (!bitmap.allocPixels()) + return NULL; + // Follow the logic in SkCanvas::createDevice(), initialize the bitmap if it + // is not opaque. + if (!is_opaque) + bitmap.eraseARGB(0, 0, 0, 0); + } + bitmap.setIsOpaque(is_opaque); + return new BitmapPlatformDevice(bitmap); +} + +BitmapPlatformDevice::BitmapPlatformDevice(const SkBitmap& bitmap) + : SkDevice(bitmap) { + SetPlatformDevice(this, this); +} + +BitmapPlatformDevice::~BitmapPlatformDevice() { +} + +SkDevice* BitmapPlatformDevice::onCreateCompatibleDevice( + SkBitmap::Config config, int width, int height, bool isOpaque, + Usage /*usage*/) { + SkASSERT(config == SkBitmap::kARGB_8888_Config); + return BitmapPlatformDevice::Create(width, height, isOpaque); +} + +PlatformSurface BitmapPlatformDevice::BeginPlatformPaint() { + // TODO(zhenghao): What should we return? The ptr to the address of the + // pixels? Maybe this won't be called at all. + return accessBitmap(true).getPixels(); +} + +void BitmapPlatformDevice::DrawToNativeContext( + PlatformSurface surface, int x, int y, const PlatformRect* src_rect) { + // Should never be called on Android. + SkASSERT(false); +} + +} // namespace skia diff --git a/skia/ext/bitmap_platform_device_android.h b/skia/ext/bitmap_platform_device_android.h new file mode 100644 index 0000000..a68c9e6 --- /dev/null +++ b/skia/ext/bitmap_platform_device_android.h @@ -0,0 +1,51 @@ +// Copyright (c) 2011 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_ANDROID_H_ +#define SKIA_EXT_BITMAP_PLATFORM_DEVICE_ANDROID_H_ + +#include "base/memory/ref_counted.h" +#include "base/compiler_specific.h" +#include "skia/ext/platform_device.h" + +namespace skia { + +// ----------------------------------------------------------------------------- +// For now we just use SkBitmap for SkDevice +// +// 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 BitmapPlatformDevice : public PlatformDevice, public SkDevice { + public: + static BitmapPlatformDevice* Create(int width, int height, bool is_opaque); + + // This doesn't take ownership of |data| + static BitmapPlatformDevice* Create(int width, int height, bool is_opaque, + uint8_t* data); + + // Create a BitmapPlatformDevice 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. + explicit BitmapPlatformDevice(const SkBitmap& other); + virtual ~BitmapPlatformDevice(); + + virtual PlatformSurface BeginPlatformPaint() OVERRIDE; + virtual void DrawToNativeContext(PlatformSurface surface, int x, int y, + const PlatformRect* src_rect) OVERRIDE; + + protected: + virtual SkDevice* onCreateCompatibleDevice(SkBitmap::Config, int width, + int height, bool isOpaque, + Usage usage) OVERRIDE; + + private: + DISALLOW_COPY_AND_ASSIGN(BitmapPlatformDevice); +}; + +} // namespace skia + +#endif // SKIA_EXT_BITMAP_PLATFORM_DEVICE_ANDROID_H_ diff --git a/skia/ext/platform_canvas.h b/skia/ext/platform_canvas.h index 354314b..87e2bd2 100644 --- a/skia/ext/platform_canvas.h +++ b/skia/ext/platform_canvas.h @@ -33,7 +33,7 @@ class SK_API PlatformCanvas : public SkCanvas { CGContextRef context); PlatformCanvas(int width, int height, bool is_opaque, uint8_t* context); #elif defined(__linux__) || defined(__FreeBSD__) || defined(__OpenBSD__) || \ - defined(__sun) + defined(__sun) || defined(ANDROID) // Linux --------------------------------------------------------------------- // Construct a canvas from the given memory region. The memory is not cleared @@ -55,7 +55,7 @@ class SK_API PlatformCanvas : public SkCanvas { bool initialize(int width, int height, bool is_opaque, uint8_t* data = NULL); #elif defined(__linux__) || defined(__FreeBSD__) || defined(__OpenBSD__) || \ - defined(__sun) + defined(__sun) || defined(ANDROID) // For two-part init, call if you use the no-argument constructor above bool initialize(int width, int height, bool is_opaque, uint8_t* data = NULL); #endif diff --git a/skia/ext/platform_canvas_linux.cc b/skia/ext/platform_canvas_linux.cc index f471b33..09a0ff4 100644 --- a/skia/ext/platform_canvas_linux.cc +++ b/skia/ext/platform_canvas_linux.cc @@ -4,8 +4,6 @@ #include "skia/ext/platform_canvas.h" -#include <cairo/cairo.h> - #include "skia/ext/bitmap_platform_device.h" #include "skia/ext/platform_device.h" #include "third_party/skia/include/core/SkTypes.h" @@ -25,6 +23,7 @@ PlatformCanvas::PlatformCanvas(int width, int height, bool is_opaque, PlatformCanvas::~PlatformCanvas() { } + bool PlatformCanvas::initialize(int width, int height, bool is_opaque, uint8_t* data) { return initializeWithDevice(BitmapPlatformDevice::Create( diff --git a/skia/ext/platform_device.h b/skia/ext/platform_device.h index 2e441be..179a8e8 100644 --- a/skia/ext/platform_device.h +++ b/skia/ext/platform_device.h @@ -46,6 +46,10 @@ typedef cairo_rectangle_t PlatformRect; #elif defined(OS_MACOSX) typedef CGContextRef PlatformSurface; typedef CGRect PlatformRect; +#elif defined(ANDROID) +// TODO(tonyg): FIX TYPES! +typedef void* PlatformSurface; +typedef void* PlatformRect; #endif // The following routines provide accessor points for the functionality diff --git a/skia/ext/vector_platform_device_skia.cc b/skia/ext/vector_platform_device_skia.cc index a320526..466b64c 100644 --- a/skia/ext/vector_platform_device_skia.cc +++ b/skia/ext/vector_platform_device_skia.cc @@ -88,7 +88,7 @@ CGContextRef VectorPlatformDeviceSkia::GetBitmapContext() { SkASSERT(false); return NULL; } -#elif defined(OS_LINUX) +#elif defined(OS_LINUX) || defined(OS_ANDROID) void VectorPlatformDeviceSkia::DrawToNativeContext( PlatformSurface surface, int x, int y, const PlatformRect* src_rect) { // Should never be called on Linux. diff --git a/skia/ext/vector_platform_device_skia.h b/skia/ext/vector_platform_device_skia.h index 005d798..692aca8 100644 --- a/skia/ext/vector_platform_device_skia.h +++ b/skia/ext/vector_platform_device_skia.h @@ -40,7 +40,7 @@ class VectorPlatformDeviceSkia : public PlatformDevice, public SkPDFDevice { virtual void DrawToNativeContext(CGContext* context, int x, int y, const CGRect* src_rect); virtual CGContextRef GetBitmapContext(); -#elif defined(OS_LINUX) +#elif defined(OS_LINUX) || defined(OS_ANDROID) virtual void DrawToNativeContext(PlatformSurface surface, int x, int y, const PlatformRect* src_rect); #endif diff --git a/skia/skia.gyp b/skia/skia.gyp index 610472e..daecaae 100644 --- a/skia/skia.gyp +++ b/skia/skia.gyp @@ -664,8 +664,9 @@ '../third_party/skia/include/images/SkMovie.h', '../third_party/skia/include/images/SkPageFlipper.h', - 'ext/bitmap_platform_device.cc', 'ext/bitmap_platform_device.h', + 'ext/bitmap_platform_device_android.cc', + 'ext/bitmap_platform_device_android.h', 'ext/bitmap_platform_device_data.h', 'ext/bitmap_platform_device_linux.cc', 'ext/bitmap_platform_device_linux.h', @@ -752,6 +753,14 @@ '../third_party/skia/src/ports/SkFontHost_tables.cpp', ], }], + [ 'OS == "android"', { + 'sources/': [ + ['include', 'ext/platform_device_linux.cc'], + ['include', 'ext/platform_canvas_linux.cc'], + ], + }, { # OS != "android" + 'sources/': [ ['exclude', '_android\\.(cc|cpp)$'] ], + }], [ 'OS != "win"', { 'sources/': [ ['exclude', '_win\\.(cc|cpp)$'] ], }], |