|
1 commit 5786f516119bcb677510f3c9256b870c3b5616c8 |
|
2 Author: George Wright <gwright@mozilla.com> |
|
3 Date: Wed Aug 15 23:51:34 2012 -0400 |
|
4 |
|
5 Bug 740194 - [Skia] Implement a version of SkMemory for Mozilla that uses the infallible mozalloc allocators r=cjones |
|
6 |
|
7 diff --git a/gfx/skia/include/config/SkUserConfig.h b/gfx/skia/include/config/SkUserConfig.h |
|
8 index f98ba85..17be191 100644 |
|
9 --- a/gfx/skia/include/config/SkUserConfig.h |
|
10 +++ b/gfx/skia/include/config/SkUserConfig.h |
|
11 @@ -35,6 +35,16 @@ |
|
12 commented out, so including it will have no effect. |
|
13 */ |
|
14 |
|
15 +/* |
|
16 + Override new/delete with Mozilla's allocator, mozalloc |
|
17 + |
|
18 + Ideally we shouldn't need to do this here, but until |
|
19 + http://code.google.com/p/skia/issues/detail?id=598 is fixed |
|
20 + we need to include this here to override operator new and delete |
|
21 +*/ |
|
22 + |
|
23 +#include "mozilla/mozalloc.h" |
|
24 + |
|
25 /////////////////////////////////////////////////////////////////////////////// |
|
26 |
|
27 /* Scalars (the fractional value type in skia) can be implemented either as |
|
28 diff --git a/gfx/skia/src/ports/SkMemory_mozalloc.cpp b/gfx/skia/src/ports/SkMemory_mozalloc.cpp |
|
29 new file mode 100644 |
|
30 index 0000000..1f16ee5 |
|
31 --- /dev/null |
|
32 +++ b/gfx/skia/src/ports/SkMemory_mozalloc.cpp |
|
33 @@ -0,0 +1,40 @@ |
|
34 +/* |
|
35 + * Copyright 2011 Google Inc. |
|
36 + * Copyright 2012 Mozilla Foundation |
|
37 + * |
|
38 + * Use of this source code is governed by a BSD-style license that can be |
|
39 + * found in the LICENSE file. |
|
40 + */ |
|
41 + |
|
42 +#include "SkTypes.h" |
|
43 + |
|
44 +#include "mozilla/mozalloc.h" |
|
45 +#include "mozilla/mozalloc_abort.h" |
|
46 +#include "mozilla/mozalloc_oom.h" |
|
47 + |
|
48 +void sk_throw() { |
|
49 + SkDEBUGFAIL("sk_throw"); |
|
50 + mozalloc_abort("Abort from sk_throw"); |
|
51 +} |
|
52 + |
|
53 +void sk_out_of_memory(void) { |
|
54 + SkDEBUGFAIL("sk_out_of_memory"); |
|
55 + mozalloc_handle_oom(0); |
|
56 +} |
|
57 + |
|
58 +void* sk_malloc_throw(size_t size) { |
|
59 + return sk_malloc_flags(size, SK_MALLOC_THROW); |
|
60 +} |
|
61 + |
|
62 +void* sk_realloc_throw(void* addr, size_t size) { |
|
63 + return moz_xrealloc(addr, size); |
|
64 +} |
|
65 + |
|
66 +void sk_free(void* p) { |
|
67 + moz_free(p); |
|
68 +} |
|
69 + |
|
70 +void* sk_malloc_flags(size_t size, unsigned flags) { |
|
71 + return (flags & SK_MALLOC_THROW) ? moz_xmalloc(size) : moz_malloc(size); |
|
72 +} |
|
73 + |