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/eintr_wrapper.h" | 10 #include "base/eintr_wrapper.h" |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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()) |
67 return NULL; | 67 return NULL; |
68 scoped_ptr<skia::PlatformCanvas> canvas(new skia::PlatformCanvas); | 68 return skia::CreatePlatformCanvas(w, h, true, |
69 if (!canvas->initialize(w, h, true, reinterpret_cast<uint8_t*>(memory()))) { | 69 reinterpret_cast<uint8_t*>(memory()), |
70 // TODO(husky): Remove when http://b/issue?id=4233182 is definitely fixed. | 70 skia::RETURN_NULL_ON_FAILURE); |
71 LOG(ERROR) << "Failed to initialize canvas of size " << w << "x" << h; | |
72 return NULL; | |
73 } | |
74 return canvas.release(); | |
75 } | 71 } |
76 | 72 |
77 bool TransportDIB::Map() { | 73 bool TransportDIB::Map() { |
78 if (!is_valid_handle(handle())) | 74 if (!is_valid_handle(handle())) |
79 return false; | 75 return false; |
80 // We will use ashmem_get_size_region() to figure out the size in Map(size). | 76 // We will use ashmem_get_size_region() to figure out the size in Map(size). |
81 if (!shared_memory_.Map(0)) | 77 if (!shared_memory_.Map(0)) |
82 return false; | 78 return false; |
83 | 79 |
84 // TODO: Note that using created_size() below is a hack. See the comment in | 80 // TODO: Note that using created_size() below is a hack. See the comment in |
85 // SharedMemory::Map(). | 81 // SharedMemory::Map(). |
86 size_ = shared_memory_.created_size(); | 82 size_ = shared_memory_.created_size(); |
87 return true; | 83 return true; |
88 } | 84 } |
89 | 85 |
90 void* TransportDIB::memory() const { | 86 void* TransportDIB::memory() const { |
91 return shared_memory_.memory(); | 87 return shared_memory_.memory(); |
92 } | 88 } |
93 | 89 |
94 TransportDIB::Id TransportDIB::id() const { | 90 TransportDIB::Id TransportDIB::id() const { |
95 // Use FileDescriptor as id. | 91 // Use FileDescriptor as id. |
96 return shared_memory_.handle(); | 92 return shared_memory_.handle(); |
97 } | 93 } |
98 | 94 |
99 TransportDIB::Handle TransportDIB::handle() const { | 95 TransportDIB::Handle TransportDIB::handle() const { |
100 return shared_memory_.handle(); | 96 return shared_memory_.handle(); |
101 } | 97 } |
OLD | NEW |