summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJohn Reck <jreck@google.com>2012-08-14 16:53:39 -0700
committerJohn Reck <jreck@google.com>2012-08-14 16:53:39 -0700
commit682a85cb3ff0b200d4fe0f7ef41a4e1c57dea233 (patch)
treed84cc68736e77e24f11348668dc9c6d6261e5441
parentb0a56fa335e9435238de5f2cde15076488057c52 (diff)
downloadexternal_webkit-682a85cb3ff0b200d4fe0f7ef41a4e1c57dea233.zip
external_webkit-682a85cb3ff0b200d4fe0f7ef41a4e1c57dea233.tar.gz
external_webkit-682a85cb3ff0b200d4fe0f7ef41a4e1c57dea233.tar.bz2
Move text allocations to LinearAllocator
Change-Id: I3ef492679e94bdb452033ee3af3162b88d323d57
-rw-r--r--Source/WebCore/platform/graphics/android/context/GraphicsOperation.h17
-rw-r--r--Source/WebCore/platform/graphics/android/context/PlatformGraphicsContextRecording.cpp11
-rw-r--r--Source/WebCore/platform/graphics/android/utils/LinearAllocator.cpp23
3 files changed, 34 insertions, 17 deletions
diff --git a/Source/WebCore/platform/graphics/android/context/GraphicsOperation.h b/Source/WebCore/platform/graphics/android/context/GraphicsOperation.h
index c70c295..edcdc35 100644
--- a/Source/WebCore/platform/graphics/android/context/GraphicsOperation.h
+++ b/Source/WebCore/platform/graphics/android/context/GraphicsOperation.h
@@ -587,25 +587,20 @@ class DrawPosText : public Operation {
public:
DrawPosText(const void* text, size_t byteLength,
const SkPoint pos[], const SkPaint* paint)
- : m_byteLength(byteLength)
+ : m_text(text)
+ , m_byteLength(byteLength)
+ , m_pos(pos)
, m_paint(paint)
- {
- size_t points = m_paint->countText(text, byteLength);
- m_pos = new SkPoint[points];
- memcpy(m_pos, pos, sizeof(SkPoint) * points);
- m_text = malloc(byteLength);
- memcpy(m_text, text, byteLength);
- }
- ~DrawPosText() { delete m_pos; free(m_text); }
+ {}
virtual bool applyImpl(PlatformGraphicsContext* context) {
context->drawPosText(m_text, m_byteLength, m_pos, *m_paint);
return true;
}
TYPE(DrawPosTextOperation)
private:
- void* m_text;
+ const void* m_text;
size_t m_byteLength;
- SkPoint* m_pos;
+ const SkPoint* m_pos;
const SkPaint* m_paint;
};
diff --git a/Source/WebCore/platform/graphics/android/context/PlatformGraphicsContextRecording.cpp b/Source/WebCore/platform/graphics/android/context/PlatformGraphicsContextRecording.cpp
index 24ee47e..464224a 100644
--- a/Source/WebCore/platform/graphics/android/context/PlatformGraphicsContextRecording.cpp
+++ b/Source/WebCore/platform/graphics/android/context/PlatformGraphicsContextRecording.cpp
@@ -891,15 +891,20 @@ void PlatformGraphicsContextRecording::strokeRect(const FloatRect& rect, float l
appendDrawingOperation(NEW_OP(StrokeRect)(rect, lineWidth), bounds);
}
-void PlatformGraphicsContextRecording::drawPosText(const void* text, size_t byteLength,
- const SkPoint pos[], const SkPaint& inPaint)
+void PlatformGraphicsContextRecording::drawPosText(const void* inText, size_t byteLength,
+ const SkPoint inPos[], const SkPaint& inPaint)
{
if (inPaint.getTextEncoding() != SkPaint::kGlyphID_TextEncoding) {
ALOGE("Unsupported text encoding! %d", inPaint.getTextEncoding());
return;
}
- FloatRect bounds = approximateTextBounds(byteLength / sizeof(uint16_t), pos, inPaint);
+ FloatRect bounds = approximateTextBounds(byteLength / sizeof(uint16_t), inPos, inPaint);
const SkPaint* paint = mRecording->recording()->getSkPaint(inPaint);
+ int posSize = sizeof(SkPoint) * paint->countText(inText, byteLength);
+ void* text = operationHeap()->alloc(posSize + byteLength);
+ SkPoint* pos = (SkPoint*) ((char*)text + byteLength);
+ memcpy(text, inText, byteLength);
+ memcpy(pos, inPos, posSize);
appendDrawingOperation(NEW_OP(DrawPosText)(text, byteLength, pos, paint), bounds);
}
diff --git a/Source/WebCore/platform/graphics/android/utils/LinearAllocator.cpp b/Source/WebCore/platform/graphics/android/utils/LinearAllocator.cpp
index 1899557..8aa1616 100644
--- a/Source/WebCore/platform/graphics/android/utils/LinearAllocator.cpp
+++ b/Source/WebCore/platform/graphics/android/utils/LinearAllocator.cpp
@@ -39,6 +39,14 @@ namespace WebCore {
// our pool needs to big enough to hold at least this many items
#define MIN_OBJECT_COUNT 4
+// The maximum amount of wasted space we can have per page
+// Allocations exceeding this will have their own dedicated page
+// If this is too low, we will malloc too much
+// Too high, and we may waste too much space
+#define MAX_WASTE_SIZE ((size_t)256)
+
+#define ALIGN(x) (x + (x % sizeof(int)))
+
#if LOG_NDEBUG
#define ADD_ALLOCATION(size)
#define RM_ALLOCATION(size)
@@ -103,7 +111,8 @@ LinearAllocator::LinearAllocator(size_t averageAllocSize)
m_pageSize = pcount * averageAllocSize + sizeof(LinearAllocator::Page);
} else
m_pageSize = TARGET_PAGE_SIZE;
- m_maxAllocSize = (m_pageSize - sizeof(LinearAllocator::Page));
+ m_pageSize = ALIGN(m_pageSize);
+ m_maxAllocSize = std::min(MAX_WASTE_SIZE, (m_pageSize - sizeof(LinearAllocator::Page)));
}
LinearAllocator::~LinearAllocator(void)
@@ -153,9 +162,17 @@ unsigned LinearAllocator::memusage()
void* LinearAllocator::alloc(size_t size)
{
+ size = ALIGN(size);
if (size > m_maxAllocSize) {
- ALOGE("Allocation too large! (%d exceeds max size %d)", size, m_maxAllocSize);
- return 0;
+ // Allocation is too large, create a dedicated page for the allocation
+ ADD_ALLOCATION(size);
+ void* buf = malloc(size + sizeof(LinearAllocator::Page));
+ Page* page = new (buf) Page();
+ page->setNext(m_pages);
+ m_pages = page;
+ if (!m_currentPage)
+ m_currentPage = m_pages;
+ return start(page);
}
ensureNext(size);
void* ptr = m_next;