| 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 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 56 return dib.fd >= 0; | 56 return dib.fd >= 0; |
| 57 } | 57 } |
| 58 | 58 |
| 59 // static | 59 // static |
| 60 bool TransportDIB::is_valid_id(Id id) { | 60 bool TransportDIB::is_valid_id(Id id) { |
| 61 // Same as is_valid_handle(). | 61 // Same as is_valid_handle(). |
| 62 return id.fd >= 0; | 62 return id.fd >= 0; |
| 63 } | 63 } |
| 64 | 64 |
| 65 skia::PlatformCanvas* TransportDIB::GetPlatformCanvas(int w, int h) { | 65 skia::PlatformCanvas* TransportDIB::GetPlatformCanvas(int w, int h) { |
| 66 if (!memory() && !Map()) | 66 if ((!memory() && !Map()) || !VerifyCanvasSize(w, h)) |
| 67 return NULL; | 67 return NULL; |
| 68 return skia::CreatePlatformCanvas(w, h, true, | 68 return skia::CreatePlatformCanvas(w, h, true, |
| 69 reinterpret_cast<uint8_t*>(memory()), | 69 reinterpret_cast<uint8_t*>(memory()), |
| 70 skia::RETURN_NULL_ON_FAILURE); | 70 skia::RETURN_NULL_ON_FAILURE); |
| 71 } | 71 } |
| 72 | 72 |
| 73 bool TransportDIB::Map() { | 73 bool TransportDIB::Map() { |
| 74 if (!is_valid_handle(handle())) | 74 if (!is_valid_handle(handle()) || !shared_memory_.Map(0)) |
| 75 return false; | |
| 76 // We will use ashmem_get_size_region() to figure out the size in Map(size). | |
| 77 if (!shared_memory_.Map(0)) | |
| 78 return false; | 75 return false; |
| 79 | 76 |
| 80 // TODO: Note that using created_size() below is a hack. See the comment in | 77 size_ = shared_memory_.mapped_size(); |
| 81 // SharedMemory::Map(). | |
| 82 size_ = shared_memory_.created_size(); | |
| 83 return true; | 78 return true; |
| 84 } | 79 } |
| 85 | 80 |
| 86 void* TransportDIB::memory() const { | 81 void* TransportDIB::memory() const { |
| 87 return shared_memory_.memory(); | 82 return shared_memory_.memory(); |
| 88 } | 83 } |
| 89 | 84 |
| 90 TransportDIB::Id TransportDIB::id() const { | 85 TransportDIB::Id TransportDIB::id() const { |
| 91 // Use FileDescriptor as id. | 86 // Use FileDescriptor as id. |
| 92 return shared_memory_.handle(); | 87 return shared_memory_.handle(); |
| 93 } | 88 } |
| 94 | 89 |
| 95 TransportDIB::Handle TransportDIB::handle() const { | 90 TransportDIB::Handle TransportDIB::handle() const { |
| 96 return shared_memory_.handle(); | 91 return shared_memory_.handle(); |
| 97 } | 92 } |
| OLD | NEW |