Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(535)

Side by Side Diff: ui/surface/transport_dib_posix.cc

Issue 13582008: Simplify the transport dib situation across our various platforms, as a (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 7 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « ui/surface/transport_dib_mac.cc ('k') | ui/surface/transport_dib_sysvipc.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ui/surface/transport_dib.h" 5 #include "ui/surface/transport_dib.h"
6 6
7 // Desktop GTK Linux builds use the old-style SYSV SHM based DIBs.
8 // Linux Aura and Chrome OS do too. This will change very soon.
9 #if !defined(TOOLKIT_GTK) && !(defined(OS_LINUX) && defined(USE_AURA))
10
7 #include <sys/stat.h> 11 #include <sys/stat.h>
8 #include <unistd.h> 12 #include <unistd.h>
9 13
10 #include "base/logging.h" 14 #include "base/logging.h"
11 #include "base/memory/scoped_ptr.h" 15 #include "base/memory/scoped_ptr.h"
12 #include "base/memory/shared_memory.h" 16 #include "base/memory/shared_memory.h"
13 #include "base/posix/eintr_wrapper.h" 17 #include "base/posix/eintr_wrapper.h"
14 #include "skia/ext/platform_canvas.h" 18 #include "skia/ext/platform_canvas.h"
15 19
16 TransportDIB::TransportDIB() 20 TransportDIB::TransportDIB()
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
50 return new TransportDIB(handle); 54 return new TransportDIB(handle);
51 } 55 }
52 56
53 // static 57 // static
54 bool TransportDIB::is_valid_handle(Handle dib) { 58 bool TransportDIB::is_valid_handle(Handle dib) {
55 return dib.fd >= 0; 59 return dib.fd >= 0;
56 } 60 }
57 61
58 // static 62 // static
59 bool TransportDIB::is_valid_id(Id id) { 63 bool TransportDIB::is_valid_id(Id id) {
64 #if defined(OS_ANDROID)
65 return is_valid_handle(id);
66 #else
60 return id != 0; 67 return id != 0;
68 #endif
61 } 69 }
62 70
63 skia::PlatformCanvas* TransportDIB::GetPlatformCanvas(int w, int h) { 71 skia::PlatformCanvas* TransportDIB::GetPlatformCanvas(int w, int h) {
64 if ((!memory() && !Map()) || !VerifyCanvasSize(w, h)) 72 if ((!memory() && !Map()) || !VerifyCanvasSize(w, h))
65 return NULL; 73 return NULL;
66 return skia::CreatePlatformCanvas(w, h, true, 74 return skia::CreatePlatformCanvas(w, h, true,
67 reinterpret_cast<uint8_t*>(memory()), 75 reinterpret_cast<uint8_t*>(memory()),
68 skia::RETURN_NULL_ON_FAILURE); 76 skia::RETURN_NULL_ON_FAILURE);
69 } 77 }
70 78
71 bool TransportDIB::Map() { 79 bool TransportDIB::Map() {
72 if (!is_valid_handle(handle())) 80 if (!is_valid_handle(handle()))
73 return false; 81 return false;
82 #if defined(OS_ANDROID)
83 if (!shared_memory_.Map(0))
84 return false;
85 size_ = shared_memory_.mapped_size();
86 #else
74 if (memory()) 87 if (memory())
75 return true; 88 return true;
76 89
77 struct stat st; 90 struct stat st;
78 if ((fstat(shared_memory_.handle().fd, &st) != 0) || 91 if ((fstat(shared_memory_.handle().fd, &st) != 0) ||
79 (!shared_memory_.Map(st.st_size))) { 92 (!shared_memory_.Map(st.st_size))) {
80 return false; 93 return false;
81 } 94 }
82 95
83 size_ = st.st_size; 96 size_ = st.st_size;
97 #endif
84 return true; 98 return true;
85 } 99 }
86 100
87 void* TransportDIB::memory() const { 101 void* TransportDIB::memory() const {
88 return shared_memory_.memory(); 102 return shared_memory_.memory();
89 } 103 }
90 104
91 TransportDIB::Id TransportDIB::id() const { 105 TransportDIB::Id TransportDIB::id() const {
106 #if defined(OS_ANDROID)
107 return handle();
108 #else
92 return shared_memory_.id(); 109 return shared_memory_.id();
110 #endif
93 } 111 }
94 112
95 TransportDIB::Handle TransportDIB::handle() const { 113 TransportDIB::Handle TransportDIB::handle() const {
96 return shared_memory_.handle(); 114 return shared_memory_.handle();
97 } 115 }
116
117 #endif // !defined(TOOLKIT_GTK) && !(defined(OS_LINUX) && defined(USE_AURA))
118
OLDNEW
« no previous file with comments | « ui/surface/transport_dib_mac.cc ('k') | ui/surface/transport_dib_sysvipc.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698