Chromium Code Reviews| Index: app/surface/transport_dib_win.cc |
| diff --git a/app/surface/transport_dib_win.cc b/app/surface/transport_dib_win.cc |
| index 63506b2ca2d5fa5fb8ca25fbd369f717082291b3..a9ebe697de72b098e716252f7d01951cbd6f8b69 100644 |
| --- a/app/surface/transport_dib_win.cc |
| +++ b/app/surface/transport_dib_win.cc |
| @@ -2,9 +2,10 @@ |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| -#include <limits> |
| #include <windows.h> |
| +#include <limits> |
| + |
| #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.
|
| #include "base/logging.h" |
| #include "base/scoped_ptr.h" |
| @@ -41,36 +42,55 @@ TransportDIB* TransportDIB::Create(size_t size, uint32 sequence_num) { |
| } |
| // static |
| -TransportDIB* TransportDIB::Map(TransportDIB::Handle handle) { |
| - TransportDIB* dib = new TransportDIB(handle); |
| - if (!dib->shared_memory_.Map(0 /* map whole shared memory segment */)) { |
| - LOG(ERROR) << "Failed to map transport DIB" |
| - << " handle:" << handle |
| - << " error:" << GetLastError(); |
| - delete dib; |
| +TransportDIB* TransportDIB::Map(Handle handle) { |
| + scoped_ptr<TransportDIB> dib(CreateWithHandle(handle)); |
| + if (!dib->Map()) |
| return NULL; |
| - } |
| - |
| - // There doesn't seem to be any way to find the size of the shared memory |
| - // region! GetFileSize indicates that the handle is invalid. Thus, we |
| - // conservatively set the size to the maximum and hope that the renderer |
| - // isn't about to ask us to read off the end of the array. |
| - dib->size_ = std::numeric_limits<size_t>::max(); |
| + return dib.release(); |
| +} |
| - return dib; |
| +// static |
| +TransportDIB* TransportDIB::CreateWithHandle(Handle handle) { |
| + return new TransportDIB(handle); |
| } |
| +// static |
| bool TransportDIB::is_valid(Handle dib) { |
| return dib != NULL; |
| } |
| skia::PlatformCanvas* TransportDIB::GetPlatformCanvas(int w, int h) { |
| + // This DIB already mapped the file into this process, but PlatformCanvas |
| + // will map it again. |
| + DCHECK(!memory()) << "Mapped file twice in the same process."; |
| + |
| scoped_ptr<skia::PlatformCanvas> canvas(new skia::PlatformCanvas); |
| if (!canvas->initialize(w, h, true, handle())) |
| return NULL; |
| return canvas.release(); |
| } |
| +bool TransportDIB::Map() { |
| + if (!is_valid(handle())) |
| + return false; |
| + if (memory()) |
| + return true; |
| + |
| + if (!shared_memory_.Map(0 /* map whole shared memory segment */)) { |
| + LOG(ERROR) << "Failed to map transport DIB" |
| + << " handle:" << shared_memory_.handle() |
| + << " error:" << ::GetLastError(); |
| + return false; |
| + } |
| + |
| + // There doesn't seem to be any way to find the size of the shared memory |
| + // region! GetFileSize indicates that the handle is invalid. Thus, we |
| + // conservatively set the size to the maximum and hope that the renderer |
| + // isn't about to ask us to read off the end of the array. |
| + size_ = std::numeric_limits<size_t>::max(); |
| + return true; |
| +} |
| + |
| void* TransportDIB::memory() const { |
| return shared_memory_.memory(); |
| } |
| @@ -80,5 +100,5 @@ TransportDIB::Handle TransportDIB::handle() const { |
| } |
| TransportDIB::Id TransportDIB::id() const { |
| - return Id(shared_memory_.handle(), sequence_num_); |
| + return Id(handle(), sequence_num_); |
| } |