#include "content/common/gpu/client/gpu_memory_buffer_impl.h"
#include "content/common/gpu/gpu_messages.h"
#include "content/public/browser/browser_thread.h"
+#include "content/public/browser/gpu_data_manager.h"
#include "content/public/common/content_client.h"
#include "ipc/ipc_forwarding_message_filter.h"
+#include "ipc/message_filter.h"
namespace content {
host = GpuProcessHost::Get(GpuProcessHost::GPU_PROCESS_KIND_SANDBOXED,
cause_for_gpu_launch_);
if (!host) {
+ LOG(ERROR) << "Failed to launch GPU process.";
FinishOnIO();
return;
}
// failure in ChannelEstablishedOnIO, but we ended up with the same
// process ID, meaning the failure was not because of a channel error,
// but another reason. So fail now.
+ LOG(ERROR) << "Failed to create channel.";
FinishOnIO();
return;
}
if (channel_handle.name.empty() && reused_gpu_process_) {
// We failed after re-using the GPU process, but it may have died in the
// mean time. Retry to have a chance to create a fresh GPU process.
+ DVLOG(1) << "Failed to create channel on existing GPU process. Trying to "
+ "restart GPU process.";
EstablishOnIO();
} else {
channel_handle_ = channel_handle;
finished_ = true;
}
+bool BrowserGpuChannelHostFactory::CanUseForTesting() {
+ return GpuDataManager::GetInstance()->GpuAccessAllowed(NULL);
+}
+
void BrowserGpuChannelHostFactory::Initialize(bool establish_gpu_channel) {
DCHECK(!instance_);
instance_ = new BrowserGpuChannelHostFactory(establish_gpu_channel);
return BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO);
}
-base::WaitableEvent* BrowserGpuChannelHostFactory::GetShutDownEvent() {
- return shutdown_event_.get();
-}
-
scoped_ptr<base::SharedMemory>
BrowserGpuChannelHostFactory::AllocateSharedMemory(size_t size) {
scoped_ptr<base::SharedMemory> shm(new base::SharedMemory());
surface_id,
gpu_client_id_,
init_params,
+ request->route_id,
base::Bind(&BrowserGpuChannelHostFactory::CommandBufferCreatedOnIO,
request));
}
// static
void BrowserGpuChannelHostFactory::CommandBufferCreatedOnIO(
- CreateRequest* request, int32 route_id) {
- request->route_id = route_id;
+ CreateRequest* request, bool succeeded) {
+ request->succeeded = succeeded;
request->event.Signal();
}
-int32 BrowserGpuChannelHostFactory::CreateViewCommandBuffer(
+bool BrowserGpuChannelHostFactory::CreateViewCommandBuffer(
int32 surface_id,
- const GPUCreateCommandBufferConfig& init_params) {
+ const GPUCreateCommandBufferConfig& init_params,
+ int32 route_id) {
CreateRequest request;
+ request.route_id = route_id;
GetIOLoopProxy()->PostTask(FROM_HERE, base::Bind(
&BrowserGpuChannelHostFactory::CreateViewCommandBufferOnIO,
base::Unretained(this),
"BrowserGpuChannelHostFactory::CreateViewCommandBuffer");
base::ThreadRestrictions::ScopedAllowWait allow_wait;
request.event.Wait();
- return request.route_id;
+ return request.succeeded;
}
void BrowserGpuChannelHostFactory::CreateImageOnIO(
GetContentClient()->SetGpuInfo(pending_request_->gpu_info());
gpu_channel_ = GpuChannelHost::Create(this,
- pending_request_->gpu_host_id(),
- gpu_client_id_,
pending_request_->gpu_info(),
- pending_request_->channel_handle());
+ pending_request_->channel_handle(),
+ shutdown_event_.get());
gpu_host_id_ = pending_request_->gpu_host_id();
pending_request_ = NULL;
}
scoped_ptr<gfx::GpuMemoryBuffer>
- BrowserGpuChannelHostFactory::AllocateGpuMemoryBuffer(
- size_t width,
- size_t height,
- unsigned internalformat) {
- if (!GpuMemoryBufferImpl::IsFormatValid(internalformat))
- return scoped_ptr<gfx::GpuMemoryBuffer>();
-
- size_t size = width * height *
- GpuMemoryBufferImpl::BytesPerPixel(internalformat);
- scoped_ptr<base::SharedMemory> shm(new base::SharedMemory());
- if (!shm->CreateAnonymous(size))
+BrowserGpuChannelHostFactory::AllocateGpuMemoryBuffer(size_t width,
+ size_t height,
+ unsigned internalformat,
+ unsigned usage) {
+ if (!GpuMemoryBufferImpl::IsFormatValid(internalformat) ||
+ !GpuMemoryBufferImpl::IsUsageValid(usage))
return scoped_ptr<gfx::GpuMemoryBuffer>();
- return make_scoped_ptr<gfx::GpuMemoryBuffer>(
- new GpuMemoryBufferImpl(shm.Pass(),
- width,
- height,
- internalformat));
+ return GpuMemoryBufferImpl::Create(gfx::Size(width, height),
+ internalformat,
+ usage).PassAs<gfx::GpuMemoryBuffer>();
}
// static
void BrowserGpuChannelHostFactory::AddFilterOnIO(
int host_id,
- scoped_refptr<IPC::ChannelProxy::MessageFilter> filter) {
+ scoped_refptr<IPC::MessageFilter> filter) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
GpuProcessHost* host = GpuProcessHost::FromID(host_id);