diff options
author | cevans@chromium.org <cevans@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-04-05 20:50:42 +0000 |
---|---|---|
committer | cevans@chromium.org <cevans@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-04-05 20:50:42 +0000 |
commit | cb75116ab624dd0df65508653119afdc081e7800 (patch) | |
tree | a7c7cedeb5fd7c5e3e137e029cd18f070fee382d /ui/surface | |
parent | 7c194f4763833ae85b83fed6786a26789768f542 (diff) | |
download | chromium_src-cb75116ab624dd0df65508653119afdc081e7800.zip chromium_src-cb75116ab624dd0df65508653119afdc081e7800.tar.gz chromium_src-cb75116ab624dd0df65508653119afdc081e7800.tar.bz2 |
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
Diffstat (limited to 'ui/surface')
-rw-r--r-- | ui/surface/surface.gyp | 5 | ||||
-rw-r--r-- | ui/surface/transport_dib.h | 40 | ||||
-rw-r--r-- | ui/surface/transport_dib_android.cc | 92 | ||||
-rw-r--r-- | ui/surface/transport_dib_posix.cc (renamed from ui/surface/transport_dib_mac.cc) | 21 | ||||
-rw-r--r-- | ui/surface/transport_dib_sysvipc.cc (renamed from ui/surface/transport_dib_linux.cc) | 7 |
5 files changed, 45 insertions, 120 deletions
diff --git a/ui/surface/surface.gyp b/ui/surface/surface.gyp index cc4aa6b..d64972d 100644 --- a/ui/surface/surface.gyp +++ b/ui/surface/surface.gyp @@ -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': [ diff --git a/ui/surface/transport_dib.h b/ui/surface/transport_dib.h index a9d17d4..9057bb6 100644 --- a/ui/surface/transport_dib.h +++ b/ui/surface/transport_dib.h @@ -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 diff --git a/ui/surface/transport_dib_android.cc b/ui/surface/transport_dib_android.cc deleted file mode 100644 index 310f3f3..0000000 --- a/ui/surface/transport_dib_android.cc +++ /dev/null @@ -1,92 +0,0 @@ -// 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(); -} diff --git a/ui/surface/transport_dib_mac.cc b/ui/surface/transport_dib_posix.cc index 5e30f2b..fcb935d 100644 --- a/ui/surface/transport_dib_mac.cc +++ b/ui/surface/transport_dib_posix.cc @@ -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)) + diff --git a/ui/surface/transport_dib_linux.cc b/ui/surface/transport_dib_sysvipc.cc index 1e8d8fa..a15ca41 100644 --- a/ui/surface/transport_dib_linux.cc +++ b/ui/surface/transport_dib_sysvipc.cc @@ -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 + |