Bug 740194 - [Skia] Implement a version of SkMemory for Mozilla that uses the infallible mozalloc allocators r=cjones
☠☠ backed out by 5fbacb9e6e62 ☠ ☠
authorGeorge Wright <gwright@mozilla.com>
Wed, 15 Aug 2012 16:59:07 -0400
changeset 107944 c2475674e105eef9a93a5adad033745308040271
parent 107943 2f0808dd3a119eba5b020fdd52ed24593ccf0434
child 107945 5fbacb9e6e627f1a10a19a55979741eba6a9190f
push id1490
push userakeybl@mozilla.com
push dateMon, 08 Oct 2012 18:29:50 +0000
treeherdermozilla-beta@f335e7dacdc1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerscjones
bugs740194
milestone17.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
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_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