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 { ...@@ -26,8 +26,10 @@ namespace content {
BrowserGpuChannelHostFactory* BrowserGpuChannelHostFactory::instance_ = NULL; BrowserGpuChannelHostFactory* BrowserGpuChannelHostFactory::instance_ = NULL;
struct BrowserGpuChannelHostFactory::CreateRequest { struct BrowserGpuChannelHostFactory::CreateRequest {
CreateRequest() CreateRequest(int32 route_id)
: event(true, false), gpu_host_id(0), route_id(MSG_ROUTING_NONE), : event(true, false),
gpu_host_id(0),
route_id(route_id),
result(CREATE_COMMAND_BUFFER_FAILED) {} result(CREATE_COMMAND_BUFFER_FAILED) {}
~CreateRequest() {} ~CreateRequest() {}
base::WaitableEvent event; base::WaitableEvent event;
...@@ -36,6 +38,25 @@ struct BrowserGpuChannelHostFactory::CreateRequest { ...@@ -36,6 +38,25 @@ struct BrowserGpuChannelHostFactory::CreateRequest {
CreateCommandBufferResult result; 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 class BrowserGpuChannelHostFactory::EstablishRequest
: public base::RefCountedThreadSafe<EstablishRequest> { : public base::RefCountedThreadSafe<EstablishRequest> {
public: public:
...@@ -278,8 +299,7 @@ CreateCommandBufferResult BrowserGpuChannelHostFactory::CreateViewCommandBuffer( ...@@ -278,8 +299,7 @@ CreateCommandBufferResult BrowserGpuChannelHostFactory::CreateViewCommandBuffer(
int32 surface_id, int32 surface_id,
const GPUCreateCommandBufferConfig& init_params, const GPUCreateCommandBufferConfig& init_params,
int32 route_id) { int32 route_id) {
CreateRequest request; CreateRequest request(route_id);
request.route_id = route_id;
GetIOLoopProxy()->PostTask(FROM_HERE, base::Bind( GetIOLoopProxy()->PostTask(FROM_HERE, base::Bind(
&BrowserGpuChannelHostFactory::CreateViewCommandBufferOnIO, &BrowserGpuChannelHostFactory::CreateViewCommandBufferOnIO,
base::Unretained(this), base::Unretained(this),
...@@ -363,13 +383,69 @@ BrowserGpuChannelHostFactory::AllocateGpuMemoryBuffer(size_t width, ...@@ -363,13 +383,69 @@ BrowserGpuChannelHostFactory::AllocateGpuMemoryBuffer(size_t width,
size_t height, size_t height,
unsigned internalformat, unsigned internalformat,
unsigned usage) { unsigned usage) {
if (!GpuMemoryBufferImpl::IsFormatValid(internalformat) || DCHECK(!BrowserThread::CurrentlyOn(BrowserThread::IO));
!GpuMemoryBufferImpl::IsUsageValid(usage))
return scoped_ptr<gfx::GpuMemoryBuffer>(); 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), uint32 request_id = next_create_gpu_memory_buffer_request_id_++;
internalformat, create_gpu_memory_buffer_requests_[request_id] = callback;
usage).PassAs<gfx::GpuMemoryBuffer>();
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 // static
...@@ -406,75 +482,33 @@ void BrowserGpuChannelHostFactory::SetHandlerForControlMessages( ...@@ -406,75 +482,33 @@ void BrowserGpuChannelHostFactory::SetHandlerForControlMessages(
filter)); filter));
} }
void BrowserGpuChannelHostFactory::CreateGpuMemoryBuffer( // static
const gfx::GpuMemoryBufferHandle& handle, void BrowserGpuChannelHostFactory::AllocateGpuMemoryBufferOnIO(
const gfx::Size& size, AllocateGpuMemoryBufferRequest* request) {
unsigned internalformat, if (!GpuMemoryBufferImpl::IsFormatValid(request->internalformat) ||
unsigned usage, !GpuMemoryBufferImpl::IsUsageValid(request->usage)) {
const CreateGpuMemoryBufferCallback& callback) { request->result = scoped_ptr<gfx::GpuMemoryBuffer>();
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); request->event.Signal();
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());
return; return;
} }
host->CreateGpuMemoryBuffer( request->result = GpuMemoryBufferImpl::Create(
handle, gfx::Size(request->width, request->height),
size, request->internalformat,
internalformat, request->usage).PassAs<gfx::GpuMemoryBuffer>();
usage, request->event.Signal();
base::Bind(&BrowserGpuChannelHostFactory::GpuMemoryBufferCreatedOnIO,
base::Unretained(this),
request_id));
} }
void BrowserGpuChannelHostFactory::GpuMemoryBufferCreatedOnIO( // static
uint32 request_id, void BrowserGpuChannelHostFactory::DeleteGpuMemoryBufferOnIO(
const gfx::GpuMemoryBufferHandle& handle) { scoped_ptr<gfx::GpuMemoryBuffer> buffer) {
BrowserThread::PostTask(
BrowserThread::UI,
FROM_HERE,
base::Bind(&BrowserGpuChannelHostFactory::OnGpuMemoryBufferCreated,
base::Unretained(this),
request_id,
handle));
} }
void BrowserGpuChannelHostFactory::OnGpuMemoryBufferCreated( void BrowserGpuChannelHostFactory::OnGpuMemoryBufferCreated(
uint32 request_id, uint32 request_id,
const gfx::GpuMemoryBufferHandle& handle) { const gfx::GpuMemoryBufferHandle& handle) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
CreateGpuMemoryBufferCallbackMap::iterator iter = CreateGpuMemoryBufferCallbackMap::iterator iter =
create_gpu_memory_buffer_requests_.find(request_id); create_gpu_memory_buffer_requests_.find(request_id);
DCHECK(iter != create_gpu_memory_buffer_requests_.end()); DCHECK(iter != create_gpu_memory_buffer_requests_.end());
...@@ -482,14 +516,4 @@ void BrowserGpuChannelHostFactory::OnGpuMemoryBufferCreated( ...@@ -482,14 +516,4 @@ void BrowserGpuChannelHostFactory::OnGpuMemoryBufferCreated(
create_gpu_memory_buffer_requests_.erase(iter); 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 } // namespace content
...@@ -39,7 +39,7 @@ class CONTENT_EXPORT BrowserGpuChannelHostFactory ...@@ -39,7 +39,7 @@ class CONTENT_EXPORT BrowserGpuChannelHostFactory
unsigned internalformat, unsigned internalformat,
unsigned usage) OVERRIDE; unsigned usage) OVERRIDE;
virtual void DeleteGpuMemoryBuffer( virtual void DeleteGpuMemoryBuffer(
scoped_ptr<gfx::GpuMemoryBuffer> buffer) OVERRIDE {} scoped_ptr<gfx::GpuMemoryBuffer> buffer) OVERRIDE;
// GpuMemoryBufferFactoryHost implementation. // GpuMemoryBufferFactoryHost implementation.
virtual void CreateGpuMemoryBuffer( virtual void CreateGpuMemoryBuffer(
...@@ -72,6 +72,7 @@ class CONTENT_EXPORT BrowserGpuChannelHostFactory ...@@ -72,6 +72,7 @@ class CONTENT_EXPORT BrowserGpuChannelHostFactory
private: private:
struct CreateRequest; struct CreateRequest;
struct AllocateGpuMemoryBufferRequest;
class EstablishRequest; class EstablishRequest;
BrowserGpuChannelHostFactory(); BrowserGpuChannelHostFactory();
...@@ -86,20 +87,12 @@ class CONTENT_EXPORT BrowserGpuChannelHostFactory ...@@ -86,20 +87,12 @@ class CONTENT_EXPORT BrowserGpuChannelHostFactory
CreateCommandBufferResult result); CreateCommandBufferResult result);
static void AddFilterOnIO(int gpu_host_id, static void AddFilterOnIO(int gpu_host_id,
scoped_refptr<IPC::MessageFilter> filter); scoped_refptr<IPC::MessageFilter> filter);
static void AllocateGpuMemoryBufferOnIO(
void CreateGpuMemoryBufferOnIO(const gfx::GpuMemoryBufferHandle& handle, AllocateGpuMemoryBufferRequest* request);
const gfx::Size& size, static void DeleteGpuMemoryBufferOnIO(
unsigned internalformat, scoped_ptr<gfx::GpuMemoryBuffer> buffer);
unsigned usage, void OnGpuMemoryBufferCreated(uint32 request_id,
uint32 request_id); const gfx::GpuMemoryBufferHandle& handle);
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);
const int gpu_client_id_; const int gpu_client_id_;
scoped_ptr<base::WaitableEvent> shutdown_event_; scoped_ptr<base::WaitableEvent> shutdown_event_;
...@@ -107,7 +100,6 @@ class CONTENT_EXPORT BrowserGpuChannelHostFactory ...@@ -107,7 +100,6 @@ class CONTENT_EXPORT BrowserGpuChannelHostFactory
int gpu_host_id_; int gpu_host_id_;
scoped_refptr<EstablishRequest> pending_request_; scoped_refptr<EstablishRequest> pending_request_;
std::vector<base::Closure> established_callbacks_; std::vector<base::Closure> established_callbacks_;
uint32 next_create_gpu_memory_buffer_request_id_; uint32 next_create_gpu_memory_buffer_request_id_;
typedef std::map<uint32, CreateGpuMemoryBufferCallback> typedef std::map<uint32, CreateGpuMemoryBufferCallback>
CreateGpuMemoryBufferCallbackMap; CreateGpuMemoryBufferCallbackMap;
......
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#include "base/bind_helpers.h" #include "base/bind_helpers.h"
#include "base/command_line.h" #include "base/command_line.h"
#include "base/debug/alias.h" #include "base/debug/alias.h"
#include "base/numerics/safe_math.h"
#include "base/strings/sys_string_conversions.h" #include "base/strings/sys_string_conversions.h"
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
#include "base/threading/thread.h" #include "base/threading/thread.h"
...@@ -34,6 +35,7 @@ ...@@ -34,6 +35,7 @@
#include "content/common/cookie_data.h" #include "content/common/cookie_data.h"
#include "content/common/desktop_notification_messages.h" #include "content/common/desktop_notification_messages.h"
#include "content/common/frame_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/host_shared_bitmap_manager.h"
#include "content/common/media/media_param_traits.h" #include "content/common/media/media_param_traits.h"
#include "content/common/view_messages.h" #include "content/common/view_messages.h"
...@@ -70,6 +72,7 @@ ...@@ -70,6 +72,7 @@
#include "ui/gfx/color_profile.h" #include "ui/gfx/color_profile.h"
#if defined(OS_MACOSX) #if defined(OS_MACOSX)
#include "content/common/gpu/client/gpu_memory_buffer_impl_io_surface.h"
#include "content/common/mac/font_descriptor.h" #include "content/common/mac/font_descriptor.h"
#else #else
#include "gpu/GLES2/gl2extchromium.h" #include "gpu/GLES2/gl2extchromium.h"
...@@ -84,6 +87,8 @@ ...@@ -84,6 +87,8 @@
#include "content/common/sandbox_win.h" #include "content/common/sandbox_win.h"
#endif #endif
#if defined(OS_ANDROID) #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" #include "media/base/android/webaudio_media_codec_bridge.h"
#endif #endif
...@@ -222,6 +227,23 @@ class OpenChannelToPpapiBrokerCallback ...@@ -222,6 +227,23 @@ class OpenChannelToPpapiBrokerCallback
}; };
#endif // defined(ENABLE_PLUGINS) #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 } // namespace
class RenderMessageFilter::OpenChannelToNpapiPluginCallback class RenderMessageFilter::OpenChannelToNpapiPluginCallback
...@@ -359,6 +381,9 @@ void RenderMessageFilter::OnChannelClosing() { ...@@ -359,6 +381,9 @@ void RenderMessageFilter::OnChannelClosing() {
} }
#endif // defined(ENABLE_PLUGINS) #endif // defined(ENABLE_PLUGINS)
plugin_host_clients_.clear(); plugin_host_clients_.clear();
#if defined(OS_ANDROID)
CompositorImpl::DestroyAllSurfaceTextures(render_process_id_);
#endif
} }
void RenderMessageFilter::OnChannelConnected(int32 peer_id) { void RenderMessageFilter::OnChannelConnected(int32 peer_id) {
...@@ -424,6 +449,11 @@ bool RenderMessageFilter::OnMessageReceived(const IPC::Message& message) { ...@@ -424,6 +449,11 @@ bool RenderMessageFilter::OnMessageReceived(const IPC::Message& message) {
OnAllocateSharedMemory) OnAllocateSharedMemory)
IPC_MESSAGE_HANDLER_DELAY_REPLY( IPC_MESSAGE_HANDLER_DELAY_REPLY(
ChildProcessHostMsg_SyncAllocateSharedBitmap, OnAllocateSharedBitmap) ChildProcessHostMsg_SyncAllocateSharedBitmap, OnAllocateSharedBitmap)
IPC_MESSAGE_HANDLER_DELAY_REPLY(
ChildProcessHostMsg_SyncAllocateGpuMemoryBuffer,
OnAllocateGpuMemoryBuffer)
IPC_MESSAGE_HANDLER(ChildProcessHostMsg_DeletedGpuMemoryBuffer,
OnDeletedGpuMemoryBuffer)
IPC_MESSAGE_HANDLER(ChildProcessHostMsg_AllocatedSharedBitmap, IPC_MESSAGE_HANDLER(ChildProcessHostMsg_AllocatedSharedBitmap,
OnAllocatedSharedBitmap) OnAllocatedSharedBitmap)
IPC_MESSAGE_HANDLER(ChildProcessHostMsg_DeletedSharedBitmap, IPC_MESSAGE_HANDLER(ChildProcessHostMsg_DeletedSharedBitmap,
...@@ -1220,7 +1250,6 @@ void RenderMessageFilter::OnWebAudioMediaCodec( ...@@ -1220,7 +1250,6 @@ void RenderMessageFilter::OnWebAudioMediaCodec(
} }
#endif #endif
void RenderMessageFilter::OnAddNavigationTransitionData( void RenderMessageFilter::OnAddNavigationTransitionData(
int render_frame_id, int render_frame_id,
const std::string& allowed_destination_host_pattern, const std::string& allowed_destination_host_pattern,
...@@ -1231,4 +1260,108 @@ void RenderMessageFilter::OnAddNavigationTransitionData( ...@@ -1231,4 +1260,108 @@ void RenderMessageFilter::OnAddNavigationTransitionData(
selector, markup); 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 } // namespace content
...@@ -27,10 +27,13 @@ ...@@ -27,10 +27,13 @@
#include "media/base/channel_layout.h" #include "media/base/channel_layout.h"
#include "net/cookies/canonical_cookie.h" #include "net/cookies/canonical_cookie.h"
#include "third_party/WebKit/public/web/WebPopupType.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/gfx/native_widget_types.h"
#include "ui/surface/transport_dib.h" #include "ui/surface/transport_dib.h"
#if defined(OS_MACOSX) #if defined(OS_MACOSX)
#include <IOSurface/IOSurfaceAPI.h>
#include "base/mac/scoped_cftyperef.h"
#include "content/common/mac/font_loader.h" #include "content/common/mac/font_loader.h"
#endif #endif
...@@ -55,6 +58,10 @@ class SharedMemory; ...@@ -55,6 +58,10 @@ class SharedMemory;
class TaskRunner; class TaskRunner;
} }
namespace gfx {
struct GpuMemoryBufferHandle;
}
namespace media { namespace media {
class AudioManager; class AudioManager;
struct MediaLogEvent; struct MediaLogEvent;
...@@ -281,6 +288,16 @@ class RenderMessageFilter : public BrowserMessageFilter { ...@@ -281,6 +288,16 @@ class RenderMessageFilter : public BrowserMessageFilter {
const std::string& selector, const std::string& selector,
const std::string& markup); 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 // 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 // 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. // by the BrowserProcess, which has a wider scope than we do.
...@@ -319,6 +336,10 @@ class RenderMessageFilter : public BrowserMessageFilter { ...@@ -319,6 +336,10 @@ class RenderMessageFilter : public BrowserMessageFilter {
media::AudioManager* audio_manager_; media::AudioManager* audio_manager_;
MediaInternals* media_internals_; MediaInternals* media_internals_;
#if defined(OS_MACOSX)
base::ScopedCFTypeRef<IOSurfaceRef> last_io_surface_;
#endif
DISALLOW_COPY_AND_ASSIGN(RenderMessageFilter); DISALLOW_COPY_AND_ASSIGN(RenderMessageFilter);
}; };
......
...@@ -26,7 +26,6 @@ ...@@ -26,7 +26,6 @@
#include "base/logging.h" #include "base/logging.h"
#include "base/metrics/field_trial.h" #include "base/metrics/field_trial.h"
#include "base/metrics/histogram.h" #include "base/metrics/histogram.h"
#include "base/numerics/safe_math.h"
#include "base/path_service.h" #include "base/path_service.h"
#include "base/process/process_handle.h" #include "base/process/process_handle.h"
#include "base/rand_util.h" #include "base/rand_util.h"
...@@ -109,7 +108,6 @@ ...@@ -109,7 +108,6 @@
#include "content/common/child_process_host_impl.h" #include "content/common/child_process_host_impl.h"
#include "content/common/child_process_messages.h" #include "content/common/child_process_messages.h"
#include "content/common/content_switches_internal.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/gpu/gpu_messages.h"
#include "content/common/mojo/mojo_messages.h" #include "content/common/mojo/mojo_messages.h"
#include "content/common/resource_messages.h" #include "content/common/resource_messages.h"
...@@ -151,13 +149,7 @@ ...@@ -151,13 +149,7 @@
#if defined(OS_ANDROID) #if defined(OS_ANDROID)
#include "content/browser/media/android/browser_demuxer_android.h" #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/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 #endif
#if defined(OS_WIN) #if defined(OS_WIN)
...@@ -340,23 +332,6 @@ class RendererSandboxedProcessLauncherDelegate ...@@ -340,23 +332,6 @@ class RendererSandboxedProcessLauncherDelegate
#endif // OS_POSIX #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"; const char kSessionStorageHolderKey[] = "kSessionStorageHolderKey";
class SessionStorageHolder : public base::SupportsUserData::Data { class SessionStorageHolder : public base::SupportsUserData::Data {
...@@ -559,10 +534,6 @@ RenderProcessHostImpl::~RenderProcessHostImpl() { ...@@ -559,10 +534,6 @@ RenderProcessHostImpl::~RenderProcessHostImpl() {
BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
base::Bind(&RemoveShaderInfo, GetID())); base::Bind(&RemoveShaderInfo, GetID()));
} }
#if defined(OS_ANDROID)
CompositorImpl::DestroyAllSurfaceTextures(GetID());
#endif
} }
void RenderProcessHostImpl::EnableSendQueue() { void RenderProcessHostImpl::EnableSendQueue() {
...@@ -1388,11 +1359,6 @@ bool RenderProcessHostImpl::OnMessageReceived(const IPC::Message& msg) { ...@@ -1388,11 +1359,6 @@ bool RenderProcessHostImpl::OnMessageReceived(const IPC::Message& msg) {
IPC_MESSAGE_HANDLER(ViewHostMsg_UserMetricsRecordAction, IPC_MESSAGE_HANDLER(ViewHostMsg_UserMetricsRecordAction,
OnUserMetricsRecordAction) OnUserMetricsRecordAction)
IPC_MESSAGE_HANDLER(ViewHostMsg_SavedPageAsMHTML, OnSavedPageAsMHTML) 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) IPC_MESSAGE_HANDLER(ViewHostMsg_Close_ACK, OnCloseACK)
#if defined(ENABLE_WEBRTC) #if defined(ENABLE_WEBRTC)
IPC_MESSAGE_HANDLER(AecDumpMsg_RegisterAecDumpConsumer, IPC_MESSAGE_HANDLER(AecDumpMsg_RegisterAecDumpConsumer,
...@@ -2265,113 +2231,4 @@ void RenderProcessHostImpl::EnsureMojoActivated() { ...@@ -2265,113 +2231,4 @@ void RenderProcessHostImpl::EnsureMojoActivated() {
MaybeActivateMojo(); 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 } // namespace content
...@@ -25,11 +25,6 @@ ...@@ -25,11 +25,6 @@
#include "mojo/public/cpp/bindings/interface_ptr.h" #include "mojo/public/cpp/bindings/interface_ptr.h"
#include "ui/gfx/gpu_memory_buffer.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 { namespace base {
class CommandLine; class CommandLine;
class MessageLoop; class MessageLoop;
...@@ -37,7 +32,6 @@ class MessageLoop; ...@@ -37,7 +32,6 @@ class MessageLoop;
namespace gfx { namespace gfx {
class Size; class Size;
struct GpuMemoryBufferHandle;
} }
namespace content { namespace content {
...@@ -325,17 +319,6 @@ class CONTENT_EXPORT RenderProcessHostImpl ...@@ -325,17 +319,6 @@ class CONTENT_EXPORT RenderProcessHostImpl
void SendDisableAecDumpToRenderer(); void SendDisableAecDumpToRenderer();
#endif #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_; scoped_ptr<MojoApplicationHost> mojo_application_host_;
bool mojo_activation_required_; bool mojo_activation_required_;
...@@ -455,10 +438,6 @@ class CONTENT_EXPORT RenderProcessHostImpl ...@@ -455,10 +438,6 @@ class CONTENT_EXPORT RenderProcessHostImpl
base::WeakPtrFactory<RenderProcessHostImpl> weak_factory_; base::WeakPtrFactory<RenderProcessHostImpl> weak_factory_;
#if defined(OS_MACOSX)
base::ScopedCFTypeRef<IOSurfaceRef> last_io_surface_;
#endif
DISALLOW_COPY_AND_ASSIGN(RenderProcessHostImpl); 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