Bug 740194 - [Skia] Implement a version of SkMemory for Mozilla that uses the infallible mozalloc allocators r=cjones
authorGeorge Wright <gwright@mozilla.com>
Wed, 15 Aug 2012 23:51:34 -0400
changeset 107974 da866a8a19e384f197d62109d03fd5be32b3d9ef
parent 107973 56ae921df543697d729b8b77f2b3b2dd9fc0c5e7
child 107975 418b5cbc7cd9f259d950526cb450881d4d6d4a1e
push idunknown
push userunknown
push dateunknown
reviewerscjones
bugs740194
milestone17.0a1
Bug 740194 - [Skia] Implement a version of SkMemory for Mozilla that uses the infallible mozalloc allocators r=cjones
Makefile.in
gfx/skia/Makefile.in
gfx/skia/include/config/SkUserConfig.h
gfx/skia/src/ports/SkMemory_mozalloc.cpp
toolkit/toolkit-tiers.mk
--- a/Makefile.in
+++ b/Makefile.in
@@ -32,17 +32,16 @@ tier_base_dirs = \
   probes \
   mfbt \
   $(NULL)
 
 ifndef LIBXUL_SDK
 ifeq (android,$(MOZ_WIDGET_TOOLKIT))
 tier_base_dirs += \
   other-licenses/android \
-  other-licenses/skia-npapi \
   $(NULL)
 endif
 ifeq (gonk,$(MOZ_WIDGET_TOOLKIT))
 tier_base_dirs += \
   other-licenses/android \
   $(NULL)
 endif
 
--- a/gfx/skia/Makefile.in
+++ b/gfx/skia/Makefile.in
@@ -226,17 +226,17 @@ CPPSRCS = \
 	SkLayerDrawLooper.cpp \
 	SkLayerRasterizer.cpp \
 	SkLineClipper.cpp \
 	SkMallocPixelRef.cpp \
 	SkMask.cpp \
 	SkMaskFilter.cpp \
 	SkMath.cpp \
 	SkMatrix.cpp \
-	SkMemory_malloc.cpp \
+	SkMemory_mozalloc.cpp \
 	SkMetaData.cpp \
 	SkMorphologyImageFilter.cpp \
 	SkOrderedReadBuffer.cpp \
 	SkOrderedWriteBuffer.cpp \
 	SkOSFile_stdio.cpp \
 	SkOTUtils.cpp \
 	SkPackBits.cpp \
 	SkPaint.cpp \
--- a/gfx/skia/include/config/SkUserConfig.h
+++ b/gfx/skia/include/config/SkUserConfig.h
@@ -30,16 +30,26 @@
     Below are optional defines that add, subtract, or change default behavior
     in Skia. Your port can locally edit this file to enable/disable flags as
     you choose, or these can be delared on your command line (i.e. -Dfoo).
 
     By default, this include file will always default to having all of the flags
     commented out, so including it will have no effect.
 */
 
+/*
+    Override new/delete with Mozilla's allocator, mozalloc
+
+    Ideally we shouldn't need to do this here, but until
+    http://code.google.com/p/skia/issues/detail?id=598 is fixed
+    we need to include this here to override operator new and delete
+*/
+
+#include "mozilla/mozalloc.h"
+
 ///////////////////////////////////////////////////////////////////////////////
 
 /*  Scalars (the fractional value type in skia) can be implemented either as
     floats or 16.16 integers (fixed). Exactly one of these two symbols must be
     defined.
 */
 //#define SK_SCALAR_IS_FLOAT
 //#define SK_SCALAR_IS_FIXED
new file mode 100644
--- /dev/null
+++ b/gfx/skia/src/ports/SkMemory_mozalloc.cpp
@@ -0,0 +1,40 @@
+/*
+ * Copyright 2011 Google Inc.
+ * Copyright 2012 Mozilla Foundation
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#include "SkTypes.h"
+
+#include "mozilla/mozalloc.h"
+#include "mozilla/mozalloc_abort.h"
+#include "mozilla/mozalloc_oom.h"
+
+void sk_throw() {
+    SkDEBUGFAIL("sk_throw");
+    mozalloc_abort("Abort from sk_throw");
+}
+
+void sk_out_of_memory(void) {
+    SkDEBUGFAIL("sk_out_of_memory");
+    mozalloc_handle_oom(0);
+}
+
+void* sk_malloc_throw(size_t size) {
+    return sk_malloc_flags(size, SK_MALLOC_THROW);
+}
+
+void* sk_realloc_throw(void* addr, size_t size) {
+    return moz_xrealloc(addr, size);
+}
+
+void sk_free(void* p) {
+    moz_free(p);
+}
+
+void* sk_malloc_flags(size_t size, unsigned flags) {
+    return (flags & SK_MALLOC_THROW) ? moz_xmalloc(size) : moz_malloc(size);
+}
+
--- a/toolkit/toolkit-tiers.mk
+++ b/toolkit/toolkit-tiers.mk
@@ -174,16 +174,23 @@ tier_platform_dirs	+= \
 		content \
 		editor \
 		layout \
 		docshell \
 		embedding \
 		xpfe/appshell \
 		$(NULL)
 
+# This needs to be built after the gfx/ directory
+# to ensure all dependencies for skia (e.g. mozalloc, xpcom)
+# have been built
+ifeq (android,$(MOZ_WIDGET_TOOLKIT))
+tier_platform_dirs += other-licenses/skia-npapi
+endif
+
 ifdef MOZ_UNIVERSALCHARDET
 tier_platform_dirs += extensions/universalchardet
 endif
 
 ifdef ACCESSIBILITY
 tier_platform_dirs    += accessible
 endif