OLD | NEW |
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 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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(shared_memory_.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 int size = base::SharedMemory::GetSizeFromSharedMemoryHandle( | 85 int size = base::SharedMemory::GetSizeFromSharedMemoryHandle( |
86 shared_memory_.handle()); | 86 shared_memory_.handle()); |
87 if (size == -1 || !shared_memory_.Map(size)) | 87 if (size == -1 || !shared_memory_.Map(size)) |
88 return false; | 88 return false; |
89 | 89 |
90 size_ = size; | 90 size_ = size; |
91 #endif | 91 #endif |
92 return true; | 92 return true; |
93 } | 93 } |
94 | 94 |
95 void* TransportDIB::memory() const { | 95 void* TransportDIB::memory() const { |
96 return shared_memory_.memory(); | 96 return shared_memory_.memory(); |
97 } | 97 } |
98 | 98 |
99 TransportDIB::Id TransportDIB::id() const { | 99 TransportDIB::Id TransportDIB::id() const { |
100 #if defined(OS_ANDROID) | 100 #if defined(OS_ANDROID) |
101 return handle(); | 101 return shared_memory_.handle(); |
102 #else | 102 #else |
103 return shared_memory_.id(); | 103 return shared_memory_.id(); |
104 #endif | 104 #endif |
105 } | 105 } |
106 | |
107 TransportDIB::Handle TransportDIB::handle() const { | |
108 return shared_memory_.handle(); | |
109 } | |
OLD | NEW |