Commit 1953007c authored by reveman's avatar reveman Committed by Commit bot

content: Move all GpuMemoryBuffer allocation to IO thread.

Allocation of a GpuMemoryBuffer is still asynchronous on the UI
thread and as a result also for the renderer on the browser side.
However, allocation of a GpuMemoryBuffer still need to be
synchronous for the browser compositor but instead of limiting
the browser compositor to GpuMemoryBuffer implementations that
can be allocated synchronously, we block on the UI thread while
waiting for allocation to be handled asynchronous on the IO
thread. This allows all GpuMemoryBuffer implementations to be
used with the browser compositor.

BUG=380861

Review URL: https://codereview.chromium.org/542083002

Cr-Commit-Position: refs/heads/master@{#293871}
parent fac2f875
......@@ -26,8 +26,10 @@ namespace content {
BrowserGpuChannelHostFactory* BrowserGpuChannelHostFactory::instance_ = NULL;
struct BrowserGpuChannelHostFactory::CreateRequest {
CreateRequest()
: event(true, false), gpu_host_id(0), route_id(MSG_ROUTING_NONE),
CreateRequest(int32 route_id)
: event(true, false),
gpu_host_id(0),
route_id(route_id),
result(CREATE_COMMAND_BUFFER_FAILED) {}
~CreateRequest() {}
base::WaitableEvent event;
......@@ -36,6 +38,25 @@ struct BrowserGpuChannelHostFactory::CreateRequest {
CreateCommandBufferResult result;
};
struct BrowserGpuChannelHostFactory::AllocateGpuMemoryBufferRequest {
AllocateGpuMemoryBufferRequest(size_t width,
size_t height,
unsigned internalformat,
unsigned usage)
: event(true, false),
width(width),
height(height),
internalformat(internalformat),
usage(usage) {}
~AllocateGpuMemoryBufferRequest() {}
base::WaitableEvent event;
size_t width;
size_t height;
unsigned internalformat;
unsigned usage;
scoped_ptr<gfx::GpuMemoryBuffer> result;
};
class BrowserGpuChannelHostFactory::EstablishRequest
: public base::RefCountedThreadSafe<EstablishRequest> {
public:
......@@ -278,8 +299,7 @@ CreateCommandBufferResult BrowserGpuChannelHostFactory::CreateViewCommandBuffer(
int32 surface_id,
const GPUCreateCommandBufferConfig& init_params,
int32 route_id) {
CreateRequest request;
request.route_id = route_id;
CreateRequest request(route_id);
GetIOLoopProxy()->PostTask(FROM_HERE, base::Bind(
&BrowserGpuChannelHostFactory::CreateViewCommandBufferOnIO,
base::Unretained(this),
......@@ -363,13 +383,69 @@ BrowserGpuChannelHostFactory::AllocateGpuMemoryBuffer(size_t width,
size_t height,
unsigned internalformat,
unsigned usage) {
if (!GpuMemoryBufferImpl::IsFormatValid(internalformat) ||
!GpuMemoryBufferImpl::IsUsageValid(usage))
return scoped_ptr<gfx::GpuMemoryBuffer>();
DCHECK(!BrowserThread::CurrentlyOn(BrowserThread::IO));
AllocateGpuMemoryBufferRequest request(width, height, internalformat, usage);
GetIOLoopProxy()->PostTask(
FROM_HERE,
base::Bind(&BrowserGpuChannelHostFactory::AllocateGpuMemoryBufferOnIO,
base::Unretained(&request)));
// We're blocking the UI thread, which is generally undesirable.
TRACE_EVENT0("browser",
"BrowserGpuChannelHostFactory::AllocateGpuMemoryBuffer");
base::ThreadRestrictions::ScopedAllowWait allow_wait;
request.event.Wait();
return request.result.Pass();
}
void BrowserGpuChannelHostFactory::DeleteGpuMemoryBuffer(
scoped_ptr<gfx::GpuMemoryBuffer> buffer) {
DCHECK(!BrowserThread::CurrentlyOn(BrowserThread::IO));
GetIOLoopProxy()->PostTask(
FROM_HERE,
base::Bind(&BrowserGpuChannelHostFactory::DeleteGpuMemoryBufferOnIO,
base::Passed(&buffer)));
}
void BrowserGpuChannelHostFactory::CreateGpuMemoryBuffer(
const gfx::GpuMemoryBufferHandle& handle,
const gfx::Size& size,
unsigned internalformat,
unsigned usage,
const CreateGpuMemoryBufferCallback& callback) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
GpuProcessHost* host = GpuProcessHost::FromID(gpu_host_id_);
if (!host) {
callback.Run(gfx::GpuMemoryBufferHandle());
return;
}
return GpuMemoryBufferImpl::Create(gfx::Size(width, height),
internalformat,
usage).PassAs<gfx::GpuMemoryBuffer>();
uint32 request_id = next_create_gpu_memory_buffer_request_id_++;
create_gpu_memory_buffer_requests_[request_id] = callback;
host->CreateGpuMemoryBuffer(
handle,
size,
internalformat,
usage,
base::Bind(&BrowserGpuChannelHostFactory::OnGpuMemoryBufferCreated,
base::Unretained(this),
request_id));
}
void BrowserGpuChannelHostFactory::DestroyGpuMemoryBuffer(
const gfx::GpuMemoryBufferHandle& handle,
int32 sync_point) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
GpuProcessHost* host = GpuProcessHost::FromID(gpu_host_id_);
if (!host)
return;
host->DestroyGpuMemoryBuffer(handle, sync_point);
}
// static
......@@ -406,75 +482,33 @@ void BrowserGpuChannelHostFactory::SetHandlerForControlMessages(
filter));
}
void BrowserGpuChannelHostFactory::CreateGpuMemoryBuffer(
const gfx::GpuMemoryBufferHandle& handle,
const gfx::Size& size,
unsigned internalformat,
unsigned usage,
const CreateGpuMemoryBufferCallback& callback) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
uint32 request_id = next_create_gpu_memory_buffer_request_id_++;
create_gpu_memory_buffer_requests_[request_id] = callback;
GetIOLoopProxy()->PostTask(
FROM_HERE,
base::Bind(&BrowserGpuChannelHostFactory::CreateGpuMemoryBufferOnIO,
base::Unretained(this),
handle,
size,
internalformat,
usage,
request_id));
}
void BrowserGpuChannelHostFactory::DestroyGpuMemoryBuffer(
const gfx::GpuMemoryBufferHandle& handle,
int32 sync_point) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
GetIOLoopProxy()->PostTask(
FROM_HERE,
base::Bind(&BrowserGpuChannelHostFactory::DestroyGpuMemoryBufferOnIO,
base::Unretained(this),
handle,
sync_point));
}
void BrowserGpuChannelHostFactory::CreateGpuMemoryBufferOnIO(
const gfx::GpuMemoryBufferHandle& handle,
const gfx::Size& size,
unsigned internalformat,
unsigned usage,
uint32 request_id) {
GpuProcessHost* host = GpuProcessHost::FromID(gpu_host_id_);
if (!host) {
GpuMemoryBufferCreatedOnIO(request_id, gfx::GpuMemoryBufferHandle());
// static
void BrowserGpuChannelHostFactory::AllocateGpuMemoryBufferOnIO(
AllocateGpuMemoryBufferRequest* request) {
if (!GpuMemoryBufferImpl::IsFormatValid(request->internalformat) ||
!GpuMemoryBufferImpl::IsUsageValid(request->usage)) {
request->result = scoped_ptr<gfx::GpuMemoryBuffer>();
request->event.Signal();
return;
}
host->CreateGpuMemoryBuffer(
handle,
size,
internalformat,
usage,
base::Bind(&BrowserGpuChannelHostFactory::GpuMemoryBufferCreatedOnIO,
base::Unretained(this),
request_id));
request->result = GpuMemoryBufferImpl::Create(
gfx::Size(request->width, request->height),
request->internalformat,
request->usage).PassAs<gfx::GpuMemoryBuffer>();
request->event.Signal();
}
void BrowserGpuChannelHostFactory::GpuMemoryBufferCreatedOnIO(
uint32 request_id,
const gfx::GpuMemoryBufferHandle& handle) {
BrowserThread::PostTask(
BrowserThread::UI,
FROM_HERE,
base::Bind(&BrowserGpuChannelHostFactory::OnGpuMemoryBufferCreated,
base::Unretained(this),
request_id,
handle));
// static
void BrowserGpuChannelHostFactory::DeleteGpuMemoryBufferOnIO(
scoped_ptr<gfx::GpuMemoryBuffer> buffer) {
}
void BrowserGpuChannelHostFactory::OnGpuMemoryBufferCreated(
uint32 request_id,
const gfx::GpuMemoryBufferHandle& handle) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
CreateGpuMemoryBufferCallbackMap::iterator iter =
create_gpu_memory_buffer_requests_.find(request_id);
DCHECK(iter != create_gpu_memory_buffer_requests_.end());
......@@ -482,14 +516,4 @@ void BrowserGpuChannelHostFactory::OnGpuMemoryBufferCreated(
create_gpu_memory_buffer_requests_.erase(iter);
}
void BrowserGpuChannelHostFactory::DestroyGpuMemoryBufferOnIO(
const gfx::GpuMemoryBufferHandle& handle,
int32 sync_point) {
GpuProcessHost* host = GpuProcessHost::FromID(gpu_host_id_);
if (!host)
return;
host->DestroyGpuMemoryBuffer(handle, sync_point);
}
} // namespace content
......@@ -39,7 +39,7 @@ class CONTENT_EXPORT BrowserGpuChannelHostFactory
unsigned internalformat,
unsigned usage) OVERRIDE;
virtual void DeleteGpuMemoryBuffer(
scoped_ptr<gfx::GpuMemoryBuffer> buffer) OVERRIDE {}
scoped_ptr<gfx::GpuMemoryBuffer> buffer) OVERRIDE;
// GpuMemoryBufferFactoryHost implementation.
virtual void CreateGpuMemoryBuffer(
......@@ -72,6 +72,7 @@ class CONTENT_EXPORT BrowserGpuChannelHostFactory
private:
struct CreateRequest;
struct AllocateGpuMemoryBufferRequest;
class EstablishRequest;
BrowserGpuChannelHostFactory();
......@@ -86,20 +87,12 @@ class CONTENT_EXPORT BrowserGpuChannelHostFactory
CreateCommandBufferResult result);
static void AddFilterOnIO(int gpu_host_id,
scoped_refptr<IPC::MessageFilter> filter);
void CreateGpuMemoryBufferOnIO(const gfx::GpuMemoryBufferHandle& handle,
const gfx::Size& size,
unsigned internalformat,
unsigned usage,
uint32 request_id);
void GpuMemoryBufferCreatedOnIO(
uint32 request_id,
const gfx::GpuMemoryBufferHandle& handle);
void OnGpuMemoryBufferCreated(
uint32 request_id,
const gfx::GpuMemoryBufferHandle& handle);
void DestroyGpuMemoryBufferOnIO(const gfx::GpuMemoryBufferHandle& handle,
int32 sync_point);
static void AllocateGpuMemoryBufferOnIO(
AllocateGpuMemoryBufferRequest* request);
static void DeleteGpuMemoryBufferOnIO(
scoped_ptr<gfx::GpuMemoryBuffer> buffer);
void OnGpuMemoryBufferCreated(uint32 request_id,
const gfx::GpuMemoryBufferHandle& handle);
const int gpu_client_id_;
scoped_ptr<base::WaitableEvent> shutdown_event_;
......@@ -107,7 +100,6 @@ class CONTENT_EXPORT BrowserGpuChannelHostFactory
int gpu_host_id_;
scoped_refptr<EstablishRequest> pending_request_;
std::vector<base::Closure> established_callbacks_;
uint32 next_create_gpu_memory_buffer_request_id_;
typedef std::map<uint32, CreateGpuMemoryBufferCallback>
CreateGpuMemoryBufferCallbackMap;
......
......@@ -10,6 +10,7 @@
#include "base/bind_helpers.h"
#include "base/command_line.h"
#include "base/debug/alias.h"
#include "base/numerics/safe_math.h"
#include "base/strings/sys_string_conversions.h"
#include "base/strings/utf_string_conversions.h"
#include "base/threading/thread.h"
......@@ -34,6 +35,7 @@
#include "content/common/cookie_data.h"
#include "content/common/desktop_notification_messages.h"
#include "content/common/frame_messages.h"
#include "content/common/gpu/client/gpu_memory_buffer_impl.h"
#include "content/common/host_shared_bitmap_manager.h"
#include "content/common/media/media_param_traits.h"
#include "content/common/view_messages.h"
......@@ -70,6 +72,7 @@
#include "ui/gfx/color_profile.h"
#if defined(OS_MACOSX)
#include "content/common/gpu/client/gpu_memory_buffer_impl_io_surface.h"
#include "content/common/mac/font_descriptor.h"
#else
#include "gpu/GLES2/gl2extchromium.h"
......@@ -84,6 +87,8 @@
#include "content/common/sandbox_win.h"
#endif
#if defined(OS_ANDROID)
#include "content/browser/renderer_host/compositor_impl_android.h"
#include "content/common/gpu/client/gpu_memory_buffer_impl_surface_texture.h"
#include "media/base/android/webaudio_media_codec_bridge.h"
#endif
......@@ -222,6 +227,23 @@ class OpenChannelToPpapiBrokerCallback
};
#endif // defined(ENABLE_PLUGINS)
#if defined(OS_MACOSX)
void AddBooleanValue(CFMutableDictionaryRef dictionary,
const CFStringRef key,
bool value) {
CFDictionaryAddValue(
dictionary, key, value ? kCFBooleanTrue : kCFBooleanFalse);
}
void AddIntegerValue(CFMutableDictionaryRef dictionary,
const CFStringRef key,
int32 value) {
base::ScopedCFTypeRef<CFNumberRef> number(
CFNumberCreate(NULL, kCFNumberSInt32Type, &value));
CFDictionaryAddValue(dictionary, key, number.get());
}
#endif
} // namespace
class RenderMessageFilter::OpenChannelToNpapiPluginCallback
......@@ -359,6 +381,9 @@ void RenderMessageFilter::OnChannelClosing() {
}
#endif // defined(ENABLE_PLUGINS)
plugin_host_clients_.clear();
#if defined(OS_ANDROID)
CompositorImpl::DestroyAllSurfaceTextures(render_process_id_);
#endif
}
void RenderMessageFilter::OnChannelConnected(int32 peer_id) {
......@@ -424,6 +449,11 @@ bool RenderMessageFilter::OnMessageReceived(const IPC::Message& message) {
OnAllocateSharedMemory)
IPC_MESSAGE_HANDLER_DELAY_REPLY(
ChildProcessHostMsg_SyncAllocateSharedBitmap, OnAllocateSharedBitmap)
IPC_MESSAGE_HANDLER_DELAY_REPLY(
ChildProcessHostMsg_SyncAllocateGpuMemoryBuffer,
OnAllocateGpuMemoryBuffer)
IPC_MESSAGE_HANDLER(ChildProcessHostMsg_DeletedGpuMemoryBuffer,
OnDeletedGpuMemoryBuffer)
IPC_MESSAGE_HANDLER(ChildProcessHostMsg_AllocatedSharedBitmap,
OnAllocatedSharedBitmap)
IPC_MESSAGE_HANDLER(ChildProcessHostMsg_DeletedSharedBitmap,
......@@ -1220,7 +1250,6 @@ void RenderMessageFilter::OnWebAudioMediaCodec(
}
#endif
void RenderMessageFilter::OnAddNavigationTransitionData(
int render_frame_id,
const std::string& allowed_destination_host_pattern,
......@@ -1231,4 +1260,108 @@ void RenderMessageFilter::OnAddNavigationTransitionData(
selector, markup);
}
void RenderMessageFilter::OnAllocateGpuMemoryBuffer(uint32 width,
uint32 height,
uint32 internalformat,
uint32 usage,
IPC::Message* reply) {
if (!GpuMemoryBufferImpl::IsFormatValid(internalformat) ||
!GpuMemoryBufferImpl::IsUsageValid(usage)) {
GpuMemoryBufferAllocated(reply, gfx::GpuMemoryBufferHandle());
return;
}
base::CheckedNumeric<int> size = width;
size *= height;
if (!size.IsValid()) {
GpuMemoryBufferAllocated(reply, gfx::GpuMemoryBufferHandle());
return;
}
#if defined(OS_MACOSX)
// TODO(reveman): This should be moved to
// GpuMemoryBufferImpl::AllocateForChildProcess and
// GpuMemoryBufferImplIOSurface. crbug.com/325045, crbug.com/323304
if (GpuMemoryBufferImplIOSurface::IsConfigurationSupported(internalformat,
usage)) {
base::ScopedCFTypeRef<CFMutableDictionaryRef> properties;
properties.reset(
CFDictionaryCreateMutable(kCFAllocatorDefault,
0,
&kCFTypeDictionaryKeyCallBacks,
&kCFTypeDictionaryValueCallBacks));
AddIntegerValue(properties, kIOSurfaceWidth, width);
AddIntegerValue(properties, kIOSurfaceHeight, height);
AddIntegerValue(properties,
kIOSurfaceBytesPerElement,
GpuMemoryBufferImpl::BytesPerPixel(internalformat));
AddIntegerValue(properties,
kIOSurfacePixelFormat,
GpuMemoryBufferImplIOSurface::PixelFormat(internalformat));
// TODO(reveman): Remove this when using a mach_port_t to transfer
// IOSurface to renderer process. crbug.com/323304
AddBooleanValue(properties, kIOSurfaceIsGlobal, true);
base::ScopedCFTypeRef<IOSurfaceRef> io_surface(IOSurfaceCreate(properties));
if (io_surface) {
gfx::GpuMemoryBufferHandle handle;
handle.type = gfx::IO_SURFACE_BUFFER;
handle.io_surface_id = IOSurfaceGetID(io_surface);
// TODO(reveman): This makes the assumption that the renderer will
// grab a reference to the surface before sending another message.
// crbug.com/325045
last_io_surface_ = io_surface;
GpuMemoryBufferAllocated(reply, handle);
return;
}
}
#endif
#if defined(OS_ANDROID)
// TODO(reveman): This should be moved to
// GpuMemoryBufferImpl::AllocateForChildProcess and
// GpuMemoryBufferImplSurfaceTexture when adding support for out-of-process
// GPU service. crbug.com/368716
if (GpuMemoryBufferImplSurfaceTexture::IsConfigurationSupported(
internalformat, usage)) {
// Each surface texture is associated with a render process id. This allows
// the GPU service and Java Binder IPC to verify that a renderer is not
// trying to use a surface texture it doesn't own.
int surface_texture_id =
CompositorImpl::CreateSurfaceTexture(render_process_id_);
if (surface_texture_id != -1) {
gfx::GpuMemoryBufferHandle handle;
handle.type = gfx::SURFACE_TEXTURE_BUFFER;
handle.surface_texture_id =
gfx::SurfaceTextureId(surface_texture_id, render_process_id_);
GpuMemoryBufferAllocated(reply, handle);
return;
}
}
#endif
GpuMemoryBufferImpl::AllocateForChildProcess(
gfx::Size(width, height),
internalformat,
usage,
PeerHandle(),
render_process_id_,
base::Bind(&RenderMessageFilter::GpuMemoryBufferAllocated, this, reply));
}
void RenderMessageFilter::GpuMemoryBufferAllocated(
IPC::Message* reply,
const gfx::GpuMemoryBufferHandle& handle) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
ChildProcessHostMsg_SyncAllocateGpuMemoryBuffer::WriteReplyParams(reply,
handle);
Send(reply);
}
void RenderMessageFilter::OnDeletedGpuMemoryBuffer(
gfx::GpuMemoryBufferType type,
const gfx::GpuMemoryBufferId& id) {
GpuMemoryBufferImpl::DeletedByChildProcess(type, id, PeerHandle());
}
} // namespace content
......@@ -27,10 +27,13 @@
#include "media/base/channel_layout.h"
#include "net/cookies/canonical_cookie.h"
#include "third_party/WebKit/public/web/WebPopupType.h"
#include "ui/gfx/gpu_memory_buffer.h"
#include "ui/gfx/native_widget_types.h"
#include "ui/surface/transport_dib.h"
#if defined(OS_MACOSX)
#include <IOSurface/IOSurfaceAPI.h>
#include "base/mac/scoped_cftyperef.h"
#include "content/common/mac/font_loader.h"
#endif
......@@ -55,6 +58,10 @@ class SharedMemory;
class TaskRunner;
}
namespace gfx {
struct GpuMemoryBufferHandle;
}
namespace media {
class AudioManager;
struct MediaLogEvent;
......@@ -281,6 +288,16 @@ class RenderMessageFilter : public BrowserMessageFilter {
const std::string& selector,
const std::string& markup);
void OnAllocateGpuMemoryBuffer(uint32 width,
uint32 height,
uint32 internalformat,
uint32 usage,
IPC::Message* reply);
void GpuMemoryBufferAllocated(IPC::Message* reply,
const gfx::GpuMemoryBufferHandle& handle);
void OnDeletedGpuMemoryBuffer(gfx::GpuMemoryBufferType type,
const gfx::GpuMemoryBufferId& id);
// Cached resource request dispatcher host and plugin service, guaranteed to
// be non-null if Init succeeds. We do not own the objects, they are managed
// by the BrowserProcess, which has a wider scope than we do.
......@@ -319,6 +336,10 @@ class RenderMessageFilter : public BrowserMessageFilter {
media::AudioManager* audio_manager_;
MediaInternals* media_internals_;
#if defined(OS_MACOSX)
base::ScopedCFTypeRef<IOSurfaceRef> last_io_surface_;
#endif
DISALLOW_COPY_AND_ASSIGN(RenderMessageFilter);
};
......
......@@ -26,7 +26,6 @@
#include "base/logging.h"
#include "base/metrics/field_trial.h"
#include "base/metrics/histogram.h"
#include "base/numerics/safe_math.h"
#include "base/path_service.h"
#include "base/process/process_handle.h"
#include "base/rand_util.h"
......@@ -109,7 +108,6 @@
#include "content/common/child_process_host_impl.h"
#include "content/common/child_process_messages.h"
#include "content/common/content_switches_internal.h"
#include "content/common/gpu/client/gpu_memory_buffer_impl.h"
#include "content/common/gpu/gpu_messages.h"
#include "content/common/mojo/mojo_messages.h"
#include "content/common/resource_messages.h"
......@@ -151,13 +149,7 @@
#if defined(OS_ANDROID)
#include "content/browser/media/android/browser_demuxer_android.h"
#include "content/browser/renderer_host/compositor_impl_android.h"
#include "content/browser/screen_orientation/screen_orientation_message_filter_android.h"
#include "content/common/gpu/client/gpu_memory_buffer_impl_surface_texture.h"
#endif
#if defined(OS_MACOSX)
#include "content/common/gpu/client/gpu_memory_buffer_impl_io_surface.h"
#endif
#if defined(OS_WIN)
......@@ -340,23 +332,6 @@ class RendererSandboxedProcessLauncherDelegate
#endif // OS_POSIX
};
#if defined(OS_MACOSX)
void AddBooleanValue(CFMutableDictionaryRef dictionary,
const CFStringRef key,
bool value) {
CFDictionaryAddValue(
dictionary, key, value ? kCFBooleanTrue : kCFBooleanFalse);
}
void AddIntegerValue(CFMutableDictionaryRef dictionary,
const CFStringRef key,
int32 value) {
base::ScopedCFTypeRef<CFNumberRef> number(
CFNumberCreate(NULL, kCFNumberSInt32Type, &value));
CFDictionaryAddValue(dictionary, key, number.get());
}
#endif
const char kSessionStorageHolderKey[] = "kSessionStorageHolderKey";
class SessionStorageHolder : public base::SupportsUserData::Data {
......@@ -559,10 +534,6 @@ RenderProcessHostImpl::~RenderProcessHostImpl() {
BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
base::Bind(&RemoveShaderInfo, GetID()));
}
#if defined(OS_ANDROID)
CompositorImpl::DestroyAllSurfaceTextures(GetID());
#endif
}
void RenderProcessHostImpl::EnableSendQueue() {
......@@ -1388,11 +1359,6 @@ bool RenderProcessHostImpl::OnMessageReceived(const IPC::Message& msg) {
IPC_MESSAGE_HANDLER(ViewHostMsg_UserMetricsRecordAction,
OnUserMetricsRecordAction)
IPC_MESSAGE_HANDLER(ViewHostMsg_SavedPageAsMHTML, OnSavedPageAsMHTML)
IPC_MESSAGE_HANDLER_DELAY_REPLY(
ChildProcessHostMsg_SyncAllocateGpuMemoryBuffer,
OnAllocateGpuMemoryBuffer)
IPC_MESSAGE_HANDLER(ChildProcessHostMsg_DeletedGpuMemoryBuffer,
OnDeletedGpuMemoryBuffer)
IPC_MESSAGE_HANDLER(ViewHostMsg_Close_ACK, OnCloseACK)
#if defined(ENABLE_WEBRTC)
IPC_MESSAGE_HANDLER(AecDumpMsg_RegisterAecDumpConsumer,
......@@ -2265,113 +2231,4 @@ void RenderProcessHostImpl::EnsureMojoActivated() {
MaybeActivateMojo();
}
void RenderProcessHostImpl::OnAllocateGpuMemoryBuffer(uint32 width,
uint32 height,
uint32 internalformat,
uint32 usage,
IPC::Message* reply) {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
if (!GpuMemoryBufferImpl::IsFormatValid(internalformat) ||
!GpuMemoryBufferImpl::IsUsageValid(usage)) {
GpuMemoryBufferAllocated(reply, gfx::GpuMemoryBufferHandle());
return;
}
base::CheckedNumeric<int> size = width;
size *= height;
if (!size.IsValid()) {
GpuMemoryBufferAllocated(reply, gfx::GpuMemoryBufferHandle());
return;
}
#if defined(OS_MACOSX)
// TODO(reveman): This should be moved to
// GpuMemoryBufferImpl::AllocateForChildProcess and
// GpuMemoryBufferImplIOSurface. crbug.com/325045, crbug.com/323304
if (GpuMemoryBufferImplIOSurface::IsConfigurationSupported(internalformat,
usage)) {
base::ScopedCFTypeRef<CFMutableDictionaryRef> properties;
properties.reset(
CFDictionaryCreateMutable(kCFAllocatorDefault,
0,
&kCFTypeDictionaryKeyCallBacks,
&kCFTypeDictionaryValueCallBacks));
AddIntegerValue(properties, kIOSurfaceWidth, width);
AddIntegerValue(properties, kIOSurfaceHeight, height);
AddIntegerValue(properties,
kIOSurfaceBytesPerElement,
GpuMemoryBufferImpl::BytesPerPixel(internalformat));
AddIntegerValue(
properties,
kIOSurfacePixelFormat,
GpuMemoryBufferImplIOSurface::PixelFormat(internalformat));
// TODO(reveman): Remove this when using a mach_port_t to transfer
// IOSurface to renderer process. crbug.com/323304
AddBooleanValue(
properties, kIOSurfaceIsGlobal, true);
base::ScopedCFTypeRef<IOSurfaceRef> io_surface(IOSurfaceCreate(properties));
if (io_surface) {
gfx::GpuMemoryBufferHandle handle;
handle.type = gfx::IO_SURFACE_BUFFER;
handle.io_surface_id = IOSurfaceGetID(io_surface);
// TODO(reveman): This makes the assumption that the renderer will
// grab a reference to the surface before sending another message.
// crbug.com/325045
last_io_surface_ = io_surface;
GpuMemoryBufferAllocated(reply, handle);
return;
}
}
#endif
#if defined(OS_ANDROID)
// TODO(reveman): This should be moved to
// GpuMemoryBufferImpl::AllocateForChildProcess and
// GpuMemoryBufferImplSurfaceTexture when adding support for out-of-process
// GPU service. crbug.com/368716
if (GpuMemoryBufferImplSurfaceTexture::IsConfigurationSupported(
internalformat, usage)) {
// Each surface texture is associated with a render process id. This allows
// the GPU service and Java Binder IPC to verify that a renderer is not
// trying to use a surface texture it doesn't own.
int surface_texture_id = CompositorImpl::CreateSurfaceTexture(GetID());
if (surface_texture_id != -1) {
gfx::GpuMemoryBufferHandle handle;
handle.type = gfx::SURFACE_TEXTURE_BUFFER;
handle.surface_texture_id =
gfx::SurfaceTextureId(surface_texture_id, GetID());
GpuMemoryBufferAllocated(reply, handle);
return;
}
}
#endif
GpuMemoryBufferImpl::AllocateForChildProcess(
gfx::Size(width, height),
internalformat,
usage,
GetHandle(),
GetID(),
base::Bind(&RenderProcessHostImpl::GpuMemoryBufferAllocated,
weak_factory_.GetWeakPtr(),
reply));
}
void RenderProcessHostImpl::GpuMemoryBufferAllocated(
IPC::Message* reply,
const gfx::GpuMemoryBufferHandle& handle) {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
ChildProcessHostMsg_SyncAllocateGpuMemoryBuffer::WriteReplyParams(reply,
handle);
Send(reply);
}
void RenderProcessHostImpl::OnDeletedGpuMemoryBuffer(
gfx::GpuMemoryBufferType type,
const gfx::GpuMemoryBufferId& id) {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
GpuMemoryBufferImpl::DeletedByChildProcess(type, id, GetHandle());
}
} // namespace content
......@@ -25,11 +25,6 @@
#include "mojo/public/cpp/bindings/interface_ptr.h"
#include "ui/gfx/gpu_memory_buffer.h"
#if defined(OS_MACOSX)
#include <IOSurface/IOSurfaceAPI.h>
#include "base/mac/scoped_cftyperef.h"
#endif
namespace base {
class CommandLine;
class MessageLoop;
......@@ -37,7 +32,6 @@ class MessageLoop;
namespace gfx {
class Size;
struct GpuMemoryBufferHandle;
}
namespace content {
......@@ -325,17 +319,6 @@ class CONTENT_EXPORT RenderProcessHostImpl
void SendDisableAecDumpToRenderer();
#endif
// GpuMemoryBuffer allocation handler.
void OnAllocateGpuMemoryBuffer(uint32 width,
uint32 height,
uint32 internalformat,
uint32 usage,
IPC::Message* reply);
void GpuMemoryBufferAllocated(IPC::Message* reply,
const gfx::GpuMemoryBufferHandle& handle);
void OnDeletedGpuMemoryBuffer(gfx::GpuMemoryBufferType type,
const gfx::GpuMemoryBufferId& id);
scoped_ptr<MojoApplicationHost> mojo_application_host_;
bool mojo_activation_required_;
......@@ -455,10 +438,6 @@ class CONTENT_EXPORT RenderProcessHostImpl
base::WeakPtrFactory<RenderProcessHostImpl> weak_factory_;
#if defined(OS_MACOSX)
base::ScopedCFTypeRef<IOSurfaceRef> last_io_surface_;
#endif
DISALLOW_COPY_AND_ASSIGN(RenderProcessHostImpl);
};
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment