From afd70c31dafb5d4fdcf9697a6edcca84de048823 Mon Sep 17 00:00:00 2001 From: Petr Sumbera Date: Fri, 13 Dec 2019 20:18:45 +0000 Subject: [PATCH] Bug 1568533 - make CaptureCommandList.h Append() template use aligned pointers r=rhunt Differential Revision: https://phabricator.services.mozilla.com/D48952 --- gfx/2d/CaptureCommandList.h | 35 +++++++++++++++++++++++------------ 1 file changed, 23 insertions(+), 12 deletions(-) diff --git a/gfx/2d/CaptureCommandList.h b/gfx/2d/CaptureCommandList.h index ee00702b9b2c..642336381ae8 100644 --- a/gfx/2d/CaptureCommandList.h +++ b/gfx/2d/CaptureCommandList.h @@ -15,6 +15,16 @@ #include "DrawCommand.h" #include "Logging.h" +// Command object is stored into record with header containing size and +// redundant size of whole record. Some platforms may require Command +// object to be stored on 8 bytes aligned address. Therefore we need to +// adjust size of header for these platforms. +#ifdef __sparc__ +typedef uint32_t kAdvance_t; +#else +typedef uint16_t kAdvance_t; +#endif + namespace mozilla { namespace gfx { @@ -37,19 +47,19 @@ class CaptureCommandList { template T* Append() { - static_assert(sizeof(T) + sizeof(uint16_t) + sizeof(uint16_t) <= - std::numeric_limits::max(), + static_assert(sizeof(T) + 2 * sizeof(kAdvance_t) <= + std::numeric_limits::max(), "encoding is too small to contain advance"); - const uint16_t kAdvance = sizeof(T) + sizeof(uint16_t) + sizeof(uint16_t); + const kAdvance_t kAdvance = sizeof(T) + 2 * sizeof(kAdvance_t); size_t size = mStorage.size(); mStorage.resize(size + kAdvance); uint8_t* current = &mStorage.front() + size; - *(uint16_t*)(current) = kAdvance; - current += sizeof(uint16_t); - *(uint16_t*)(current) = ~kAdvance; - current += sizeof(uint16_t); + *(kAdvance_t*)(current) = kAdvance; + current += sizeof(kAdvance_t); + *(kAdvance_t*)(current) = ~kAdvance; + current += sizeof(kAdvance_t); T* command = reinterpret_cast(current); mLastCommand = command; @@ -70,7 +80,7 @@ class CaptureCommandList { template bool BufferWillAlloc() const { - const uint16_t kAdvance = sizeof(T) + sizeof(uint16_t) + sizeof(uint16_t); + const kAdvance_t kAdvance = sizeof(T) + 2 * sizeof(kAdvance_t); return mStorage.size() + kAdvance > mStorage.capacity(); } @@ -91,15 +101,16 @@ class CaptureCommandList { bool Done() const { return mCurrent >= mEnd; } void Next() { MOZ_ASSERT(!Done()); - uint16_t advance = *reinterpret_cast(mCurrent); - uint16_t redundant = - ~*reinterpret_cast(mCurrent + sizeof(uint16_t)); + kAdvance_t advance = *reinterpret_cast(mCurrent); + kAdvance_t redundant = + ~*reinterpret_cast(mCurrent + sizeof(kAdvance_t)); MOZ_RELEASE_ASSERT(advance == redundant); mCurrent += advance; } DrawingCommand* Get() { MOZ_ASSERT(!Done()); - return reinterpret_cast(mCurrent + sizeof(uint32_t)); + return reinterpret_cast(mCurrent + + 2 * sizeof(kAdvance_t)); } private: