#include "base/sequence_checker.h"
#include "base/synchronization/condition_variable.h"
#include "base/threading/thread.h"
+#include "gpu/command_buffer/client/gpu_memory_buffer_factory.h"
#include "gpu/command_buffer/service/command_buffer_service.h"
#include "gpu/command_buffer/service/context_group.h"
#include "gpu/command_buffer/service/gl_context_virtual.h"
virtual void ScheduleTask(const base::Closure& task) OVERRIDE;
virtual void ScheduleIdleWork(const base::Closure& callback) OVERRIDE;
virtual bool UseVirtualizedGLContexts() OVERRIDE { return false; }
+ virtual scoped_refptr<gles2::ShaderTranslatorCache> shader_translator_cache()
+ OVERRIDE;
private:
virtual ~GpuInProcessThread();
friend class base::RefCountedThreadSafe<GpuInProcessThread>;
+ scoped_refptr<gpu::gles2::ShaderTranslatorCache> shader_translator_cache_;
DISALLOW_COPY_AND_ASSIGN(GpuInProcessThread);
};
FROM_HERE, callback, base::TimeDelta::FromMilliseconds(5));
}
+scoped_refptr<gles2::ShaderTranslatorCache>
+GpuInProcessThread::shader_translator_cache() {
+ if (!shader_translator_cache_.get())
+ shader_translator_cache_ = new gpu::gles2::ShaderTranslatorCache;
+ return shader_translator_cache_;
+}
+
base::LazyInstance<std::set<InProcessCommandBuffer*> > default_thread_clients_ =
LAZY_INSTANCE_INITIALIZER;
base::LazyInstance<base::Lock> default_thread_clients_lock_ =
base::Bind(&RunTaskWithResult<bool>, init_task, &result, &completion));
completion.Wait();
- if (result)
+ if (result) {
capabilities_ = capabilities;
+ capabilities_.map_image =
+ capabilities_.map_image && g_gpu_memory_buffer_factory;
+ }
return result;
}
bool bind_generates_resource = false;
decoder_.reset(gles2::GLES2Decoder::Create(
- params.context_group ? params.context_group->decoder_->GetContextGroup()
- : new gles2::ContextGroup(NULL,
- NULL,
- NULL,
- NULL,
- bind_generates_resource)));
+ params.context_group
+ ? params.context_group->decoder_->GetContextGroup()
+ : new gles2::ContextGroup(NULL,
+ NULL,
+ NULL,
+ service_->shader_translator_cache(),
+ NULL,
+ bind_generates_resource)));
gpu_scheduler_.reset(
new GpuScheduler(command_buffer.get(), decoder_.get(), decoder_.get()));
DestroyOnGpuThread();
return false;
}
+ *params.capabilities = decoder_->GetCapabilities();
gpu_control_.reset(
new GpuControlService(decoder_->GetContextGroup()->image_manager(),
- g_gpu_memory_buffer_factory,
- decoder_->GetContextGroup()->mailbox_manager(),
- decoder_->GetQueryManager(),
- decoder_->GetCapabilities()));
-
- *params.capabilities = gpu_control_->GetCapabilities();
+ decoder_->GetQueryManager()));
if (!params.is_offscreen) {
decoder_->SetResizeCallback(base::Bind(
return last_state_;
}
-CommandBuffer::State InProcessCommandBuffer::GetState() {
- CheckSequencedThread();
- return GetStateFast();
-}
-
CommandBuffer::State InProcessCommandBuffer::GetLastState() {
CheckSequencedThread();
return last_state_;
{
// Update state before signaling the flush event.
base::AutoLock lock(state_after_last_flush_lock_);
- state_after_last_flush_ = command_buffer_->GetState();
+ state_after_last_flush_ = command_buffer_->GetLastState();
}
DCHECK((!error::IsError(state_after_last_flush_.error) && !context_lost_) ||
(error::IsError(state_after_last_flush_.error) && context_lost_));
}
{
base::AutoLock lock(state_after_last_flush_lock_);
- state_after_last_flush_ = command_buffer_->GetState();
+ state_after_last_flush_ = command_buffer_->GetLastState();
}
}
void InProcessCommandBuffer::DestroyTransferBuffer(int32 id) {
CheckSequencedThread();
- base::Closure task = base::Bind(&CommandBuffer::DestroyTransferBuffer,
- base::Unretained(command_buffer_.get()),
- id);
+ base::Closure task =
+ base::Bind(&InProcessCommandBuffer::DestroyTransferBufferOnGputhread,
+ base::Unretained(this),
+ id);
QueueTask(task);
}
-scoped_refptr<gpu::Buffer> InProcessCommandBuffer::GetTransferBuffer(int32 id) {
- NOTREACHED();
- return NULL;
+void InProcessCommandBuffer::DestroyTransferBufferOnGputhread(int32 id) {
+ base::AutoLock lock(command_buffer_lock_);
+ command_buffer_->DestroyTransferBuffer(id);
}
gpu::Capabilities InProcessCommandBuffer::GetCapabilities() {
size_t width,
size_t height,
unsigned internalformat,
+ unsigned usage,
int32* id) {
CheckSequencedThread();
- base::AutoLock lock(command_buffer_lock_);
- return gpu_control_->CreateGpuMemoryBuffer(width,
- height,
- internalformat,
- id);
+
+ *id = -1;
+ linked_ptr<gfx::GpuMemoryBuffer> buffer =
+ make_linked_ptr(g_gpu_memory_buffer_factory->CreateGpuMemoryBuffer(
+ width, height, internalformat, usage));
+ if (!buffer.get())
+ return NULL;
+
+ static int32 next_id = 1;
+ *id = next_id++;
+
+ base::Closure task = base::Bind(&GpuControlService::RegisterGpuMemoryBuffer,
+ base::Unretained(gpu_control_.get()),
+ *id,
+ buffer->GetHandle(),
+ width,
+ height,
+ internalformat);
+
+ QueueTask(task);
+
+ gpu_memory_buffers_[*id] = buffer;
+ return buffer.get();
}
void InProcessCommandBuffer::DestroyGpuMemoryBuffer(int32 id) {
CheckSequencedThread();
- base::Closure task = base::Bind(&GpuControl::DestroyGpuMemoryBuffer,
+ GpuMemoryBufferMap::iterator it = gpu_memory_buffers_.find(id);
+ if (it != gpu_memory_buffers_.end())
+ gpu_memory_buffers_.erase(it);
+ base::Closure task = base::Bind(&GpuControlService::UnregisterGpuMemoryBuffer,
base::Unretained(gpu_control_.get()),
id);
void InProcessCommandBuffer::SignalQuery(unsigned query,
const base::Closure& callback) {
CheckSequencedThread();
- QueueTask(base::Bind(&GpuControl::SignalQuery,
+ QueueTask(base::Bind(&GpuControlService::SignalQuery,
base::Unretained(gpu_control_.get()),
query,
WrapCallback(callback)));
return false;
}
-void InProcessCommandBuffer::SetGetOffset(int32 get_offset) { NOTREACHED(); }
-
-void InProcessCommandBuffer::SetToken(int32 token) { NOTREACHED(); }
-
-void InProcessCommandBuffer::SetParseError(gpu::error::Error error) {
- NOTREACHED();
-}
-
-void InProcessCommandBuffer::SetContextLostReason(
- gpu::error::ContextLostReason reason) {
- NOTREACHED();
-}
-
namespace {
void PostCallback(const scoped_refptr<base::MessageLoopProxy>& loop,