summaryrefslogtreecommitdiff
path: root/Source/WebKit2/Shared/ShareableBitmap.cpp
diff options
context:
space:
mode:
authorLorry Tar Creator <lorry-tar-importer@lorry>2017-06-27 06:07:23 +0000
committerLorry Tar Creator <lorry-tar-importer@lorry>2017-06-27 06:07:23 +0000
commit1bf1084f2b10c3b47fd1a588d85d21ed0eb41d0c (patch)
tree46dcd36c86e7fbc6e5df36deb463b33e9967a6f7 /Source/WebKit2/Shared/ShareableBitmap.cpp
parent32761a6cee1d0dee366b885b7b9c777e67885688 (diff)
downloadWebKitGtk-tarball-master.tar.gz
Diffstat (limited to 'Source/WebKit2/Shared/ShareableBitmap.cpp')
-rw-r--r--Source/WebKit2/Shared/ShareableBitmap.cpp94
1 files changed, 51 insertions, 43 deletions
diff --git a/Source/WebKit2/Shared/ShareableBitmap.cpp b/Source/WebKit2/Shared/ShareableBitmap.cpp
index 1971100ee..9942e7c26 100644
--- a/Source/WebKit2/Shared/ShareableBitmap.cpp
+++ b/Source/WebKit2/Shared/ShareableBitmap.cpp
@@ -33,20 +33,27 @@
using namespace WebCore;
namespace WebKit {
+
+static unsigned calculateBytesPerPixel(ShareableBitmap::Flags flags)
+{
+ if (flags & ShareableBitmap::SupportsExtendedColor)
+ return 8; // for extended color, we are using half-float representations
+ return 4;
+}
ShareableBitmap::Handle::Handle()
: m_flags(0)
{
}
-void ShareableBitmap::Handle::encode(IPC::ArgumentEncoder& encoder) const
+void ShareableBitmap::Handle::encode(IPC::Encoder& encoder) const
{
encoder << m_handle;
encoder << m_size;
encoder << m_flags;
}
-bool ShareableBitmap::Handle::decode(IPC::ArgumentDecoder& decoder, Handle& handle)
+bool ShareableBitmap::Handle::decode(IPC::Decoder& decoder, Handle& handle)
{
if (!decoder.decode(handle.m_handle))
return false;
@@ -54,52 +61,73 @@ bool ShareableBitmap::Handle::decode(IPC::ArgumentDecoder& decoder, Handle& hand
return false;
if (!decoder.decode(handle.m_flags))
return false;
+ handle.m_bytesPerPixel = calculateBytesPerPixel(handle.m_flags);
return true;
}
-PassRefPtr<ShareableBitmap> ShareableBitmap::create(const IntSize& size, Flags flags)
+void ShareableBitmap::Handle::clear()
{
- size_t numBytes = numBytesForSize(size);
-
+ m_handle.clear();
+ m_size = IntSize();
+ m_flags = Flag::NoFlags;
+ m_bytesPerPixel = calculateBytesPerPixel(m_flags);
+}
+
+RefPtr<ShareableBitmap> ShareableBitmap::create(const IntSize& size, Flags flags)
+{
+ unsigned bytesPerPixel = calculateBytesPerPixel(flags);
+ auto numBytes = numBytesForSize(size, bytesPerPixel);
+ if (numBytes.hasOverflowed())
+ return nullptr;
+
void* data = 0;
- if (!tryFastMalloc(numBytes).getValue(data))
- return 0;
+ if (!tryFastMalloc(numBytes.unsafeGet()).getValue(data))
+ return nullptr;
return adoptRef(new ShareableBitmap(size, flags, data));
}
-PassRefPtr<ShareableBitmap> ShareableBitmap::createShareable(const IntSize& size, Flags flags)
+RefPtr<ShareableBitmap> ShareableBitmap::createShareable(const IntSize& size, Flags flags)
{
- size_t numBytes = numBytesForSize(size);
+ unsigned bytesPerPixel = calculateBytesPerPixel(flags);
+ auto numBytes = numBytesForSize(size, bytesPerPixel);
+ if (numBytes.hasOverflowed())
+ return nullptr;
- RefPtr<SharedMemory> sharedMemory = SharedMemory::create(numBytes);
+ RefPtr<SharedMemory> sharedMemory = SharedMemory::allocate(numBytes.unsafeGet());
if (!sharedMemory)
- return 0;
+ return nullptr;
return adoptRef(new ShareableBitmap(size, flags, sharedMemory));
}
-PassRefPtr<ShareableBitmap> ShareableBitmap::create(const IntSize& size, Flags flags, PassRefPtr<SharedMemory> sharedMemory)
+RefPtr<ShareableBitmap> ShareableBitmap::create(const IntSize& size, Flags flags, RefPtr<SharedMemory> sharedMemory)
{
ASSERT(sharedMemory);
- size_t numBytes = numBytesForSize(size);
- ASSERT_UNUSED(numBytes, sharedMemory->size() >= numBytes);
+ unsigned bytesPerPixel = calculateBytesPerPixel(flags);
+ auto numBytes = numBytesForSize(size, bytesPerPixel);
+ if (numBytes.hasOverflowed())
+ return nullptr;
+ if (sharedMemory->size() < numBytes.unsafeGet()) {
+ ASSERT_NOT_REACHED();
+ return nullptr;
+ }
return adoptRef(new ShareableBitmap(size, flags, sharedMemory));
}
-PassRefPtr<ShareableBitmap> ShareableBitmap::create(const Handle& handle, SharedMemory::Protection protection)
+RefPtr<ShareableBitmap> ShareableBitmap::create(const Handle& handle, SharedMemory::Protection protection)
{
// Create the shared memory.
- RefPtr<SharedMemory> sharedMemory = SharedMemory::create(handle.m_handle, protection);
+ auto sharedMemory = SharedMemory::map(handle.m_handle, protection);
if (!sharedMemory)
- return 0;
+ return nullptr;
- return create(handle.m_size, handle.m_flags, sharedMemory.release());
+ return create(handle.m_size, handle.m_flags, WTFMove(sharedMemory));
}
-bool ShareableBitmap::createHandle(Handle& handle, SharedMemory::Protection protection)
+bool ShareableBitmap::createHandle(Handle& handle, SharedMemory::Protection protection) const
{
ASSERT(isBackedBySharedMemory());
@@ -107,6 +135,7 @@ bool ShareableBitmap::createHandle(Handle& handle, SharedMemory::Protection prot
return false;
handle.m_size = m_size;
handle.m_flags = m_flags;
+ handle.m_bytesPerPixel = m_bytesPerPixel;
return true;
}
@@ -115,14 +144,16 @@ ShareableBitmap::ShareableBitmap(const IntSize& size, Flags flags, void* data)
, m_flags(flags)
, m_data(data)
{
+ m_bytesPerPixel = calculateBytesPerPixel(flags);
}
-ShareableBitmap::ShareableBitmap(const IntSize& size, Flags flags, PassRefPtr<SharedMemory> sharedMemory)
+ShareableBitmap::ShareableBitmap(const IntSize& size, Flags flags, RefPtr<SharedMemory> sharedMemory)
: m_size(size)
, m_flags(flags)
, m_sharedMemory(sharedMemory)
, m_data(0)
{
+ m_bytesPerPixel = calculateBytesPerPixel(flags);
}
ShareableBitmap::~ShareableBitmap()
@@ -131,29 +162,6 @@ ShareableBitmap::~ShareableBitmap()
fastFree(m_data);
}
-bool ShareableBitmap::resize(const IntSize& size)
-{
- // We can't resize backing stores that are backed by shared memory.
- ASSERT(!isBackedBySharedMemory());
-
- if (size == m_size)
- return true;
-
- size_t newNumBytes = numBytesForSize(size);
-
- // Try to resize.
- char* newData = 0;
- if (!tryFastRealloc(m_data, newNumBytes).getValue(newData)) {
- // We failed, but the backing store is still kept in a consistent state.
- return false;
- }
-
- m_size = size;
- m_data = newData;
-
- return true;
-}
-
void* ShareableBitmap::data() const
{
if (isBackedBySharedMemory())