diff options
author | jamesr@chromium.org <jamesr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-03-25 00:14:00 +0000 |
---|---|---|
committer | jamesr@chromium.org <jamesr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-03-25 00:14:00 +0000 |
commit | 27543452369d6a2cdcc058cb5f92910d7a47e823 (patch) | |
tree | 4a1c2f46659e653f2186947a27e7ff4571c80832 /app | |
parent | 0f46f8115f6b5baf16e602e006d5c1ffa7f08482 (diff) | |
download | chromium_src-27543452369d6a2cdcc058cb5f92910d7a47e823.zip chromium_src-27543452369d6a2cdcc058cb5f92910d7a47e823.tar.gz chromium_src-27543452369d6a2cdcc058cb5f92910d7a47e823.tar.bz2 |
Adds a TransportDIB::Id value that is explicitly invalid and use it when compositing
BUG=76001
TEST=
Review URL: http://codereview.chromium.org/6665029
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@79349 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'app')
-rw-r--r-- | app/surface/accelerated_surface_mac.cc | 2 | ||||
-rw-r--r-- | app/surface/transport_dib.h | 21 | ||||
-rw-r--r-- | app/surface/transport_dib_linux.cc | 24 | ||||
-rw-r--r-- | app/surface/transport_dib_mac.cc | 9 | ||||
-rw-r--r-- | app/surface/transport_dib_win.cc | 9 |
5 files changed, 46 insertions, 19 deletions
diff --git a/app/surface/accelerated_surface_mac.cc b/app/surface/accelerated_surface_mac.cc index ab5529e..6322603 100644 --- a/app/surface/accelerated_surface_mac.cc +++ b/app/surface/accelerated_surface_mac.cc @@ -307,7 +307,7 @@ TransportDIB::Handle AcceleratedSurface::SetTransportDIBSize( if (dib_alloc_callback_.get()) { dib_alloc_callback_->Run(dib_size, &dib_handle); } - if (!TransportDIB::is_valid(dib_handle)) { + if (!TransportDIB::is_valid_handle(dib_handle)) { // If the allocator fails, it means the DIB was not created in the browser, // so there is no need to run the deallocator here. return TransportDIB::DefaultHandleValue(); diff --git a/app/surface/transport_dib.h b/app/surface/transport_dib.h index a55f624..d13168a 100644 --- a/app/surface/transport_dib.h +++ b/app/surface/transport_dib.h @@ -56,7 +56,7 @@ class TransportDIB { sequence_num(seq_num) { } - bool operator< (const HandleAndSequenceNum& other) const { + bool operator<(const HandleAndSequenceNum& other) const { // Use the lexicographic order on the tuple <handle, sequence_num>. if (other.handle != handle) return other.handle < handle; @@ -95,7 +95,17 @@ class TransportDIB { } #elif defined(USE_X11) typedef int Handle; // These two ints are SysV IPC shared memory keys - typedef int Id; + struct Id { + // Ensure that default initialized Ids are invalid. + Id() : shmkey(-1) { + } + + bool operator<(const Id& other) const { + return shmkey < other.shmkey; + } + + int shmkey; + }; // Returns a default, invalid handle, that is meant to indicate a missing // Transport DIB. @@ -129,7 +139,10 @@ class TransportDIB { static TransportDIB* CreateWithHandle(Handle handle); // Returns true if the handle is valid. - static bool is_valid(Handle dib); + static bool is_valid_handle(Handle dib); + + // Returns true if the ID refers to a valid dib. + static bool is_valid_id(Id id); // Returns a canvas using the memory of this TransportDIB. The returned // pointer will be owned by the caller. The bitmap will be of the given size, @@ -176,7 +189,7 @@ class TransportDIB { base::SharedMemory shared_memory_; uint32 sequence_num_; #elif defined(USE_X11) - int key_; // SysV shared memory id + 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 diff --git a/app/surface/transport_dib_linux.cc b/app/surface/transport_dib_linux.cc index 69fabff..614cdb0 100644 --- a/app/surface/transport_dib_linux.cc +++ b/app/surface/transport_dib_linux.cc @@ -18,8 +18,7 @@ static void *const kInvalidAddress = (void*) -1; TransportDIB::TransportDIB() - : key_(-1), - address_(kInvalidAddress), + : address_(kInvalidAddress), x_shm_(0), display_(NULL), size_(0) { @@ -59,7 +58,7 @@ TransportDIB* TransportDIB::Create(size_t size, uint32 sequence_num) { TransportDIB* dib = new TransportDIB; - dib->key_ = shmkey; + dib->key_.shmkey = shmkey; dib->address_ = address; dib->size_ = size; return dib; @@ -76,15 +75,20 @@ TransportDIB* TransportDIB::Map(Handle handle) { // static TransportDIB* TransportDIB::CreateWithHandle(Handle shmkey) { TransportDIB* dib = new TransportDIB; - dib->key_ = shmkey; + dib->key_.shmkey = shmkey; return dib; } // static -bool TransportDIB::is_valid(Handle dib) { +bool TransportDIB::is_valid_handle(Handle dib) { return dib >= 0; } +// static +bool TransportDIB::is_valid_id(Id id) { + return id.shmkey != -1; +} + skia::PlatformCanvas* TransportDIB::GetPlatformCanvas(int w, int h) { if (address_ == kInvalidAddress && !Map()) return NULL; @@ -95,16 +99,16 @@ skia::PlatformCanvas* TransportDIB::GetPlatformCanvas(int w, int h) { } bool TransportDIB::Map() { - if (!is_valid(key_)) + if (!is_valid_id(key_)) return false; if (address_ != kInvalidAddress) return true; struct shmid_ds shmst; - if (shmctl(key_, IPC_STAT, &shmst) == -1) + if (shmctl(key_.shmkey, IPC_STAT, &shmst) == -1) return false; - void* address = shmat(key_, NULL /* desired address */, 0 /* flags */); + void* address = shmat(key_.shmkey, NULL /* desired address */, 0 /* flags */); if (address == kInvalidAddress) return false; @@ -123,12 +127,12 @@ TransportDIB::Id TransportDIB::id() const { } TransportDIB::Handle TransportDIB::handle() const { - return key_; + return key_.shmkey; } XID TransportDIB::MapToX(Display* display) { if (!x_shm_) { - x_shm_ = ui::AttachSharedMemory(display, key_); + x_shm_ = ui::AttachSharedMemory(display, key_.shmkey); display_ = display; } diff --git a/app/surface/transport_dib_mac.cc b/app/surface/transport_dib_mac.cc index 8ea81ae..c0dd457 100644 --- a/app/surface/transport_dib_mac.cc +++ b/app/surface/transport_dib_mac.cc @@ -51,10 +51,15 @@ TransportDIB* TransportDIB::CreateWithHandle(Handle handle) { } // static -bool TransportDIB::is_valid(Handle dib) { +bool TransportDIB::is_valid_handle(Handle dib) { return dib.fd >= 0; } +// static +bool TransportDIB::is_valid_id(Id id) { + return id != 0; +} + skia::PlatformCanvas* TransportDIB::GetPlatformCanvas(int w, int h) { if (!memory() && !Map()) return NULL; @@ -65,7 +70,7 @@ skia::PlatformCanvas* TransportDIB::GetPlatformCanvas(int w, int h) { } bool TransportDIB::Map() { - if (!is_valid(handle())) + if (!is_valid_handle(handle())) return false; if (memory()) return true; diff --git a/app/surface/transport_dib_win.cc b/app/surface/transport_dib_win.cc index 22812c9..3de7fab 100644 --- a/app/surface/transport_dib_win.cc +++ b/app/surface/transport_dib_win.cc @@ -56,10 +56,15 @@ TransportDIB* TransportDIB::CreateWithHandle(Handle handle) { } // static -bool TransportDIB::is_valid(Handle dib) { +bool TransportDIB::is_valid_handle(Handle dib) { return dib != NULL; } +// static +bool TransportDIB::is_valid_id(TransportDIB::Id id) { + return is_valid_handle(id.handle); +} + skia::PlatformCanvas* TransportDIB::GetPlatformCanvas(int w, int h) { // This DIB already mapped the file into this process, but PlatformCanvas // will map it again. @@ -72,7 +77,7 @@ skia::PlatformCanvas* TransportDIB::GetPlatformCanvas(int w, int h) { } bool TransportDIB::Map() { - if (!is_valid(handle())) + if (!is_valid_handle(handle())) return false; if (memory()) return true; |