Commit cb75116a authored by cevans@chromium.org's avatar cevans@chromium.org

Simplify the transport dib situation across our various platforms, as a

pre-cursor to moving Chrome OS + Aura away from legacy GTK+X11 dibs. Now, we
have just:
- Windows style dibs
- POSIX style dibs
- Legacy GTK+X11 style dibs.

There's some ifdef hoops that will be removed in a follow-up CL when
Chrome OS + Aura will be moved away from legacy GTK+X11 dibs and on to POSIX
dibs.

BUG=147622
Review URL: https://codereview.chromium.org/13582008

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@192629 0039d316-1c4b-4281-b951-d872f2087c98
parent 7c194f47
......@@ -1007,15 +1007,15 @@ TransportDIB* RenderProcessHostImpl::MapTransportDIB(
STANDARD_RIGHTS_REQUIRED | FILE_MAP_READ | FILE_MAP_WRITE,
FALSE, 0);
return TransportDIB::Map(section);
#elif defined(OS_MACOSX)
// On OSX, the browser allocates all DIBs and keeps a file descriptor around
// for each.
return widget_helper_->MapTransportDIB(dib_id);
#elif defined(TOOLKIT_GTK) || (defined(OS_LINUX) && defined(USE_AURA))
return TransportDIB::Map(dib_id.shmkey);
#elif defined(OS_ANDROID)
return TransportDIB::Map(dib_id);
#elif defined(OS_POSIX)
return TransportDIB::Map(dib_id.shmkey);
#endif // defined(OS_POSIX)
#else
// On POSIX, the browser allocates all DIBs and keeps a file descriptor around
// for each.
return widget_helper_->MapTransportDIB(dib_id);
#endif
}
TransportDIB* RenderProcessHostImpl::GetTransportDIB(
......@@ -1047,7 +1047,7 @@ TransportDIB* RenderProcessHostImpl::GetTransportDIB(
}
}
#if defined(USE_X11)
#if defined(TOOLKIT_GTK) || (defined(OS_LINUX) && defined(USE_AURA))
smallest_iterator->second->Detach();
#else
delete smallest_iterator->second;
......@@ -1061,7 +1061,7 @@ TransportDIB* RenderProcessHostImpl::GetTransportDIB(
}
void RenderProcessHostImpl::ClearTransportDIBCache() {
#if defined(USE_X11)
#if defined(TOOLKIT_GTK) || (defined(OS_LINUX) && defined(USE_AURA))
std::map<TransportDIB::Id, TransportDIB*>::const_iterator dib =
cached_dibs_.begin();
for (; dib != cached_dibs_.end(); ++dib)
......
......@@ -81,9 +81,8 @@
'surface_switches.cc',
'transport_dib.h',
'transport_dib.cc',
'transport_dib_android.cc',
'transport_dib_linux.cc',
'transport_dib_mac.cc',
'transport_dib_posix.cc',
'transport_dib_sysvipc.cc',
'transport_dib_win.cc',
],
'defines': [
......
......@@ -8,13 +8,13 @@
#include "base/basictypes.h"
#include "ui/surface/surface_export.h"
#if defined(OS_WIN) || defined(OS_MACOSX) || defined(OS_ANDROID)
#if !defined(TOOLKIT_GTK)
#include "base/memory/shared_memory.h"
#endif
#if defined(OS_WIN)
#include <windows.h>
#elif defined(USE_X11)
#elif defined(TOOLKIT_GTK) || (defined(OS_LINUX) && defined(USE_AURA))
#include "ui/base/x/x11_util.h"
#endif
......@@ -80,22 +80,7 @@ class SURFACE_EXPORT TransportDIB {
static int fake_handle = 10;
return reinterpret_cast<Handle>(fake_handle++);
}
#elif defined(OS_MACOSX)
typedef base::SharedMemoryHandle Handle;
// On Mac, the inode number of the backing file is used as an id.
typedef base::SharedMemoryId Id;
// Returns a default, invalid handle, that is meant to indicate a missing
// Transport DIB.
static Handle DefaultHandleValue() { return Handle(); }
// Returns a value that is ONLY USEFUL FOR TESTS WHERE IT WON'T BE
// ACTUALLY USED AS A REAL HANDLE.
static Handle GetFakeHandleForTest() {
static int fake_handle = 10;
return Handle(fake_handle++, false);
}
#elif defined(USE_X11)
#elif defined(TOOLKIT_GTK) || (defined(OS_LINUX) && defined(USE_AURA))
typedef int Handle; // These two ints are SysV IPC shared memory keys
struct Id {
// Ensure that default initialized Ids are invalid.
......@@ -123,9 +108,14 @@ class SURFACE_EXPORT TransportDIB {
static int fake_handle = 10;
return fake_handle++;
}
#elif defined(OS_ANDROID)
#else // OS_POSIX
typedef base::SharedMemoryHandle Handle;
// On POSIX, the inode number of the backing file is used as an id.
#if defined(OS_ANDROID)
typedef base::SharedMemoryHandle Id;
#else
typedef base::SharedMemoryId Id;
#endif
// Returns a default, invalid handle, that is meant to indicate a missing
// Transport DIB.
......@@ -196,7 +186,7 @@ class SURFACE_EXPORT TransportDIB {
// wire to give this transport DIB to another process.
Handle handle() const;
#if defined(USE_X11)
#if defined(TOOLKIT_GTK) || (defined(OS_LINUX) && defined(USE_AURA))
// Map the shared memory into the X server and return an id for the shared
// segment.
XID MapToX(Display* connection);
......@@ -217,17 +207,17 @@ class SURFACE_EXPORT TransportDIB {
// Verifies that the dib can hold a canvas of the requested dimensions.
bool VerifyCanvasSize(int w, int h);
#if defined(OS_WIN) || defined(OS_MACOSX) || defined(OS_ANDROID)
explicit TransportDIB(base::SharedMemoryHandle dib);
base::SharedMemory shared_memory_;
uint32 sequence_num_;
#elif defined(USE_X11)
#if defined(TOOLKIT_GTK) || (defined(OS_LINUX) && defined(USE_AURA))
Id key_; // SysV shared memory id
void* address_; // mapped address
XSharedMemoryId x_shm_; // X id for the shared segment
Display* display_; // connection to the X server
size_t inflight_counter_; // How many requests to the X server are in flight
bool detached_; // If true, delete the transport DIB when it is idle
#else
explicit TransportDIB(base::SharedMemoryHandle dib);
base::SharedMemory shared_memory_;
uint32 sequence_num_;
#endif
size_t size_; // length, in bytes
......
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ui/surface/transport_dib.h"
#include <sys/stat.h>
#include <unistd.h>
#include "base/logging.h"
#include "base/memory/scoped_ptr.h"
#include "base/memory/shared_memory.h"
#include "base/posix/eintr_wrapper.h"
#include "skia/ext/platform_canvas.h"
TransportDIB::TransportDIB()
: size_(0) {
}
TransportDIB::TransportDIB(TransportDIB::Handle dib)
: shared_memory_(dib, false /* read write */),
size_(0) {
}
TransportDIB::~TransportDIB() {
}
// static
TransportDIB* TransportDIB::Create(size_t size, uint32 sequence_num) {
TransportDIB* dib = new TransportDIB;
// We will use ashmem_get_size_region() to figure out the size in Map(size).
if (!dib->shared_memory_.CreateAndMapAnonymous(size)) {
delete dib;
return NULL;
}
dib->size_ = size;
return dib;
}
// static
TransportDIB* TransportDIB::Map(Handle handle) {
scoped_ptr<TransportDIB> dib(CreateWithHandle(handle));
if (!dib->Map())
return NULL;
return dib.release();
}
// static
TransportDIB* TransportDIB::CreateWithHandle(Handle handle) {
return new TransportDIB(handle);
}
// static
bool TransportDIB::is_valid_handle(Handle dib) {
return dib.fd >= 0;
}
// static
bool TransportDIB::is_valid_id(Id id) {
// Same as is_valid_handle().
return id.fd >= 0;
}
skia::PlatformCanvas* TransportDIB::GetPlatformCanvas(int w, int h) {
if ((!memory() && !Map()) || !VerifyCanvasSize(w, h))
return NULL;
return skia::CreatePlatformCanvas(w, h, true,
reinterpret_cast<uint8_t*>(memory()),
skia::RETURN_NULL_ON_FAILURE);
}
bool TransportDIB::Map() {
if (!is_valid_handle(handle()) || !shared_memory_.Map(0))
return false;
size_ = shared_memory_.mapped_size();
return true;
}
void* TransportDIB::memory() const {
return shared_memory_.memory();
}
TransportDIB::Id TransportDIB::id() const {
// Use FileDescriptor as id.
return shared_memory_.handle();
}
TransportDIB::Handle TransportDIB::handle() const {
return shared_memory_.handle();
}
......@@ -4,6 +4,10 @@
#include "ui/surface/transport_dib.h"
// Desktop GTK Linux builds use the old-style SYSV SHM based DIBs.
// Linux Aura and Chrome OS do too. This will change very soon.
#if !defined(TOOLKIT_GTK) && !(defined(OS_LINUX) && defined(USE_AURA))
#include <sys/stat.h>
#include <unistd.h>
......@@ -57,7 +61,11 @@ bool TransportDIB::is_valid_handle(Handle dib) {
// static
bool TransportDIB::is_valid_id(Id id) {
#if defined(OS_ANDROID)
return is_valid_handle(id);
#else
return id != 0;
#endif
}
skia::PlatformCanvas* TransportDIB::GetPlatformCanvas(int w, int h) {
......@@ -71,6 +79,11 @@ skia::PlatformCanvas* TransportDIB::GetPlatformCanvas(int w, int h) {
bool TransportDIB::Map() {
if (!is_valid_handle(handle()))
return false;
#if defined(OS_ANDROID)
if (!shared_memory_.Map(0))
return false;
size_ = shared_memory_.mapped_size();
#else
if (memory())
return true;
......@@ -81,6 +94,7 @@ bool TransportDIB::Map() {
}
size_ = st.st_size;
#endif
return true;
}
......@@ -89,9 +103,16 @@ void* TransportDIB::memory() const {
}
TransportDIB::Id TransportDIB::id() const {
#if defined(OS_ANDROID)
return handle();
#else
return shared_memory_.id();
#endif
}
TransportDIB::Handle TransportDIB::handle() const {
return shared_memory_.handle();
}
#endif // !defined(TOOLKIT_GTK) && !(defined(OS_LINUX) && defined(USE_AURA))
......@@ -4,6 +4,10 @@
#include "ui/surface/transport_dib.h"
// Desktop GTK Linux builds use the old-style SYSV SHM based DIBs.
// Linux Aura and Chrome OS do too. This will change very soon.
#if defined(TOOLKIT_GTK) || (defined(OS_LINUX) && defined(USE_AURA))
#include <errno.h>
#include <stdlib.h>
#include <sys/ipc.h>
......@@ -153,3 +157,6 @@ void TransportDIB::Detach() {
if (!inflight_counter_)
delete this;
}
#endif
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment