OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 "app/surface/transport_dib.h" | 5 #include "app/surface/transport_dib.h" |
6 | 6 |
7 #include <unistd.h> | 7 #include <unistd.h> |
8 #include <sys/stat.h> | 8 #include <sys/stat.h> |
9 | 9 |
10 #include "base/eintr_wrapper.h" | 10 #include "base/eintr_wrapper.h" |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
44 return NULL; | 44 return NULL; |
45 return dib.release(); | 45 return dib.release(); |
46 } | 46 } |
47 | 47 |
48 // static | 48 // static |
49 TransportDIB* TransportDIB::CreateWithHandle(Handle handle) { | 49 TransportDIB* TransportDIB::CreateWithHandle(Handle handle) { |
50 return new TransportDIB(handle); | 50 return new TransportDIB(handle); |
51 } | 51 } |
52 | 52 |
53 // static | 53 // static |
54 bool TransportDIB::is_valid(Handle dib) { | 54 bool TransportDIB::is_valid_handle(Handle dib) { |
55 return dib.fd >= 0; | 55 return dib.fd >= 0; |
56 } | 56 } |
57 | 57 |
| 58 // static |
| 59 bool TransportDIB::is_valid_id(Id id) { |
| 60 return id != 0; |
| 61 } |
| 62 |
58 skia::PlatformCanvas* TransportDIB::GetPlatformCanvas(int w, int h) { | 63 skia::PlatformCanvas* TransportDIB::GetPlatformCanvas(int w, int h) { |
59 if (!memory() && !Map()) | 64 if (!memory() && !Map()) |
60 return NULL; | 65 return NULL; |
61 scoped_ptr<skia::PlatformCanvas> canvas(new skia::PlatformCanvas); | 66 scoped_ptr<skia::PlatformCanvas> canvas(new skia::PlatformCanvas); |
62 if (!canvas->initialize(w, h, true, reinterpret_cast<uint8_t*>(memory()))) | 67 if (!canvas->initialize(w, h, true, reinterpret_cast<uint8_t*>(memory()))) |
63 return NULL; | 68 return NULL; |
64 return canvas.release(); | 69 return canvas.release(); |
65 } | 70 } |
66 | 71 |
67 bool TransportDIB::Map() { | 72 bool TransportDIB::Map() { |
68 if (!is_valid(handle())) | 73 if (!is_valid_handle(handle())) |
69 return false; | 74 return false; |
70 if (memory()) | 75 if (memory()) |
71 return true; | 76 return true; |
72 | 77 |
73 struct stat st; | 78 struct stat st; |
74 if ((fstat(shared_memory_.handle().fd, &st) != 0) || | 79 if ((fstat(shared_memory_.handle().fd, &st) != 0) || |
75 (!shared_memory_.Map(st.st_size))) { | 80 (!shared_memory_.Map(st.st_size))) { |
76 return false; | 81 return false; |
77 } | 82 } |
78 | 83 |
79 size_ = st.st_size; | 84 size_ = st.st_size; |
80 return true; | 85 return true; |
81 } | 86 } |
82 | 87 |
83 void* TransportDIB::memory() const { | 88 void* TransportDIB::memory() const { |
84 return shared_memory_.memory(); | 89 return shared_memory_.memory(); |
85 } | 90 } |
86 | 91 |
87 TransportDIB::Id TransportDIB::id() const { | 92 TransportDIB::Id TransportDIB::id() const { |
88 return shared_memory_.id(); | 93 return shared_memory_.id(); |
89 } | 94 } |
90 | 95 |
91 TransportDIB::Handle TransportDIB::handle() const { | 96 TransportDIB::Handle TransportDIB::handle() const { |
92 return shared_memory_.handle(); | 97 return shared_memory_.handle(); |
93 } | 98 } |
OLD | NEW |