summaryrefslogtreecommitdiffstats
path: root/ui/surface
diff options
context:
space:
mode:
Diffstat (limited to 'ui/surface')
-rw-r--r--ui/surface/transport_dib.h11
-rw-r--r--ui/surface/transport_dib_linux.cc16
2 files changed, 27 insertions, 0 deletions
diff --git a/ui/surface/transport_dib.h b/ui/surface/transport_dib.h
index 3495c9d..70928ed 100644
--- a/ui/surface/transport_dib.h
+++ b/ui/surface/transport_dib.h
@@ -194,6 +194,15 @@ class SURFACE_EXPORT TransportDIB {
// Map the shared memory into the X server and return an id for the shared
// segment.
XID MapToX(Display* connection);
+
+ void IncreaseInFlightCounter() { inflight_counter_++; }
+ // Decreases the inflight counter, and deletes the transport DIB if it is
+ // detached.
+ void DecreaseInFlightCounter();
+
+ // Deletes this transport DIB and detaches the shared memory once the
+ // |inflight_counter_| is zero.
+ void Detach();
#endif
private:
@@ -207,6 +216,8 @@ class SURFACE_EXPORT TransportDIB {
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
#endif
size_t size_; // length, in bytes
diff --git a/ui/surface/transport_dib_linux.cc b/ui/surface/transport_dib_linux.cc
index b1a5469..7763c0e 100644
--- a/ui/surface/transport_dib_linux.cc
+++ b/ui/surface/transport_dib_linux.cc
@@ -22,6 +22,8 @@ TransportDIB::TransportDIB()
: address_(kInvalidAddress),
x_shm_(0),
display_(NULL),
+ inflight_counter_(0),
+ detached_(false),
size_(0) {
}
@@ -138,3 +140,17 @@ XID TransportDIB::MapToX(Display* display) {
return x_shm_;
}
+
+void TransportDIB::DecreaseInFlightCounter() {
+ CHECK(inflight_counter_);
+ inflight_counter_--;
+ if (!inflight_counter_ && detached_)
+ delete this;
+}
+
+void TransportDIB::Detach() {
+ CHECK(!detached_);
+ detached_ = true;
+ if (!inflight_counter_)
+ delete this;
+}