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

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

Issue 1143243007: Extract some logic from transport_dib into shared_memory. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 6 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
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 #include <sys/stat.h> 7 #include <sys/stat.h>
8 #include <unistd.h> 8 #include <unistd.h>
9 9
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
44 return dib.release(); 44 return dib.release();
45 } 45 }
46 46
47 // static 47 // static
48 TransportDIB* TransportDIB::CreateWithHandle(Handle handle) { 48 TransportDIB* TransportDIB::CreateWithHandle(Handle handle) {
49 return new TransportDIB(handle); 49 return new TransportDIB(handle);
50 } 50 }
51 51
52 // static 52 // static
53 bool TransportDIB::is_valid_handle(Handle dib) { 53 bool TransportDIB::is_valid_handle(Handle dib) {
54 return dib.fd >= 0; 54 return base::SharedMemory::IsHandleValid(dib);
55 } 55 }
56 56
57 // static 57 // static
58 bool TransportDIB::is_valid_id(Id id) { 58 bool TransportDIB::is_valid_id(Id id) {
59 #if defined(OS_ANDROID) 59 #if defined(OS_ANDROID)
60 return is_valid_handle(id); 60 return is_valid_handle(id);
61 #else 61 #else
62 return id != 0; 62 return id != 0;
63 #endif 63 #endif
64 } 64 }
65 65
66 skia::PlatformCanvas* TransportDIB::GetPlatformCanvas(int w, int h) { 66 skia::PlatformCanvas* TransportDIB::GetPlatformCanvas(int w, int h) {
67 if ((!memory() && !Map()) || !VerifyCanvasSize(w, h)) 67 if ((!memory() && !Map()) || !VerifyCanvasSize(w, h))
68 return NULL; 68 return NULL;
69 return skia::CreatePlatformCanvas(w, h, true, 69 return skia::CreatePlatformCanvas(w, h, true,
70 reinterpret_cast<uint8_t*>(memory()), 70 reinterpret_cast<uint8_t*>(memory()),
71 skia::RETURN_NULL_ON_FAILURE); 71 skia::RETURN_NULL_ON_FAILURE);
72 } 72 }
73 73
74 bool TransportDIB::Map() { 74 bool TransportDIB::Map() {
75 if (!is_valid_handle(handle())) 75 if (!is_valid_handle(handle()))
76 return false; 76 return false;
77 #if defined(OS_ANDROID) 77 #if defined(OS_ANDROID)
78 if (!shared_memory_.Map(0)) 78 if (!shared_memory_.Map(0))
79 return false; 79 return false;
80 size_ = shared_memory_.mapped_size(); 80 size_ = shared_memory_.mapped_size();
81 #else 81 #else
82 if (memory()) 82 if (memory())
83 return true; 83 return true;
84 84
85 struct stat st; 85 int size = base::SharedMemory::GetSizeFromSharedMemoryHandle(
86 if ((fstat(shared_memory_.handle().fd, &st) != 0) || 86 shared_memory_.handle());
87 (!shared_memory_.Map(st.st_size))) { 87 if (size == -1 || (!shared_memory_.Map(size)))
Nico 2015/05/30 00:02:43 nit: no parens around (!...) on the rhs (yes, they
erikchen 2015/05/30 00:10:50 Done. The new version is indeed easier to read.
88 return false; 88 return false;
89 }
90 89
91 size_ = st.st_size; 90 size_ = size;
92 #endif 91 #endif
93 return true; 92 return true;
94 } 93 }
95 94
96 void* TransportDIB::memory() const { 95 void* TransportDIB::memory() const {
97 return shared_memory_.memory(); 96 return shared_memory_.memory();
98 } 97 }
99 98
100 TransportDIB::Id TransportDIB::id() const { 99 TransportDIB::Id TransportDIB::id() const {
101 #if defined(OS_ANDROID) 100 #if defined(OS_ANDROID)
102 return handle(); 101 return handle();
103 #else 102 #else
104 return shared_memory_.id(); 103 return shared_memory_.id();
105 #endif 104 #endif
106 } 105 }
107 106
108 TransportDIB::Handle TransportDIB::handle() const { 107 TransportDIB::Handle TransportDIB::handle() const {
109 return shared_memory_.handle(); 108 return shared_memory_.handle();
110 } 109 }
OLDNEW
« base/memory/shared_memory.h ('K') | « base/memory/shared_memory_posix.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698