This source file includes following definitions.
- size_
- Create
- Map
- CreateWithHandle
- is_valid_handle
- is_valid_id
- GetPlatformCanvas
- Map
- memory
- handle
- id
#include "ui/surface/transport_dib.h"
#include <windows.h>
#include <limits>
#include "base/logging.h"
#include "base/memory/scoped_ptr.h"
#include "base/sys_info.h"
#include "skia/ext/platform_canvas.h"
TransportDIB::TransportDIB()
: size_(0) {
}
TransportDIB::~TransportDIB() {
}
TransportDIB::TransportDIB(HANDLE handle)
: shared_memory_(handle, false ),
size_(0) {
}
TransportDIB* TransportDIB::Create(size_t size, uint32 sequence_num) {
TransportDIB* dib = new TransportDIB;
if (!dib->shared_memory_.CreateAnonymous(size)) {
delete dib;
return NULL;
}
dib->size_ = size;
dib->sequence_num_ = sequence_num;
return dib;
}
TransportDIB* TransportDIB::Map(Handle handle) {
scoped_ptr<TransportDIB> dib(CreateWithHandle(handle));
if (!dib->Map())
return NULL;
return dib.release();
}
TransportDIB* TransportDIB::CreateWithHandle(Handle handle) {
return new TransportDIB(handle);
}
bool TransportDIB::is_valid_handle(Handle dib) {
return dib != NULL;
}
bool TransportDIB::is_valid_id(TransportDIB::Id id) {
return is_valid_handle(id.handle);
}
skia::PlatformCanvas* TransportDIB::GetPlatformCanvas(int w, int h) {
DCHECK(!memory()) << "Mapped file twice in the same process.";
skia::PlatformCanvas* canvas =
skia::CreatePlatformCanvas(w, h, true, handle(),
skia::RETURN_NULL_ON_FAILURE);
if (canvas)
size_ = skia::PlatformCanvasStrideForWidth(w) * h;
return canvas;
}
bool TransportDIB::Map() {
if (!is_valid_handle(handle()))
return false;
if (memory())
return true;
if (!shared_memory_.Map(0 )) {
LOG(ERROR) << "Failed to map transport DIB"
<< " handle:" << shared_memory_.handle()
<< " error:" << ::GetLastError();
return false;
}
size_ = shared_memory_.mapped_size();
return true;
}
void* TransportDIB::memory() const {
return shared_memory_.memory();
}
TransportDIB::Handle TransportDIB::handle() const {
return shared_memory_.handle();
}
TransportDIB::Id TransportDIB::id() const {
return Id(handle(), sequence_num_);
}