diff options
author | pinkerton@chromium.org <pinkerton@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-03-19 14:01:33 +0000 |
---|---|---|
committer | pinkerton@chromium.org <pinkerton@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-03-19 14:01:33 +0000 |
commit | 6c077af5c79a85d64e4b4363b8d0e29bb16543db (patch) | |
tree | 160a0dc0eb5b39a3c302655a287d1594d4ccf58e /app/surface/transport_dib_win.cc | |
parent | 9bb2d8b4792cbf769d744fd972da2d94e9fa9647 (diff) | |
download | chromium_src-6c077af5c79a85d64e4b4363b8d0e29bb16543db.zip chromium_src-6c077af5c79a85d64e4b4363b8d0e29bb16543db.tar.gz chromium_src-6c077af5c79a85d64e4b4363b8d0e29bb16543db.tar.bz2 |
Remove dependency from webkit on chrome/common by moving files to src/app.
BUG=37985
TEST=no functional change.
Review URL: http://codereview.chromium.org/1060001
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@42101 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'app/surface/transport_dib_win.cc')
-rw-r--r-- | app/surface/transport_dib_win.cc | 81 |
1 files changed, 81 insertions, 0 deletions
diff --git a/app/surface/transport_dib_win.cc b/app/surface/transport_dib_win.cc new file mode 100644 index 0000000..2a92fb1 --- /dev/null +++ b/app/surface/transport_dib_win.cc @@ -0,0 +1,81 @@ +// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// 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 "app/surface/transport_dib.h" +#include "base/logging.h" +#include "base/sys_info.h" +#include "skia/ext/platform_canvas.h" + +TransportDIB::TransportDIB() { +} + +TransportDIB::~TransportDIB() { +} + +TransportDIB::TransportDIB(HANDLE handle) + : shared_memory_(handle, false /* read write */) { +} + +// static +TransportDIB* TransportDIB::Create(size_t size, uint32 sequence_num) { + size_t allocation_granularity = base::SysInfo::VMAllocationGranularity(); + size = size / allocation_granularity + 1; + size = size * allocation_granularity; + + TransportDIB* dib = new TransportDIB; + + if (!dib->shared_memory_.Create(L"", false /* read write */, + true /* open existing */, size)) { + delete dib; + return NULL; + } + + dib->size_ = size; + dib->sequence_num_ = sequence_num; + + return dib; +} + +// 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; + 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; +} + +bool TransportDIB::is_valid(Handle dib) { + return dib != NULL; +} + +skia::PlatformCanvas* TransportDIB::GetPlatformCanvas(int w, int h) { + return new skia::PlatformCanvas(w, h, true, handle()); +} + +void* TransportDIB::memory() const { + return shared_memory_.memory(); +} + +TransportDIB::Handle TransportDIB::handle() const { + return shared_memory_.handle(); +} + +TransportDIB::Id TransportDIB::id() const { + return Id(shared_memory_.handle(), sequence_num_); +} |