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 <windows.h> | |
6 | |
5 #include <limits> | 7 #include <limits> |
6 #include <windows.h> | |
7 | 8 |
8 #include "app/surface/transport_dib.h" | 9 #include "app/surface/transport_dib.h" |
brettw
2010/11/09 06:02:40
Technically this include should be first. Can you
kkania
2012/05/10 19:54:12
Done.
| |
9 #include "base/logging.h" | 10 #include "base/logging.h" |
10 #include "base/scoped_ptr.h" | 11 #include "base/scoped_ptr.h" |
11 #include "base/sys_info.h" | 12 #include "base/sys_info.h" |
12 #include "skia/ext/platform_canvas.h" | 13 #include "skia/ext/platform_canvas.h" |
13 | 14 |
14 TransportDIB::TransportDIB() { | 15 TransportDIB::TransportDIB() { |
15 } | 16 } |
16 | 17 |
17 TransportDIB::~TransportDIB() { | 18 TransportDIB::~TransportDIB() { |
18 } | 19 } |
(...skipping 15 matching lines...) Expand all Loading... | |
34 return NULL; | 35 return NULL; |
35 } | 36 } |
36 | 37 |
37 dib->size_ = size; | 38 dib->size_ = size; |
38 dib->sequence_num_ = sequence_num; | 39 dib->sequence_num_ = sequence_num; |
39 | 40 |
40 return dib; | 41 return dib; |
41 } | 42 } |
42 | 43 |
43 // static | 44 // static |
44 TransportDIB* TransportDIB::Map(TransportDIB::Handle handle) { | 45 TransportDIB* TransportDIB::Map(Handle handle) { |
45 TransportDIB* dib = new TransportDIB(handle); | 46 scoped_ptr<TransportDIB> dib(CreateWithHandle(handle)); |
46 if (!dib->shared_memory_.Map(0 /* map whole shared memory segment */)) { | 47 if (!dib->Map()) |
48 return NULL; | |
49 return dib.release(); | |
50 } | |
51 | |
52 // static | |
53 TransportDIB* TransportDIB::CreateWithHandle(Handle handle) { | |
54 return new TransportDIB(handle); | |
55 } | |
56 | |
57 // static | |
58 bool TransportDIB::is_valid(Handle dib) { | |
59 return dib != NULL; | |
60 } | |
61 | |
62 skia::PlatformCanvas* TransportDIB::GetPlatformCanvas(int w, int h) { | |
63 // This DIB already mapped the file into this process, but PlatformCanvas | |
64 // will map it again. | |
65 DCHECK(!memory()) << "Mapped file twice in the same process."; | |
66 | |
67 scoped_ptr<skia::PlatformCanvas> canvas(new skia::PlatformCanvas); | |
68 if (!canvas->initialize(w, h, true, handle())) | |
69 return NULL; | |
70 return canvas.release(); | |
71 } | |
72 | |
73 bool TransportDIB::Map() { | |
74 if (!is_valid(handle())) | |
75 return false; | |
76 if (memory()) | |
77 return true; | |
78 | |
79 if (!shared_memory_.Map(0 /* map whole shared memory segment */)) { | |
47 LOG(ERROR) << "Failed to map transport DIB" | 80 LOG(ERROR) << "Failed to map transport DIB" |
48 << " handle:" << handle | 81 << " handle:" << shared_memory_.handle() |
49 << " error:" << GetLastError(); | 82 << " error:" << ::GetLastError(); |
50 delete dib; | 83 return false; |
51 return NULL; | |
52 } | 84 } |
53 | 85 |
54 // There doesn't seem to be any way to find the size of the shared memory | 86 // There doesn't seem to be any way to find the size of the shared memory |
55 // region! GetFileSize indicates that the handle is invalid. Thus, we | 87 // region! GetFileSize indicates that the handle is invalid. Thus, we |
56 // conservatively set the size to the maximum and hope that the renderer | 88 // conservatively set the size to the maximum and hope that the renderer |
57 // isn't about to ask us to read off the end of the array. | 89 // isn't about to ask us to read off the end of the array. |
58 dib->size_ = std::numeric_limits<size_t>::max(); | 90 size_ = std::numeric_limits<size_t>::max(); |
59 | 91 return true; |
60 return dib; | |
61 } | |
62 | |
63 bool TransportDIB::is_valid(Handle dib) { | |
64 return dib != NULL; | |
65 } | |
66 | |
67 skia::PlatformCanvas* TransportDIB::GetPlatformCanvas(int w, int h) { | |
68 scoped_ptr<skia::PlatformCanvas> canvas(new skia::PlatformCanvas); | |
69 if (!canvas->initialize(w, h, true, handle())) | |
70 return NULL; | |
71 return canvas.release(); | |
72 } | 92 } |
73 | 93 |
74 void* TransportDIB::memory() const { | 94 void* TransportDIB::memory() const { |
75 return shared_memory_.memory(); | 95 return shared_memory_.memory(); |
76 } | 96 } |
77 | 97 |
78 TransportDIB::Handle TransportDIB::handle() const { | 98 TransportDIB::Handle TransportDIB::handle() const { |
79 return shared_memory_.handle(); | 99 return shared_memory_.handle(); |
80 } | 100 } |
81 | 101 |
82 TransportDIB::Id TransportDIB::id() const { | 102 TransportDIB::Id TransportDIB::id() const { |
83 return Id(shared_memory_.handle(), sequence_num_); | 103 return Id(handle(), sequence_num_); |
84 } | 104 } |
OLD | NEW |