egl: Don't query EGL_POST_SUB_BUFFER_SUPPORTED_NV without extension
[chromium-blink-merge.git] / content / child / child_shared_bitmap_manager.cc
bloba62fd41473a2f053ba566f7dcc7f59c57fc5e847
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "content/child/child_shared_bitmap_manager.h"
7 #include "content/child/child_thread.h"
8 #include "content/common/child_process_messages.h"
9 #include "ui/gfx/size.h"
11 namespace content {
13 namespace {
15 class ChildSharedBitmap : public cc::SharedBitmap {
16 public:
17 ChildSharedBitmap(scoped_refptr<ThreadSafeSender> sender,
18 base::SharedMemory* shared_memory,
19 const cc::SharedBitmapId& id)
20 : SharedBitmap(static_cast<uint8*>(shared_memory->memory()), id),
21 sender_(sender),
22 shared_memory_(shared_memory) {}
24 ChildSharedBitmap(scoped_refptr<ThreadSafeSender> sender,
25 scoped_ptr<base::SharedMemory> shared_memory_holder,
26 const cc::SharedBitmapId& id)
27 : ChildSharedBitmap(sender, shared_memory_holder.get(), id) {
28 shared_memory_holder_ = shared_memory_holder.Pass();
31 ~ChildSharedBitmap() override {
32 sender_->Send(new ChildProcessHostMsg_DeletedSharedBitmap(id()));
35 base::SharedMemory* memory() override { return shared_memory_; }
37 private:
38 scoped_refptr<ThreadSafeSender> sender_;
39 base::SharedMemory* shared_memory_;
40 scoped_ptr<base::SharedMemory> shared_memory_holder_;
43 } // namespace
45 ChildSharedBitmapManager::ChildSharedBitmapManager(
46 scoped_refptr<ThreadSafeSender> sender)
47 : sender_(sender) {
50 ChildSharedBitmapManager::~ChildSharedBitmapManager() {}
52 scoped_ptr<cc::SharedBitmap> ChildSharedBitmapManager::AllocateSharedBitmap(
53 const gfx::Size& size) {
54 TRACE_EVENT2("renderer",
55 "ChildSharedBitmapManager::AllocateSharedMemory",
56 "width",
57 size.width(),
58 "height",
59 size.height());
60 size_t memory_size;
61 if (!cc::SharedBitmap::SizeInBytes(size, &memory_size))
62 return scoped_ptr<cc::SharedBitmap>();
63 cc::SharedBitmapId id = cc::SharedBitmap::GenerateId();
64 scoped_ptr<base::SharedMemory> memory;
65 #if defined(OS_POSIX)
66 base::SharedMemoryHandle handle;
67 sender_->Send(new ChildProcessHostMsg_SyncAllocateSharedBitmap(
68 memory_size, id, &handle));
69 memory = make_scoped_ptr(new base::SharedMemory(handle, false));
70 if (!memory->Map(memory_size))
71 CHECK(false);
72 #else
73 memory = ChildThread::AllocateSharedMemory(memory_size, sender_.get());
74 CHECK(memory);
75 if (!memory->Map(memory_size))
76 CHECK(false);
77 base::SharedMemoryHandle handle_to_send = memory->handle();
78 sender_->Send(new ChildProcessHostMsg_AllocatedSharedBitmap(
79 memory_size, handle_to_send, id));
80 #endif
81 return make_scoped_ptr(new ChildSharedBitmap(sender_, memory.Pass(), id));
84 scoped_ptr<cc::SharedBitmap> ChildSharedBitmapManager::GetSharedBitmapFromId(
85 const gfx::Size&,
86 const cc::SharedBitmapId&) {
87 NOTREACHED();
88 return scoped_ptr<cc::SharedBitmap>();
91 scoped_ptr<cc::SharedBitmap> ChildSharedBitmapManager::GetBitmapForSharedMemory(
92 base::SharedMemory* mem) {
93 cc::SharedBitmapId id = cc::SharedBitmap::GenerateId();
94 base::SharedMemoryHandle handle_to_send = mem->handle();
95 #if defined(OS_POSIX)
96 if (!mem->ShareToProcess(base::GetCurrentProcessHandle(), &handle_to_send))
97 return scoped_ptr<cc::SharedBitmap>();
98 #endif
99 sender_->Send(new ChildProcessHostMsg_AllocatedSharedBitmap(
100 mem->mapped_size(), handle_to_send, id));
102 return make_scoped_ptr(new ChildSharedBitmap(sender_, mem, id));
105 } // namespace content