michael@0: commit 5786f516119bcb677510f3c9256b870c3b5616c8 michael@0: Author: George Wright michael@0: Date: Wed Aug 15 23:51:34 2012 -0400 michael@0: michael@0: Bug 740194 - [Skia] Implement a version of SkMemory for Mozilla that uses the infallible mozalloc allocators r=cjones michael@0: michael@0: diff --git a/gfx/skia/include/config/SkUserConfig.h b/gfx/skia/include/config/SkUserConfig.h michael@0: index f98ba85..17be191 100644 michael@0: --- a/gfx/skia/include/config/SkUserConfig.h michael@0: +++ b/gfx/skia/include/config/SkUserConfig.h michael@0: @@ -35,6 +35,16 @@ michael@0: commented out, so including it will have no effect. michael@0: */ michael@0: michael@0: +/* michael@0: + Override new/delete with Mozilla's allocator, mozalloc michael@0: + michael@0: + Ideally we shouldn't need to do this here, but until michael@0: + http://code.google.com/p/skia/issues/detail?id=598 is fixed michael@0: + we need to include this here to override operator new and delete michael@0: +*/ michael@0: + michael@0: +#include "mozilla/mozalloc.h" michael@0: + michael@0: /////////////////////////////////////////////////////////////////////////////// michael@0: michael@0: /* Scalars (the fractional value type in skia) can be implemented either as michael@0: diff --git a/gfx/skia/src/ports/SkMemory_mozalloc.cpp b/gfx/skia/src/ports/SkMemory_mozalloc.cpp michael@0: new file mode 100644 michael@0: index 0000000..1f16ee5 michael@0: --- /dev/null michael@0: +++ b/gfx/skia/src/ports/SkMemory_mozalloc.cpp michael@0: @@ -0,0 +1,40 @@ michael@0: +/* michael@0: + * Copyright 2011 Google Inc. michael@0: + * Copyright 2012 Mozilla Foundation michael@0: + * michael@0: + * Use of this source code is governed by a BSD-style license that can be michael@0: + * found in the LICENSE file. michael@0: + */ michael@0: + michael@0: +#include "SkTypes.h" michael@0: + michael@0: +#include "mozilla/mozalloc.h" michael@0: +#include "mozilla/mozalloc_abort.h" michael@0: +#include "mozilla/mozalloc_oom.h" michael@0: + michael@0: +void sk_throw() { michael@0: + SkDEBUGFAIL("sk_throw"); michael@0: + mozalloc_abort("Abort from sk_throw"); michael@0: +} michael@0: + michael@0: +void sk_out_of_memory(void) { michael@0: + SkDEBUGFAIL("sk_out_of_memory"); michael@0: + mozalloc_handle_oom(0); michael@0: +} michael@0: + michael@0: +void* sk_malloc_throw(size_t size) { michael@0: + return sk_malloc_flags(size, SK_MALLOC_THROW); michael@0: +} michael@0: + michael@0: +void* sk_realloc_throw(void* addr, size_t size) { michael@0: + return moz_xrealloc(addr, size); michael@0: +} michael@0: + michael@0: +void sk_free(void* p) { michael@0: + moz_free(p); michael@0: +} michael@0: + michael@0: +void* sk_malloc_flags(size_t size, unsigned flags) { michael@0: + return (flags & SK_MALLOC_THROW) ? moz_xmalloc(size) : moz_malloc(size); michael@0: +} michael@0: +