diff options
author | backer@chromium.org <backer@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-06-04 19:30:07 +0000 |
---|---|---|
committer | backer@chromium.org <backer@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-06-04 19:30:07 +0000 |
commit | 498b5c0709e16a9bfc5ac1007196674140e29e03 (patch) | |
tree | f1290b00aceb636702288abebe5b832884df4e1b /gpu | |
parent | 29c003e0201f2da153af7964e13ad85d49dc31de (diff) | |
download | chromium_src-498b5c0709e16a9bfc5ac1007196674140e29e03.zip chromium_src-498b5c0709e16a9bfc5ac1007196674140e29e03.tar.gz chromium_src-498b5c0709e16a9bfc5ac1007196674140e29e03.tar.bz2 |
GPU: Factory produces APTManagers instead of APTDelegates
First step of a larger refactor to push some of the logic from the
AsyncPixelTransferDelegate to the AsyncPixelTransferManager. This
CL moves a lot of files (async_pixel_transfer_delegate_* -->
async_pixel_transfer_manager_*) and introduces some Manager wrappers.
There is no functional change.
BUG=240504
Review URL: https://chromiumcodereview.appspot.com/16325018
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@204017 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'gpu')
30 files changed, 611 insertions, 423 deletions
diff --git a/gpu/command_buffer/service/async_pixel_transfer_delegate.h b/gpu/command_buffer/service/async_pixel_transfer_delegate.h index f90e2af..c8e9ded 100644 --- a/gpu/command_buffer/service/async_pixel_transfer_delegate.h +++ b/gpu/command_buffer/service/async_pixel_transfer_delegate.h @@ -96,8 +96,6 @@ class GPU_EXPORT AsyncPixelTransferDelegate { public: typedef base::Callback<void(const AsyncMemoryParams&)> CompletionCallback; - static AsyncPixelTransferDelegate* Create(gfx::GLContext* context); - virtual ~AsyncPixelTransferDelegate(); virtual AsyncPixelTransferState* CreatePixelTransferState( diff --git a/gpu/command_buffer/service/async_pixel_transfer_delegate_egl.h b/gpu/command_buffer/service/async_pixel_transfer_delegate_egl.h deleted file mode 100644 index 67cd971..0000000 --- a/gpu/command_buffer/service/async_pixel_transfer_delegate_egl.h +++ /dev/null @@ -1,77 +0,0 @@ -// Copyright (c) 2013 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef GPU_COMMAND_BUFFER_SERVICE_ASYNC_PIXEL_TRANSFER_DELEGATE_EGL_H_ -#define GPU_COMMAND_BUFFER_SERVICE_ASYNC_PIXEL_TRANSFER_DELEGATE_EGL_H_ - -#include <list> - -#include "gpu/command_buffer/service/async_pixel_transfer_delegate.h" - -namespace gpu { -class ScopedSafeSharedMemory; - -// Class which handles async pixel transfers using EGLImageKHR and another -// upload thread -class AsyncPixelTransferDelegateEGL - : public AsyncPixelTransferDelegate, - public base::SupportsWeakPtr<AsyncPixelTransferDelegateEGL> { - public: - AsyncPixelTransferDelegateEGL(); - virtual ~AsyncPixelTransferDelegateEGL(); - - // Implement AsyncPixelTransferDelegate: - virtual AsyncPixelTransferState* CreatePixelTransferState( - GLuint texture_id, - const AsyncTexImage2DParams& define_params) OVERRIDE; - virtual void BindCompletedAsyncTransfers() OVERRIDE; - virtual void AsyncNotifyCompletion( - const AsyncMemoryParams& mem_params, - const CompletionCallback& callback) OVERRIDE; - virtual void AsyncTexImage2D( - AsyncPixelTransferState* state, - const AsyncTexImage2DParams& tex_params, - const AsyncMemoryParams& mem_params, - const base::Closure& bind_callback) OVERRIDE; - virtual void AsyncTexSubImage2D( - AsyncPixelTransferState* state, - const AsyncTexSubImage2DParams& tex_params, - const AsyncMemoryParams& mem_params) OVERRIDE; - virtual void WaitForTransferCompletion( - AsyncPixelTransferState* state) OVERRIDE; - virtual uint32 GetTextureUploadCount() OVERRIDE; - virtual base::TimeDelta GetTotalTextureUploadTime() OVERRIDE; - virtual void ProcessMorePendingTransfers() OVERRIDE; - virtual bool NeedsProcessMorePendingTransfers() OVERRIDE; - - private: - static void PerformNotifyCompletion( - AsyncMemoryParams mem_params, - ScopedSafeSharedMemory* safe_shared_memory, - const CompletionCallback& callback); - - // Returns true if a work-around was used. - bool WorkAroundAsyncTexImage2D( - AsyncPixelTransferState* state, - const AsyncTexImage2DParams& tex_params, - const AsyncMemoryParams& mem_params, - const base::Closure& bind_callback); - bool WorkAroundAsyncTexSubImage2D( - AsyncPixelTransferState* state, - const AsyncTexSubImage2DParams& tex_params, - const AsyncMemoryParams& mem_params); - - typedef std::list<base::WeakPtr<AsyncPixelTransferState> > TransferQueue; - TransferQueue pending_allocations_; - - scoped_refptr<AsyncPixelTransferUploadStats> texture_upload_stats_; - bool is_imagination_; - bool is_qualcomm_; - - DISALLOW_COPY_AND_ASSIGN(AsyncPixelTransferDelegateEGL); -}; - -} // namespace gpu - -#endif // GPU_COMMAND_BUFFER_SERVICE_ASYNC_PIXEL_TRANSFER_DELEGATE_EGL_H_ diff --git a/gpu/command_buffer/service/async_pixel_transfer_delegate_idle.h b/gpu/command_buffer/service/async_pixel_transfer_delegate_idle.h deleted file mode 100644 index 4e62cde..0000000 --- a/gpu/command_buffer/service/async_pixel_transfer_delegate_idle.h +++ /dev/null @@ -1,86 +0,0 @@ -// Copyright (c) 2013 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef GPU_COMMAND_BUFFER_SERVICE_ASYNC_PIXEL_TRANSFER_DELEGATE_IDLE_H_ -#define GPU_COMMAND_BUFFER_SERVICE_ASYNC_PIXEL_TRANSFER_DELEGATE_IDLE_H_ - -#include <list> - -#include "gpu/command_buffer/service/async_pixel_transfer_delegate.h" - -namespace gpu { -class ScopedSafeSharedMemory; - -// Class which handles async pixel transfers in a platform -// independent way. -class AsyncPixelTransferDelegateIdle : public AsyncPixelTransferDelegate, - public base::SupportsWeakPtr<AsyncPixelTransferDelegateIdle> { - public: - AsyncPixelTransferDelegateIdle(); - virtual ~AsyncPixelTransferDelegateIdle(); - - // implement AsyncPixelTransferDelegate: - virtual AsyncPixelTransferState* CreatePixelTransferState( - GLuint texture_id, - const AsyncTexImage2DParams& define_params) OVERRIDE; - virtual void BindCompletedAsyncTransfers() OVERRIDE; - virtual void AsyncNotifyCompletion( - const AsyncMemoryParams& mem_params, - const CompletionCallback& callback) OVERRIDE; - virtual void AsyncTexImage2D( - AsyncPixelTransferState* transfer_state, - const AsyncTexImage2DParams& tex_params, - const AsyncMemoryParams& mem_params, - const base::Closure& bind_callback) OVERRIDE; - virtual void AsyncTexSubImage2D( - AsyncPixelTransferState* transfer_state, - const AsyncTexSubImage2DParams& tex_params, - const AsyncMemoryParams& mem_params) OVERRIDE; - virtual void WaitForTransferCompletion( - AsyncPixelTransferState* transfer_state) OVERRIDE; - virtual uint32 GetTextureUploadCount() OVERRIDE; - virtual base::TimeDelta GetTotalTextureUploadTime() OVERRIDE; - virtual void ProcessMorePendingTransfers() OVERRIDE; - virtual bool NeedsProcessMorePendingTransfers() OVERRIDE; - - private: - struct Task { - Task(uint64 transfer_id, const base::Closure& task); - ~Task(); - - // This is non-zero if pixel transfer task. - uint64 transfer_id; - - base::Closure task; - }; - - void ProcessNotificationTasks(); - - void PerformNotifyCompletion( - AsyncMemoryParams mem_params, - ScopedSafeSharedMemory* safe_shared_memory, - const CompletionCallback& callback); - void PerformAsyncTexImage2D( - AsyncTexImage2DParams tex_params, - AsyncMemoryParams mem_params, - const base::Closure& bind_callback, - ScopedSafeSharedMemory* safe_shared_memory, - GLuint texture_id); - void PerformAsyncTexSubImage2D( - AsyncTexSubImage2DParams tex_params, - AsyncMemoryParams mem_params, - ScopedSafeSharedMemory* safe_shared_memory, - GLuint texture_id); - - int texture_upload_count_; - base::TimeDelta total_texture_upload_time_; - - std::list<Task> tasks_; - - DISALLOW_COPY_AND_ASSIGN(AsyncPixelTransferDelegateIdle); -}; - -} // namespace gpu - -#endif // GPU_COMMAND_BUFFER_SERVICE_ASYNC_PIXEL_TRANSFER_DELEGATE_IDLE_H_ diff --git a/gpu/command_buffer/service/async_pixel_transfer_delegate_share_group.h b/gpu/command_buffer/service/async_pixel_transfer_delegate_share_group.h deleted file mode 100644 index f0887a9a..0000000 --- a/gpu/command_buffer/service/async_pixel_transfer_delegate_share_group.h +++ /dev/null @@ -1,58 +0,0 @@ -// Copyright (c) 2013 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef GPU_COMMAND_BUFFER_SERVICE_ASYNC_PIXEL_TRANSFER_DELEGATE_SHARE_GROUP_H_ -#define GPU_COMMAND_BUFFER_SERVICE_ASYNC_PIXEL_TRANSFER_DELEGATE_SHARE_GROUP_H_ - -#include "gpu/command_buffer/service/async_pixel_transfer_delegate.h" - -#include <list> - -#include "base/basictypes.h" -#include "base/memory/ref_counted.h" -#include "base/memory/weak_ptr.h" - -namespace gpu { - -class AsyncPixelTransferDelegateShareGroup : public AsyncPixelTransferDelegate { - public: - explicit AsyncPixelTransferDelegateShareGroup(gfx::GLContext* context); - virtual ~AsyncPixelTransferDelegateShareGroup(); - - // Implement AsyncPixelTransferDelegate: - virtual AsyncPixelTransferState* CreatePixelTransferState( - GLuint texture_id, - const AsyncTexImage2DParams& define_params) OVERRIDE; - virtual void BindCompletedAsyncTransfers() OVERRIDE; - virtual void AsyncNotifyCompletion( - const AsyncMemoryParams& mem_params, - const CompletionCallback& callback) OVERRIDE; - virtual void AsyncTexImage2D( - AsyncPixelTransferState* state, - const AsyncTexImage2DParams& tex_params, - const AsyncMemoryParams& mem_params, - const base::Closure& bind_callback) OVERRIDE; - virtual void AsyncTexSubImage2D( - AsyncPixelTransferState* state, - const AsyncTexSubImage2DParams& tex_params, - const AsyncMemoryParams& mem_params) OVERRIDE; - virtual void WaitForTransferCompletion( - AsyncPixelTransferState* state) OVERRIDE; - virtual uint32 GetTextureUploadCount() OVERRIDE; - virtual base::TimeDelta GetTotalTextureUploadTime() OVERRIDE; - virtual void ProcessMorePendingTransfers() OVERRIDE; - virtual bool NeedsProcessMorePendingTransfers() OVERRIDE; - - private: - typedef std::list<base::WeakPtr<AsyncPixelTransferState> > TransferQueue; - TransferQueue pending_allocations_; - - scoped_refptr<AsyncPixelTransferUploadStats> texture_upload_stats_; - - DISALLOW_COPY_AND_ASSIGN(AsyncPixelTransferDelegateShareGroup); -}; - -} // namespace gpu - -#endif // GPU_COMMAND_BUFFER_SERVICE_ASYNC_PIXEL_TRANSFER_DELEGATE_SHARE_GROUP_H_ diff --git a/gpu/command_buffer/service/async_pixel_transfer_delegate_stub.h b/gpu/command_buffer/service/async_pixel_transfer_delegate_stub.h deleted file mode 100644 index f2381990..0000000 --- a/gpu/command_buffer/service/async_pixel_transfer_delegate_stub.h +++ /dev/null @@ -1,47 +0,0 @@ -// Copyright (c) 2013 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef GPU_COMMAND_BUFFER_SERVICE_ASYNC_PIXEL_TRANSFER_DELEGATE_STUB_H_ -#define GPU_COMMAND_BUFFER_SERVICE_ASYNC_PIXEL_TRANSFER_DELEGATE_STUB_H_ - -#include "gpu/command_buffer/service/async_pixel_transfer_delegate.h" - -namespace gpu { - -class AsyncPixelTransferDelegateStub : public AsyncPixelTransferDelegate { - public: - AsyncPixelTransferDelegateStub(); - virtual ~AsyncPixelTransferDelegateStub(); - - // Implement AsyncPixelTransferDelegate: - virtual AsyncPixelTransferState* CreatePixelTransferState( - GLuint texture_id, - const AsyncTexImage2DParams& define_params) OVERRIDE; - virtual void BindCompletedAsyncTransfers() OVERRIDE; - virtual void AsyncNotifyCompletion( - const AsyncMemoryParams& mem_params, - const CompletionCallback& callback) OVERRIDE; - virtual void AsyncTexImage2D( - AsyncPixelTransferState* state, - const AsyncTexImage2DParams& tex_params, - const AsyncMemoryParams& mem_params, - const base::Closure& bind_callback) OVERRIDE; - virtual void AsyncTexSubImage2D( - AsyncPixelTransferState* transfer_state, - const AsyncTexSubImage2DParams& tex_params, - const AsyncMemoryParams& mem_params) OVERRIDE; - virtual void WaitForTransferCompletion( - AsyncPixelTransferState* state) OVERRIDE; - virtual uint32 GetTextureUploadCount() OVERRIDE; - virtual base::TimeDelta GetTotalTextureUploadTime() OVERRIDE; - virtual void ProcessMorePendingTransfers() OVERRIDE; - virtual bool NeedsProcessMorePendingTransfers() OVERRIDE; - - private: - DISALLOW_COPY_AND_ASSIGN(AsyncPixelTransferDelegateStub); -}; - -} // namespace gpu - -#endif // GPU_COMMAND_BUFFER_SERVICE_ASYNC_PIXEL_TRANSFER_DELEGATE_STUB_H_ diff --git a/gpu/command_buffer/service/async_pixel_transfer_delegate_sync.h b/gpu/command_buffer/service/async_pixel_transfer_delegate_sync.h deleted file mode 100644 index 5927094..0000000 --- a/gpu/command_buffer/service/async_pixel_transfer_delegate_sync.h +++ /dev/null @@ -1,51 +0,0 @@ -// Copyright (c) 2013 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef GPU_COMMAND_BUFFER_SERVICE_ASYNC_PIXEL_TRANSFER_DELEGATE_SYNC_H_ -#define GPU_COMMAND_BUFFER_SERVICE_ASYNC_PIXEL_TRANSFER_DELEGATE_SYNC_H_ - -#include "gpu/command_buffer/service/async_pixel_transfer_delegate.h" - -namespace gpu { - -// Class which handles async pixel transfers synchronously. -class AsyncPixelTransferDelegateSync : public AsyncPixelTransferDelegate { - public: - AsyncPixelTransferDelegateSync(); - virtual ~AsyncPixelTransferDelegateSync(); - - // Implement AsyncPixelTransferDelegate: - virtual AsyncPixelTransferState* CreatePixelTransferState( - GLuint texture_id, - const AsyncTexImage2DParams& define_params) OVERRIDE; - virtual void BindCompletedAsyncTransfers() OVERRIDE; - virtual void AsyncNotifyCompletion( - const AsyncMemoryParams& mem_params, - const CompletionCallback& callback) OVERRIDE; - virtual void AsyncTexImage2D( - AsyncPixelTransferState* state, - const AsyncTexImage2DParams& tex_params, - const AsyncMemoryParams& mem_params, - const base::Closure& bind_callback) OVERRIDE; - virtual void AsyncTexSubImage2D( - AsyncPixelTransferState* transfer_state, - const AsyncTexSubImage2DParams& tex_params, - const AsyncMemoryParams& mem_params) OVERRIDE; - virtual void WaitForTransferCompletion( - AsyncPixelTransferState* state) OVERRIDE; - virtual uint32 GetTextureUploadCount() OVERRIDE; - virtual base::TimeDelta GetTotalTextureUploadTime() OVERRIDE; - virtual void ProcessMorePendingTransfers() OVERRIDE; - virtual bool NeedsProcessMorePendingTransfers() OVERRIDE; - - private: - int texture_upload_count_; - base::TimeDelta total_texture_upload_time_; - - DISALLOW_COPY_AND_ASSIGN(AsyncPixelTransferDelegateSync); -}; - -} // namespace gpu - -#endif // GPU_COMMAND_BUFFER_SERVICE_ASYNC_PIXEL_TRANSFER_DELEGATE_SYNC_H_ diff --git a/gpu/command_buffer/service/async_pixel_transfer_manager.cc b/gpu/command_buffer/service/async_pixel_transfer_manager.cc index 92ecfd6..6b4ad91 100644 --- a/gpu/command_buffer/service/async_pixel_transfer_manager.cc +++ b/gpu/command_buffer/service/async_pixel_transfer_manager.cc @@ -8,25 +8,25 @@ namespace gpu { -AsyncPixelTransferManager::AsyncPixelTransferManager( - gles2::TextureManager* manager, - gfx::GLContext* context) - : manager_(manager), - delegate_(AsyncPixelTransferDelegate::Create(context)) { - manager_->AddObserver(this); -} +AsyncPixelTransferManager::AsyncPixelTransferManager() {} AsyncPixelTransferManager::~AsyncPixelTransferManager() { if (manager_) manager_->RemoveObserver(this); } +void AsyncPixelTransferManager::Initialize(gles2::TextureManager* manager) { + manager_ = manager; + manager_->AddObserver(this); +} + AsyncPixelTransferState* AsyncPixelTransferManager::CreatePixelTransferState( gles2::TextureRef* ref, const AsyncTexImage2DParams& define_params) { DCHECK(!GetPixelTransferState(ref)); - AsyncPixelTransferState* state = delegate_->CreatePixelTransferState( - ref->texture()->service_id(), define_params); + AsyncPixelTransferState* state = + GetAsyncPixelTransferDelegate()->CreatePixelTransferState( + ref->texture()->service_id(), define_params); state_map_[ref] = state; return state; } diff --git a/gpu/command_buffer/service/async_pixel_transfer_manager.h b/gpu/command_buffer/service/async_pixel_transfer_manager.h index 2f61099..21f3980 100644 --- a/gpu/command_buffer/service/async_pixel_transfer_manager.h +++ b/gpu/command_buffer/service/async_pixel_transfer_manager.h @@ -36,18 +36,13 @@ struct AsyncTexImage2DParams; class GPU_EXPORT AsyncPixelTransferManager : public gles2::TextureManager::DestructionObserver { public: - AsyncPixelTransferManager(gles2::TextureManager* texture_manager_, - gfx::GLContext* context); + static AsyncPixelTransferManager* Create(gfx::GLContext* context); + virtual ~AsyncPixelTransferManager(); - AsyncPixelTransferDelegate* GetAsyncPixelTransferDelegate() { - return delegate_.get(); - } + void Initialize(gles2::TextureManager* texture_manager); - void SetAsyncPixelTransferDelegateForTest( - AsyncPixelTransferDelegate* delegate) { - delegate_ = make_scoped_ptr(delegate); - } + virtual AsyncPixelTransferDelegate* GetAsyncPixelTransferDelegate() = 0; AsyncPixelTransferState* CreatePixelTransferState( gles2::TextureRef* ref, @@ -65,11 +60,12 @@ class GPU_EXPORT AsyncPixelTransferManager OVERRIDE; virtual void OnTextureRefDestroying(gles2::TextureRef* texture) OVERRIDE; + protected: + AsyncPixelTransferManager(); + private: gles2::TextureManager* manager_; - scoped_ptr<AsyncPixelTransferDelegate> delegate_; - typedef base::hash_map<gles2::TextureRef*, scoped_refptr<AsyncPixelTransferState> > TextureToStateMap; diff --git a/gpu/command_buffer/service/async_pixel_transfer_delegate_android.cc b/gpu/command_buffer/service/async_pixel_transfer_manager_android.cc index fa29cf6..09f16b0 100644 --- a/gpu/command_buffer/service/async_pixel_transfer_delegate_android.cc +++ b/gpu/command_buffer/service/async_pixel_transfer_manager_android.cc @@ -1,13 +1,13 @@ -// Copyright (c) 2013 The Chromium Authors. All rights reserved. +// Copyright 2013 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "gpu/command_buffer/service/async_pixel_transfer_delegate.h" +#include "gpu/command_buffer/service/async_pixel_transfer_manager.h" #include "base/debug/trace_event.h" -#include "gpu/command_buffer/service/async_pixel_transfer_delegate_egl.h" -#include "gpu/command_buffer/service/async_pixel_transfer_delegate_stub.h" -#include "gpu/command_buffer/service/async_pixel_transfer_delegate_sync.h" +#include "gpu/command_buffer/service/async_pixel_transfer_manager_egl.h" +#include "gpu/command_buffer/service/async_pixel_transfer_manager_stub.h" +#include "gpu/command_buffer/service/async_pixel_transfer_manager_sync.h" #include "ui/gl/gl_context.h" #include "ui/gl/gl_implementation.h" @@ -27,9 +27,9 @@ bool IsBroadcom() { // - Create EGLImages out of OpenGL textures (EGL_KHR_gl_texture_2D_image) // - Bind EGLImages to OpenGL textures (GL_OES_EGL_image) // - Use fences (to test for upload completion). -AsyncPixelTransferDelegate* AsyncPixelTransferDelegate::Create( +AsyncPixelTransferManager* AsyncPixelTransferManager::Create( gfx::GLContext* context) { - TRACE_EVENT0("gpu", "AsyncPixelTransferDelegate::Create"); + TRACE_EVENT0("gpu", "AsyncPixelTransferManager::Create"); switch (gfx::GetGLImplementation()) { case gfx::kGLImplementationEGLGLES2: DCHECK(context); @@ -39,12 +39,12 @@ AsyncPixelTransferDelegate* AsyncPixelTransferDelegate::Create( context->HasExtension("EGL_KHR_gl_texture_2D_image") && context->HasExtension("GL_OES_EGL_image") && !IsBroadcom()) { - return new AsyncPixelTransferDelegateEGL; + return new AsyncPixelTransferManagerEGL; } LOG(INFO) << "Async pixel transfers not supported"; - return new AsyncPixelTransferDelegateSync; + return new AsyncPixelTransferManagerSync; case gfx::kGLImplementationMockGL: - return new AsyncPixelTransferDelegateStub; + return new AsyncPixelTransferManagerStub; default: NOTREACHED(); return NULL; diff --git a/gpu/command_buffer/service/async_pixel_transfer_delegate_egl.cc b/gpu/command_buffer/service/async_pixel_transfer_manager_egl.cc index b1d3f12..1a7b301 100644 --- a/gpu/command_buffer/service/async_pixel_transfer_delegate_egl.cc +++ b/gpu/command_buffer/service/async_pixel_transfer_manager_egl.cc @@ -1,9 +1,10 @@ -// Copyright (c) 2013 The Chromium Authors. All rights reserved. +// Copyright 2013 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "gpu/command_buffer/service/async_pixel_transfer_delegate_egl.h" +#include "gpu/command_buffer/service/async_pixel_transfer_manager_egl.h" +#include <list> #include <string> #include "base/bind.h" @@ -13,6 +14,7 @@ #include "base/memory/ref_counted.h" #include "base/synchronization/waitable_event.h" #include "base/threading/thread.h" +#include "gpu/command_buffer/service/async_pixel_transfer_delegate.h" #include "gpu/command_buffer/service/safe_shared_memory_pool.h" #include "ui/gl/gl_context.h" #include "ui/gl/gl_surface_egl.h" @@ -409,6 +411,66 @@ class AsyncTransferStateImpl : public AsyncPixelTransferState { } // namespace +// Class which handles async pixel transfers using EGLImageKHR and another +// upload thread +class AsyncPixelTransferDelegateEGL + : public AsyncPixelTransferDelegate, + public base::SupportsWeakPtr<AsyncPixelTransferDelegateEGL> { + public: + AsyncPixelTransferDelegateEGL(); + virtual ~AsyncPixelTransferDelegateEGL(); + + // Implement AsyncPixelTransferDelegate: + virtual AsyncPixelTransferState* CreatePixelTransferState( + GLuint texture_id, + const AsyncTexImage2DParams& define_params) OVERRIDE; + virtual void BindCompletedAsyncTransfers() OVERRIDE; + virtual void AsyncNotifyCompletion( + const AsyncMemoryParams& mem_params, + const CompletionCallback& callback) OVERRIDE; + virtual void AsyncTexImage2D( + AsyncPixelTransferState* state, + const AsyncTexImage2DParams& tex_params, + const AsyncMemoryParams& mem_params, + const base::Closure& bind_callback) OVERRIDE; + virtual void AsyncTexSubImage2D( + AsyncPixelTransferState* state, + const AsyncTexSubImage2DParams& tex_params, + const AsyncMemoryParams& mem_params) OVERRIDE; + virtual void WaitForTransferCompletion( + AsyncPixelTransferState* state) OVERRIDE; + virtual uint32 GetTextureUploadCount() OVERRIDE; + virtual base::TimeDelta GetTotalTextureUploadTime() OVERRIDE; + virtual void ProcessMorePendingTransfers() OVERRIDE; + virtual bool NeedsProcessMorePendingTransfers() OVERRIDE; + + private: + static void PerformNotifyCompletion( + AsyncMemoryParams mem_params, + ScopedSafeSharedMemory* safe_shared_memory, + const CompletionCallback& callback); + + // Returns true if a work-around was used. + bool WorkAroundAsyncTexImage2D( + AsyncPixelTransferState* state, + const AsyncTexImage2DParams& tex_params, + const AsyncMemoryParams& mem_params, + const base::Closure& bind_callback); + bool WorkAroundAsyncTexSubImage2D( + AsyncPixelTransferState* state, + const AsyncTexSubImage2DParams& tex_params, + const AsyncMemoryParams& mem_params); + + typedef std::list<base::WeakPtr<AsyncPixelTransferState> > TransferQueue; + TransferQueue pending_allocations_; + + scoped_refptr<AsyncPixelTransferUploadStats> texture_upload_stats_; + bool is_imagination_; + bool is_qualcomm_; + + DISALLOW_COPY_AND_ASSIGN(AsyncPixelTransferDelegateEGL); +}; + AsyncPixelTransferDelegateEGL::AsyncPixelTransferDelegateEGL() { std::string vendor; vendor = reinterpret_cast<const char*>(glGetString(GL_VENDOR)); @@ -747,4 +809,14 @@ bool AsyncPixelTransferDelegateEGL::WorkAroundAsyncTexSubImage2D( return true; } +AsyncPixelTransferManagerEGL::AsyncPixelTransferManagerEGL() + : delegate_(new AsyncPixelTransferDelegateEGL()) {} + +AsyncPixelTransferManagerEGL::~AsyncPixelTransferManagerEGL() {} + +AsyncPixelTransferDelegate* +AsyncPixelTransferManagerEGL::GetAsyncPixelTransferDelegate() { + return delegate_.get(); +} + } // namespace gpu diff --git a/gpu/command_buffer/service/async_pixel_transfer_manager_egl.h b/gpu/command_buffer/service/async_pixel_transfer_manager_egl.h new file mode 100644 index 0000000..c76ee90 --- /dev/null +++ b/gpu/command_buffer/service/async_pixel_transfer_manager_egl.h @@ -0,0 +1,30 @@ +// Copyright 2013 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef GPU_COMMAND_BUFFER_SERVICE_ASYNC_PIXEL_TRANSFER_MANAGER_EGL_H_ +#define GPU_COMMAND_BUFFER_SERVICE_ASYNC_PIXEL_TRANSFER_MANAGER_EGL_H_ + +#include "gpu/command_buffer/service/async_pixel_transfer_manager.h" + +namespace gpu { + +class AsyncPixelTransferDelegateEGL; + +class AsyncPixelTransferManagerEGL : public AsyncPixelTransferManager { + public: + AsyncPixelTransferManagerEGL(); + virtual ~AsyncPixelTransferManagerEGL(); + + // AsyncPixelTransferManager implementation: + virtual AsyncPixelTransferDelegate* GetAsyncPixelTransferDelegate() OVERRIDE; + + private: + scoped_ptr<AsyncPixelTransferDelegateEGL> delegate_; + + DISALLOW_COPY_AND_ASSIGN(AsyncPixelTransferManagerEGL); +}; + +} // namespace gpu + +#endif // GPU_COMMAND_BUFFER_SERVICE_ASYNC_PIXEL_TRANSFER_MANAGER_EGL_H_ diff --git a/gpu/command_buffer/service/async_pixel_transfer_delegate_idle.cc b/gpu/command_buffer/service/async_pixel_transfer_manager_idle.cc index d8bf916..66ff879 100644 --- a/gpu/command_buffer/service/async_pixel_transfer_delegate_idle.cc +++ b/gpu/command_buffer/service/async_pixel_transfer_manager_idle.cc @@ -1,8 +1,10 @@ -// Copyright (c) 2013 The Chromium Authors. All rights reserved. +// Copyright 2013 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "gpu/command_buffer/service/async_pixel_transfer_delegate_idle.h" +#include "gpu/command_buffer/service/async_pixel_transfer_manager_idle.h" + +#include <list> #include "base/bind.h" #include "base/debug/trace_event.h" @@ -61,6 +63,75 @@ class AsyncPixelTransferStateImpl : public AsyncPixelTransferState { } // namespace +// Class which handles async pixel transfers in a platform +// independent way. +class AsyncPixelTransferDelegateIdle : public AsyncPixelTransferDelegate, + public base::SupportsWeakPtr<AsyncPixelTransferDelegateIdle> { + public: + AsyncPixelTransferDelegateIdle(); + virtual ~AsyncPixelTransferDelegateIdle(); + + // implement AsyncPixelTransferDelegate: + virtual AsyncPixelTransferState* CreatePixelTransferState( + GLuint texture_id, + const AsyncTexImage2DParams& define_params) OVERRIDE; + virtual void BindCompletedAsyncTransfers() OVERRIDE; + virtual void AsyncNotifyCompletion( + const AsyncMemoryParams& mem_params, + const CompletionCallback& callback) OVERRIDE; + virtual void AsyncTexImage2D( + AsyncPixelTransferState* transfer_state, + const AsyncTexImage2DParams& tex_params, + const AsyncMemoryParams& mem_params, + const base::Closure& bind_callback) OVERRIDE; + virtual void AsyncTexSubImage2D( + AsyncPixelTransferState* transfer_state, + const AsyncTexSubImage2DParams& tex_params, + const AsyncMemoryParams& mem_params) OVERRIDE; + virtual void WaitForTransferCompletion( + AsyncPixelTransferState* transfer_state) OVERRIDE; + virtual uint32 GetTextureUploadCount() OVERRIDE; + virtual base::TimeDelta GetTotalTextureUploadTime() OVERRIDE; + virtual void ProcessMorePendingTransfers() OVERRIDE; + virtual bool NeedsProcessMorePendingTransfers() OVERRIDE; + + private: + struct Task { + Task(uint64 transfer_id, const base::Closure& task); + ~Task(); + + // This is non-zero if pixel transfer task. + uint64 transfer_id; + + base::Closure task; + }; + + void ProcessNotificationTasks(); + + void PerformNotifyCompletion( + AsyncMemoryParams mem_params, + ScopedSafeSharedMemory* safe_shared_memory, + const CompletionCallback& callback); + void PerformAsyncTexImage2D( + AsyncTexImage2DParams tex_params, + AsyncMemoryParams mem_params, + const base::Closure& bind_callback, + ScopedSafeSharedMemory* safe_shared_memory, + GLuint texture_id); + void PerformAsyncTexSubImage2D( + AsyncTexSubImage2DParams tex_params, + AsyncMemoryParams mem_params, + ScopedSafeSharedMemory* safe_shared_memory, + GLuint texture_id); + + int texture_upload_count_; + base::TimeDelta total_texture_upload_time_; + + std::list<Task> tasks_; + + DISALLOW_COPY_AND_ASSIGN(AsyncPixelTransferDelegateIdle); +}; + AsyncPixelTransferDelegateIdle::Task::Task( uint64 transfer_id, const base::Closure& task) : transfer_id(transfer_id), @@ -296,4 +367,14 @@ void AsyncPixelTransferDelegateIdle::PerformAsyncTexSubImage2D( total_texture_upload_time_ += base::TimeTicks::HighResNow() - begin_time; } +AsyncPixelTransferManagerIdle::AsyncPixelTransferManagerIdle() + : delegate_(new AsyncPixelTransferDelegateIdle()) {} + +AsyncPixelTransferManagerIdle::~AsyncPixelTransferManagerIdle() {} + +AsyncPixelTransferDelegate* +AsyncPixelTransferManagerIdle::GetAsyncPixelTransferDelegate() { + return delegate_.get(); +} + } // namespace gpu diff --git a/gpu/command_buffer/service/async_pixel_transfer_manager_idle.h b/gpu/command_buffer/service/async_pixel_transfer_manager_idle.h new file mode 100644 index 0000000..1821dca --- /dev/null +++ b/gpu/command_buffer/service/async_pixel_transfer_manager_idle.h @@ -0,0 +1,29 @@ +// Copyright 2013 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef GPU_COMMAND_BUFFER_SERVICE_ASYNC_PIXEL_TRANSFER_MANAGER_IDLE_H_ +#define GPU_COMMAND_BUFFER_SERVICE_ASYNC_PIXEL_TRANSFER_MANAGER_IDLE_H_ + +#include "gpu/command_buffer/service/async_pixel_transfer_manager.h" + +namespace gpu { +class AsyncPixelTransferDelegateIdle; + +class AsyncPixelTransferManagerIdle : public AsyncPixelTransferManager { + public: + AsyncPixelTransferManagerIdle(); + virtual ~AsyncPixelTransferManagerIdle(); + + // AsyncPixelTransferManager implementation: + virtual AsyncPixelTransferDelegate* GetAsyncPixelTransferDelegate() OVERRIDE; + + private: + scoped_ptr<AsyncPixelTransferDelegateIdle> delegate_; + + DISALLOW_COPY_AND_ASSIGN(AsyncPixelTransferManagerIdle); +}; + +} // namespace gpu + +#endif // GPU_COMMAND_BUFFER_SERVICE_ASYNC_PIXEL_TRANSFER_MANAGER_IDLE_H_ diff --git a/gpu/command_buffer/service/async_pixel_transfer_delegate_linux.cc b/gpu/command_buffer/service/async_pixel_transfer_manager_linux.cc index 470ac1d..8d25f00 100644 --- a/gpu/command_buffer/service/async_pixel_transfer_delegate_linux.cc +++ b/gpu/command_buffer/service/async_pixel_transfer_manager_linux.cc @@ -1,36 +1,36 @@ -// Copyright (c) 2013 The Chromium Authors. All rights reserved. +// Copyright 2013 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "gpu/command_buffer/service/async_pixel_transfer_delegate.h" +#include "gpu/command_buffer/service/async_pixel_transfer_manager.h" #include "base/command_line.h" #include "base/debug/trace_event.h" -#include "gpu/command_buffer/service/async_pixel_transfer_delegate_idle.h" -#include "gpu/command_buffer/service/async_pixel_transfer_delegate_share_group.h" -#include "gpu/command_buffer/service/async_pixel_transfer_delegate_stub.h" +#include "gpu/command_buffer/service/async_pixel_transfer_manager_idle.h" +#include "gpu/command_buffer/service/async_pixel_transfer_manager_share_group.h" +#include "gpu/command_buffer/service/async_pixel_transfer_manager_stub.h" #include "gpu/command_buffer/service/gpu_switches.h" #include "ui/gl/gl_implementation.h" namespace gpu { -AsyncPixelTransferDelegate* AsyncPixelTransferDelegate::Create( +AsyncPixelTransferManager* AsyncPixelTransferManager::Create( gfx::GLContext* context) { + TRACE_EVENT0("gpu", "AsyncPixelTransferManager::Create"); if (CommandLine::ForCurrentProcess()->HasSwitch( switches::kEnableShareGroupAsyncTextureUpload)) { DCHECK(context); - return static_cast<AsyncPixelTransferDelegate*> ( - new AsyncPixelTransferDelegateShareGroup(context)); + return static_cast<AsyncPixelTransferManager*> ( + new AsyncPixelTransferManagerShareGroup(context)); } - TRACE_EVENT0("gpu", "AsyncPixelTransferDelegate::Create"); switch (gfx::GetGLImplementation()) { case gfx::kGLImplementationOSMesaGL: case gfx::kGLImplementationDesktopGL: case gfx::kGLImplementationEGLGLES2: - return new AsyncPixelTransferDelegateIdle; + return new AsyncPixelTransferManagerIdle; case gfx::kGLImplementationMockGL: - return new AsyncPixelTransferDelegateStub; + return new AsyncPixelTransferManagerStub; default: NOTREACHED(); return NULL; diff --git a/gpu/command_buffer/service/async_pixel_transfer_delegate_mac.cc b/gpu/command_buffer/service/async_pixel_transfer_manager_mac.cc index 496359c..8c19b57 100644 --- a/gpu/command_buffer/service/async_pixel_transfer_delegate_mac.cc +++ b/gpu/command_buffer/service/async_pixel_transfer_manager_mac.cc @@ -1,26 +1,26 @@ -// Copyright (c) 2013 The Chromium Authors. All rights reserved. +// Copyright 2013 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "gpu/command_buffer/service/async_pixel_transfer_delegate.h" +#include "gpu/command_buffer/service/async_pixel_transfer_manager.h" #include "base/debug/trace_event.h" -#include "gpu/command_buffer/service/async_pixel_transfer_delegate_idle.h" -#include "gpu/command_buffer/service/async_pixel_transfer_delegate_stub.h" +#include "gpu/command_buffer/service/async_pixel_transfer_manager_idle.h" +#include "gpu/command_buffer/service/async_pixel_transfer_manager_stub.h" #include "ui/gl/gl_implementation.h" namespace gpu { -AsyncPixelTransferDelegate* AsyncPixelTransferDelegate::Create( +AsyncPixelTransferManager* AsyncPixelTransferManager::Create( gfx::GLContext* context) { - TRACE_EVENT0("gpu", "AsyncPixelTransferDelegate::Create"); + TRACE_EVENT0("gpu", "AsyncPixelTransferManager::Create"); switch (gfx::GetGLImplementation()) { case gfx::kGLImplementationOSMesaGL: case gfx::kGLImplementationDesktopGL: case gfx::kGLImplementationAppleGL: - return new AsyncPixelTransferDelegateIdle; + return new AsyncPixelTransferManagerIdle; case gfx::kGLImplementationMockGL: - return new AsyncPixelTransferDelegateStub; + return new AsyncPixelTransferManagerStub; default: NOTREACHED(); return NULL; diff --git a/gpu/command_buffer/service/async_pixel_transfer_delegate_share_group.cc b/gpu/command_buffer/service/async_pixel_transfer_manager_share_group.cc index 38064d0..d2e3fad 100644 --- a/gpu/command_buffer/service/async_pixel_transfer_delegate_share_group.cc +++ b/gpu/command_buffer/service/async_pixel_transfer_manager_share_group.cc @@ -2,12 +2,16 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "gpu/command_buffer/service/async_pixel_transfer_delegate_share_group.h" +#include "gpu/command_buffer/service/async_pixel_transfer_manager_share_group.h" + +#include <list> #include "base/bind.h" #include "base/debug/trace_event.h" #include "base/lazy_instance.h" #include "base/logging.h" +#include "base/memory/ref_counted.h" +#include "base/memory/weak_ptr.h" #include "base/synchronization/cancellation_flag.h" #include "base/synchronization/lock.h" #include "base/synchronization/waitable_event.h" @@ -321,6 +325,44 @@ class AsyncTransferStateImpl : public AsyncPixelTransferState { scoped_refptr<TransferStateInternal> internal_; }; +class AsyncPixelTransferDelegateShareGroup : public AsyncPixelTransferDelegate { + public: + explicit AsyncPixelTransferDelegateShareGroup(gfx::GLContext* context); + virtual ~AsyncPixelTransferDelegateShareGroup(); + + // Implement AsyncPixelTransferDelegate: + virtual AsyncPixelTransferState* CreatePixelTransferState( + GLuint texture_id, + const AsyncTexImage2DParams& define_params) OVERRIDE; + virtual void BindCompletedAsyncTransfers() OVERRIDE; + virtual void AsyncNotifyCompletion( + const AsyncMemoryParams& mem_params, + const CompletionCallback& callback) OVERRIDE; + virtual void AsyncTexImage2D( + AsyncPixelTransferState* state, + const AsyncTexImage2DParams& tex_params, + const AsyncMemoryParams& mem_params, + const base::Closure& bind_callback) OVERRIDE; + virtual void AsyncTexSubImage2D( + AsyncPixelTransferState* state, + const AsyncTexSubImage2DParams& tex_params, + const AsyncMemoryParams& mem_params) OVERRIDE; + virtual void WaitForTransferCompletion( + AsyncPixelTransferState* state) OVERRIDE; + virtual uint32 GetTextureUploadCount() OVERRIDE; + virtual base::TimeDelta GetTotalTextureUploadTime() OVERRIDE; + virtual void ProcessMorePendingTransfers() OVERRIDE; + virtual bool NeedsProcessMorePendingTransfers() OVERRIDE; + + private: + typedef std::list<base::WeakPtr<AsyncPixelTransferState> > TransferQueue; + TransferQueue pending_allocations_; + + scoped_refptr<AsyncPixelTransferUploadStats> texture_upload_stats_; + + DISALLOW_COPY_AND_ASSIGN(AsyncPixelTransferDelegateShareGroup); +}; + AsyncPixelTransferDelegateShareGroup::AsyncPixelTransferDelegateShareGroup( gfx::GLContext* context) { g_transfer_thread.Pointer()->InitializeOnMainThread(context); @@ -501,4 +543,15 @@ bool AsyncPixelTransferDelegateShareGroup::NeedsProcessMorePendingTransfers() { return false; } +AsyncPixelTransferManagerShareGroup::AsyncPixelTransferManagerShareGroup( + gfx::GLContext* context) + : delegate_(new AsyncPixelTransferDelegateShareGroup(context)) {} + +AsyncPixelTransferManagerShareGroup::~AsyncPixelTransferManagerShareGroup() {} + +AsyncPixelTransferDelegate* +AsyncPixelTransferManagerShareGroup::GetAsyncPixelTransferDelegate() { + return delegate_.get(); +} + } // namespace gpu diff --git a/gpu/command_buffer/service/async_pixel_transfer_manager_share_group.h b/gpu/command_buffer/service/async_pixel_transfer_manager_share_group.h new file mode 100644 index 0000000..32db74f --- /dev/null +++ b/gpu/command_buffer/service/async_pixel_transfer_manager_share_group.h @@ -0,0 +1,34 @@ +// Copyright 2013 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef GPU_COMMAND_BUFFER_SERVICE_ASYNC_PIXEL_TRANSFER_MANAGER_SHARE_GROUP_H_ +#define GPU_COMMAND_BUFFER_SERVICE_ASYNC_PIXEL_TRANSFER_MANAGER_SHARE_GROUP_H_ + +#include "gpu/command_buffer/service/async_pixel_transfer_manager.h" + +namespace gfx { +class GLContext; +} + +namespace gpu { + +class AsyncPixelTransferDelegateShareGroup; + +class AsyncPixelTransferManagerShareGroup : public AsyncPixelTransferManager { + public: + explicit AsyncPixelTransferManagerShareGroup(gfx::GLContext* context); + virtual ~AsyncPixelTransferManagerShareGroup(); + + // AsyncPixelTransferManager implementation: + virtual AsyncPixelTransferDelegate* GetAsyncPixelTransferDelegate() OVERRIDE; + + private: + scoped_ptr<AsyncPixelTransferDelegateShareGroup> delegate_; + + DISALLOW_COPY_AND_ASSIGN(AsyncPixelTransferManagerShareGroup); +}; + +} // namespace gpu + +#endif // GPU_COMMAND_BUFFER_SERVICE_ASYNC_PIXEL_TRANSFER_MANAGER_SHARE_GROUP_H_ diff --git a/gpu/command_buffer/service/async_pixel_transfer_delegate_stub.cc b/gpu/command_buffer/service/async_pixel_transfer_manager_stub.cc index 5bd7db9..48af037 100644 --- a/gpu/command_buffer/service/async_pixel_transfer_delegate_stub.cc +++ b/gpu/command_buffer/service/async_pixel_transfer_manager_stub.cc @@ -1,8 +1,10 @@ -// Copyright (c) 2013 The Chromium Authors. All rights reserved. +// Copyright 2013 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "gpu/command_buffer/service/async_pixel_transfer_delegate_stub.h" +#include "gpu/command_buffer/service/async_pixel_transfer_manager_stub.h" + +#include "gpu/command_buffer/service/async_pixel_transfer_delegate.h" namespace gpu { @@ -23,6 +25,39 @@ class AsyncPixelTransferStateImpl : public AsyncPixelTransferState { } // namespace +class AsyncPixelTransferDelegateStub : public AsyncPixelTransferDelegate { + public: + AsyncPixelTransferDelegateStub(); + virtual ~AsyncPixelTransferDelegateStub(); + + // Implement AsyncPixelTransferDelegate: + virtual AsyncPixelTransferState* CreatePixelTransferState( + GLuint texture_id, + const AsyncTexImage2DParams& define_params) OVERRIDE; + virtual void BindCompletedAsyncTransfers() OVERRIDE; + virtual void AsyncNotifyCompletion( + const AsyncMemoryParams& mem_params, + const CompletionCallback& callback) OVERRIDE; + virtual void AsyncTexImage2D( + AsyncPixelTransferState* state, + const AsyncTexImage2DParams& tex_params, + const AsyncMemoryParams& mem_params, + const base::Closure& bind_callback) OVERRIDE; + virtual void AsyncTexSubImage2D( + AsyncPixelTransferState* transfer_state, + const AsyncTexSubImage2DParams& tex_params, + const AsyncMemoryParams& mem_params) OVERRIDE; + virtual void WaitForTransferCompletion( + AsyncPixelTransferState* state) OVERRIDE; + virtual uint32 GetTextureUploadCount() OVERRIDE; + virtual base::TimeDelta GetTotalTextureUploadTime() OVERRIDE; + virtual void ProcessMorePendingTransfers() OVERRIDE; + virtual bool NeedsProcessMorePendingTransfers() OVERRIDE; + + private: + DISALLOW_COPY_AND_ASSIGN(AsyncPixelTransferDelegateStub); +}; + AsyncPixelTransferDelegateStub::AsyncPixelTransferDelegateStub() {} AsyncPixelTransferDelegateStub::~AsyncPixelTransferDelegateStub() {} @@ -75,5 +110,14 @@ bool AsyncPixelTransferDelegateStub::NeedsProcessMorePendingTransfers() { return false; } -} // namespace gpu +AsyncPixelTransferManagerStub::AsyncPixelTransferManagerStub() + : delegate_(new AsyncPixelTransferDelegateStub()) {} + +AsyncPixelTransferManagerStub::~AsyncPixelTransferManagerStub() {} +AsyncPixelTransferDelegate* +AsyncPixelTransferManagerStub::GetAsyncPixelTransferDelegate() { + return delegate_.get(); +} + +} // namespace gpu diff --git a/gpu/command_buffer/service/async_pixel_transfer_manager_stub.h b/gpu/command_buffer/service/async_pixel_transfer_manager_stub.h new file mode 100644 index 0000000..c9294922 --- /dev/null +++ b/gpu/command_buffer/service/async_pixel_transfer_manager_stub.h @@ -0,0 +1,30 @@ +// Copyright 2013 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef GPU_COMMAND_BUFFER_SERVICE_ASYNC_PIXEL_TRANSFER_MANAGER_STUB_H_ +#define GPU_COMMAND_BUFFER_SERVICE_ASYNC_PIXEL_TRANSFER_MANAGER_STUB_H_ + +#include "gpu/command_buffer/service/async_pixel_transfer_manager.h" + +namespace gpu { + +class AsyncPixelTransferDelegateStub; + +class AsyncPixelTransferManagerStub : public AsyncPixelTransferManager { + public: + AsyncPixelTransferManagerStub(); + virtual ~AsyncPixelTransferManagerStub(); + + // AsyncPixelTransferManager implementation: + virtual AsyncPixelTransferDelegate* GetAsyncPixelTransferDelegate() OVERRIDE; + + private: + scoped_ptr<AsyncPixelTransferDelegateStub> delegate_; + + DISALLOW_COPY_AND_ASSIGN(AsyncPixelTransferManagerStub); +}; + +} // namespace gpu + +#endif // GPU_COMMAND_BUFFER_SERVICE_ASYNC_PIXEL_TRANSFER_MANAGER_STUB_H_ diff --git a/gpu/command_buffer/service/async_pixel_transfer_delegate_sync.cc b/gpu/command_buffer/service/async_pixel_transfer_manager_sync.cc index 6eb58f2..ffd0549 100644 --- a/gpu/command_buffer/service/async_pixel_transfer_delegate_sync.cc +++ b/gpu/command_buffer/service/async_pixel_transfer_manager_sync.cc @@ -1,8 +1,10 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Copyright 2013 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "gpu/command_buffer/service/async_pixel_transfer_delegate_sync.h" +#include "gpu/command_buffer/service/async_pixel_transfer_manager_sync.h" + +#include "gpu/command_buffer/service/async_pixel_transfer_delegate.h" namespace gpu { @@ -23,6 +25,43 @@ class AsyncPixelTransferStateImpl : public AsyncPixelTransferState { } // namespace +// Class which handles async pixel transfers synchronously. +class AsyncPixelTransferDelegateSync : public AsyncPixelTransferDelegate { + public: + AsyncPixelTransferDelegateSync(); + virtual ~AsyncPixelTransferDelegateSync(); + + // Implement AsyncPixelTransferDelegate: + virtual AsyncPixelTransferState* CreatePixelTransferState( + GLuint texture_id, + const AsyncTexImage2DParams& define_params) OVERRIDE; + virtual void BindCompletedAsyncTransfers() OVERRIDE; + virtual void AsyncNotifyCompletion( + const AsyncMemoryParams& mem_params, + const CompletionCallback& callback) OVERRIDE; + virtual void AsyncTexImage2D( + AsyncPixelTransferState* state, + const AsyncTexImage2DParams& tex_params, + const AsyncMemoryParams& mem_params, + const base::Closure& bind_callback) OVERRIDE; + virtual void AsyncTexSubImage2D( + AsyncPixelTransferState* transfer_state, + const AsyncTexSubImage2DParams& tex_params, + const AsyncMemoryParams& mem_params) OVERRIDE; + virtual void WaitForTransferCompletion( + AsyncPixelTransferState* state) OVERRIDE; + virtual uint32 GetTextureUploadCount() OVERRIDE; + virtual base::TimeDelta GetTotalTextureUploadTime() OVERRIDE; + virtual void ProcessMorePendingTransfers() OVERRIDE; + virtual bool NeedsProcessMorePendingTransfers() OVERRIDE; + + private: + int texture_upload_count_; + base::TimeDelta total_texture_upload_time_; + + DISALLOW_COPY_AND_ASSIGN(AsyncPixelTransferDelegateSync); +}; + AsyncPixelTransferDelegateSync::AsyncPixelTransferDelegateSync() : texture_upload_count_(0) { } @@ -109,5 +148,15 @@ bool AsyncPixelTransferDelegateSync::NeedsProcessMorePendingTransfers() { return false; } +AsyncPixelTransferManagerSync::AsyncPixelTransferManagerSync() + : delegate_(new AsyncPixelTransferDelegateSync()) {} + +AsyncPixelTransferManagerSync::~AsyncPixelTransferManagerSync() {} + +AsyncPixelTransferDelegate* +AsyncPixelTransferManagerSync::GetAsyncPixelTransferDelegate() { + return delegate_.get(); +} + } // namespace gpu diff --git a/gpu/command_buffer/service/async_pixel_transfer_manager_sync.h b/gpu/command_buffer/service/async_pixel_transfer_manager_sync.h new file mode 100644 index 0000000..3638647 --- /dev/null +++ b/gpu/command_buffer/service/async_pixel_transfer_manager_sync.h @@ -0,0 +1,29 @@ +// Copyright 2013 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef GPU_COMMAND_BUFFER_SERVICE_ASYNC_PIXEL_TRANSFER_MANAGER_SYNC_H_ +#define GPU_COMMAND_BUFFER_SERVICE_ASYNC_PIXEL_TRANSFER_MANAGER_SYNC_H_ + +#include "gpu/command_buffer/service/async_pixel_transfer_manager.h" + +namespace gpu { +class AsyncPixelTransferDelegateSync; + +class AsyncPixelTransferManagerSync : public AsyncPixelTransferManager { + public: + AsyncPixelTransferManagerSync(); + virtual ~AsyncPixelTransferManagerSync(); + + // AsyncPixelTransferManager implementation: + virtual AsyncPixelTransferDelegate* GetAsyncPixelTransferDelegate() OVERRIDE; + + private: + scoped_ptr<AsyncPixelTransferDelegateSync> delegate_; + + DISALLOW_COPY_AND_ASSIGN(AsyncPixelTransferManagerSync); +}; + +} // namespace gpu + +#endif // GPU_COMMAND_BUFFER_SERVICE_ASYNC_PIXEL_TRANSFER_MANAGER_SYNC_H_ diff --git a/gpu/command_buffer/service/async_pixel_transfer_manager_test.cc b/gpu/command_buffer/service/async_pixel_transfer_manager_test.cc new file mode 100644 index 0000000..d07b01f --- /dev/null +++ b/gpu/command_buffer/service/async_pixel_transfer_manager_test.cc @@ -0,0 +1,23 @@ +// Copyright 2013 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "gpu/command_buffer/service/async_pixel_transfer_manager_test.h" + +#include "gpu/command_buffer/service/async_pixel_transfer_delegate_mock.h" +#include "testing/gtest/include/gtest/gtest.h" + +namespace gpu { + +AsyncPixelTransferManagerTest::AsyncPixelTransferManagerTest() + : delegate_( + new ::testing::StrictMock<gpu::MockAsyncPixelTransferDelegate>) {} + +AsyncPixelTransferManagerTest::~AsyncPixelTransferManagerTest() {} + +AsyncPixelTransferDelegate* +AsyncPixelTransferManagerTest::GetAsyncPixelTransferDelegate() { + return delegate_.get(); +} + +} // namespace gpu diff --git a/gpu/command_buffer/service/async_pixel_transfer_manager_test.h b/gpu/command_buffer/service/async_pixel_transfer_manager_test.h new file mode 100644 index 0000000..f0b1455 --- /dev/null +++ b/gpu/command_buffer/service/async_pixel_transfer_manager_test.h @@ -0,0 +1,34 @@ +// Copyright 2013 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef GPU_COMMAND_BUFFER_SERVICE_ASYNC_PIXEL_TRANSFER_MANAGER_TEST_H_ +#define GPU_COMMAND_BUFFER_SERVICE_ASYNC_PIXEL_TRANSFER_MANAGER_TEST_H_ + +#include "gpu/command_buffer/service/async_pixel_transfer_manager.h" + +#include "gpu/command_buffer/service/async_pixel_transfer_delegate_mock.h" + +namespace gpu { + +class AsyncPixelTransferManagerTest : public AsyncPixelTransferManager { + public: + AsyncPixelTransferManagerTest(); + virtual ~AsyncPixelTransferManagerTest(); + + // AsyncPixelTransferManager implementation: + virtual AsyncPixelTransferDelegate* GetAsyncPixelTransferDelegate() OVERRIDE; + + ::testing::StrictMock<MockAsyncPixelTransferDelegate>* GetMockDelegate() { + return delegate_.get(); + } + + private: + scoped_ptr< ::testing::StrictMock<MockAsyncPixelTransferDelegate> > delegate_; + + DISALLOW_COPY_AND_ASSIGN(AsyncPixelTransferManagerTest); +}; + +} // namespace gpu + +#endif // GPU_COMMAND_BUFFER_SERVICE_ASYNC_PIXEL_TRANSFER_MANAGER_TEST_H_ diff --git a/gpu/command_buffer/service/async_pixel_transfer_delegate_win.cc b/gpu/command_buffer/service/async_pixel_transfer_manager_win.cc index 76a3e4b..6955885 100644 --- a/gpu/command_buffer/service/async_pixel_transfer_delegate_win.cc +++ b/gpu/command_buffer/service/async_pixel_transfer_manager_win.cc @@ -1,26 +1,26 @@ -// Copyright (c) 2013 The Chromium Authors. All rights reserved. +// Copyright 2013 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "gpu/command_buffer/service/async_pixel_transfer_delegate.h" +#include "gpu/command_buffer/service/async_pixel_transfer_manager.h" #include "base/debug/trace_event.h" -#include "gpu/command_buffer/service/async_pixel_transfer_delegate_idle.h" -#include "gpu/command_buffer/service/async_pixel_transfer_delegate_stub.h" +#include "gpu/command_buffer/service/async_pixel_transfer_manager_idle.h" +#include "gpu/command_buffer/service/async_pixel_transfer_manager_stub.h" #include "ui/gl/gl_implementation.h" namespace gpu { -AsyncPixelTransferDelegate* AsyncPixelTransferDelegate::Create( +AsyncPixelTransferManager* AsyncPixelTransferManager::Create( gfx::GLContext* context) { - TRACE_EVENT0("gpu", "AsyncPixelTransferDelegate::Create"); + TRACE_EVENT0("gpu", "AsyncPixelTransferManager::Create"); switch (gfx::GetGLImplementation()) { case gfx::kGLImplementationOSMesaGL: case gfx::kGLImplementationDesktopGL: case gfx::kGLImplementationEGLGLES2: - return new AsyncPixelTransferDelegateIdle; + return new AsyncPixelTransferManagerIdle; case gfx::kGLImplementationMockGL: - return new AsyncPixelTransferDelegateStub; + return new AsyncPixelTransferManagerStub; default: NOTREACHED(); return NULL; diff --git a/gpu/command_buffer/service/gles2_cmd_decoder.cc b/gpu/command_buffer/service/gles2_cmd_decoder.cc index 2f1b8c6..75ad51d 100644 --- a/gpu/command_buffer/service/gles2_cmd_decoder.cc +++ b/gpu/command_buffer/service/gles2_cmd_decoder.cc @@ -576,11 +576,11 @@ class GLES2DecoderImpl : public GLES2Decoder { virtual AsyncPixelTransferDelegate* GetAsyncPixelTransferDelegate() OVERRIDE; - virtual void SetAsyncPixelTransferDelegateForTest( - AsyncPixelTransferDelegate* delegate) OVERRIDE; virtual AsyncPixelTransferManager* GetAsyncPixelTransferManager() OVERRIDE; virtual void ResetAsyncPixelTransferManagerForTest() OVERRIDE; + virtual void SetAsyncPixelTransferManagerForTest( + AsyncPixelTransferManager* manager) OVERRIDE; void ProcessFinishedAsyncTransfers(); virtual bool GetServiceTextureId(uint32 client_texture_id, @@ -2475,7 +2475,8 @@ bool GLES2DecoderImpl::Initialize( context_->SetSafeToForceGpuSwitch(); async_pixel_transfer_manager_.reset( - new AsyncPixelTransferManager(texture_manager(), context.get())); + AsyncPixelTransferManager::Create(context.get())); + async_pixel_transfer_manager_->Initialize(texture_manager()); return true; } @@ -3061,11 +3062,6 @@ AsyncPixelTransferDelegate* return async_pixel_transfer_manager_->GetAsyncPixelTransferDelegate(); } -void GLES2DecoderImpl::SetAsyncPixelTransferDelegateForTest( - AsyncPixelTransferDelegate* delegate) { - async_pixel_transfer_manager_->SetAsyncPixelTransferDelegateForTest(delegate); -} - AsyncPixelTransferManager* GLES2DecoderImpl::GetAsyncPixelTransferManager() { return async_pixel_transfer_manager_.get(); @@ -3075,6 +3071,11 @@ void GLES2DecoderImpl::ResetAsyncPixelTransferManagerForTest() { async_pixel_transfer_manager_.reset(); } +void GLES2DecoderImpl::SetAsyncPixelTransferManagerForTest( + AsyncPixelTransferManager* manager) { + async_pixel_transfer_manager_ = make_scoped_ptr(manager); +} + bool GLES2DecoderImpl::GetServiceTextureId(uint32 client_texture_id, uint32* service_texture_id) { TextureRef* texture_ref = texture_manager()->GetTexture(client_texture_id); diff --git a/gpu/command_buffer/service/gles2_cmd_decoder.h b/gpu/command_buffer/service/gles2_cmd_decoder.h index 65ebe76..15f3e97 100644 --- a/gpu/command_buffer/service/gles2_cmd_decoder.h +++ b/gpu/command_buffer/service/gles2_cmd_decoder.h @@ -180,11 +180,10 @@ class GPU_EXPORT GLES2Decoder : public base::SupportsWeakPtr<GLES2Decoder>, // Interface to performing async pixel transfers. virtual AsyncPixelTransferDelegate* GetAsyncPixelTransferDelegate() = 0; - virtual void SetAsyncPixelTransferDelegateForTest( - AsyncPixelTransferDelegate* delegate) = 0; - virtual AsyncPixelTransferManager* GetAsyncPixelTransferManager() = 0; virtual void ResetAsyncPixelTransferManagerForTest() = 0; + virtual void SetAsyncPixelTransferManagerForTest( + AsyncPixelTransferManager* manager) = 0; // Get the service texture ID corresponding to a client texture ID. // If no such record is found then return false. diff --git a/gpu/command_buffer/service/gles2_cmd_decoder_mock.h b/gpu/command_buffer/service/gles2_cmd_decoder_mock.h index ded5e4b..4e617e3 100644 --- a/gpu/command_buffer/service/gles2_cmd_decoder_mock.h +++ b/gpu/command_buffer/service/gles2_cmd_decoder_mock.h @@ -73,11 +73,11 @@ class MockGLES2Decoder : public GLES2Decoder { MOCK_METHOD1(SetStreamTextureManager, void(StreamTextureManager*)); MOCK_METHOD0(GetAsyncPixelTransferDelegate, AsyncPixelTransferDelegate*()); - MOCK_METHOD1(SetAsyncPixelTransferDelegateForTest, - void(AsyncPixelTransferDelegate*)); MOCK_METHOD0(GetAsyncPixelTransferManager, AsyncPixelTransferManager*()); MOCK_METHOD0(ResetAsyncPixelTransferManagerForTest, void()); + MOCK_METHOD1(SetAsyncPixelTransferManagerForTest, + void(AsyncPixelTransferManager*)); MOCK_METHOD3(DoCommand, error::Error(unsigned int command, unsigned int arg_count, const void* cmd_data)); diff --git a/gpu/command_buffer/service/gles2_cmd_decoder_unittest.cc b/gpu/command_buffer/service/gles2_cmd_decoder_unittest.cc index ab2a060..e7c8417 100644 --- a/gpu/command_buffer/service/gles2_cmd_decoder_unittest.cc +++ b/gpu/command_buffer/service/gles2_cmd_decoder_unittest.cc @@ -10,6 +10,7 @@ #include "gpu/command_buffer/common/id_allocator.h" #include "gpu/command_buffer/service/async_pixel_transfer_delegate_mock.h" #include "gpu/command_buffer/service/async_pixel_transfer_manager.h" +#include "gpu/command_buffer/service/async_pixel_transfer_manager_test.h" #include "gpu/command_buffer/service/cmd_buffer_engine.h" #include "gpu/command_buffer/service/context_group.h" #include "gpu/command_buffer/service/gl_surface_mock.h" @@ -8081,9 +8082,12 @@ TEST_F(GLES2DecoderManualInitTest, AsyncPixelTransfers) { Texture* texture = texture_ref->texture(); // Set a mock Async delegate + gpu::AsyncPixelTransferManagerTest* manager = + new gpu::AsyncPixelTransferManagerTest; + manager->Initialize(group().texture_manager()); + decoder_->SetAsyncPixelTransferManagerForTest(manager); StrictMock<gpu::MockAsyncPixelTransferDelegate>* delegate = - new StrictMock<gpu::MockAsyncPixelTransferDelegate>; - decoder_->SetAsyncPixelTransferDelegateForTest(delegate); + manager->GetMockDelegate(); StrictMock<gpu::MockAsyncPixelTransferState>* state = NULL; // Tex(Sub)Image2D upload commands. @@ -8244,10 +8248,6 @@ TEST_F(GLES2DecoderManualInitTest, AsyncPixelTransfers) { EXPECT_EQ(error::kNoError, ExecuteCmd(wait_cmd)); EXPECT_EQ(GL_NO_ERROR, GetGLError()); } - - decoder_->SetAsyncPixelTransferDelegateForTest(NULL); - decoder_->GetAsyncPixelTransferManager() - ->ClearPixelTransferStateForTest(texture_ref); } TEST_F(GLES2DecoderManualInitTest, AsyncPixelTransferManager) { @@ -8262,9 +8262,12 @@ TEST_F(GLES2DecoderManualInitTest, AsyncPixelTransferManager) { TextureRef* texture_ref = GetTexture(client_texture_id_); // Set a mock Async delegate. + gpu::AsyncPixelTransferManagerTest* manager = + new gpu::AsyncPixelTransferManagerTest; + manager->Initialize(group().texture_manager()); + decoder_->SetAsyncPixelTransferManagerForTest(manager); StrictMock<gpu::MockAsyncPixelTransferDelegate>* delegate = - new StrictMock<gpu::MockAsyncPixelTransferDelegate>; - decoder_->SetAsyncPixelTransferDelegateForTest(delegate); + manager->GetMockDelegate(); StrictMock<gpu::MockAsyncPixelTransferState>* state = NULL; AsyncTexImage2DCHROMIUM teximage_cmd; diff --git a/gpu/command_buffer_service.gypi b/gpu/command_buffer_service.gypi index 9dc5efd..87b3999 100644 --- a/gpu/command_buffer_service.gypi +++ b/gpu/command_buffer_service.gypi @@ -27,18 +27,18 @@ 'sources': [ 'command_buffer/service/async_pixel_transfer_delegate.cc', 'command_buffer/service/async_pixel_transfer_delegate.h', - 'command_buffer/service/async_pixel_transfer_delegate_android.cc', - 'command_buffer/service/async_pixel_transfer_delegate_idle.cc', - 'command_buffer/service/async_pixel_transfer_delegate_idle.h', - 'command_buffer/service/async_pixel_transfer_delegate_linux.cc', - 'command_buffer/service/async_pixel_transfer_delegate_mac.cc', - 'command_buffer/service/async_pixel_transfer_delegate_share_group.cc', - 'command_buffer/service/async_pixel_transfer_delegate_share_group.h', - 'command_buffer/service/async_pixel_transfer_delegate_stub.cc', - 'command_buffer/service/async_pixel_transfer_delegate_stub.h', - 'command_buffer/service/async_pixel_transfer_delegate_sync.cc', - 'command_buffer/service/async_pixel_transfer_delegate_sync.h', - 'command_buffer/service/async_pixel_transfer_delegate_win.cc', + 'command_buffer/service/async_pixel_transfer_manager_android.cc', + 'command_buffer/service/async_pixel_transfer_manager_idle.cc', + 'command_buffer/service/async_pixel_transfer_manager_idle.h', + 'command_buffer/service/async_pixel_transfer_manager_linux.cc', + 'command_buffer/service/async_pixel_transfer_manager_mac.cc', + 'command_buffer/service/async_pixel_transfer_manager_share_group.cc', + 'command_buffer/service/async_pixel_transfer_manager_share_group.h', + 'command_buffer/service/async_pixel_transfer_manager_stub.cc', + 'command_buffer/service/async_pixel_transfer_manager_stub.h', + 'command_buffer/service/async_pixel_transfer_manager_sync.cc', + 'command_buffer/service/async_pixel_transfer_manager_sync.h', + 'command_buffer/service/async_pixel_transfer_manager_win.cc', 'command_buffer/service/async_pixel_transfer_manager.cc', 'command_buffer/service/async_pixel_transfer_manager.h', 'command_buffer/service/buffer_manager.h', @@ -136,8 +136,8 @@ }], ['OS in ("win", "android") or (OS == "linux" and use_x11 == 1)', { 'sources': [ - 'command_buffer/service/async_pixel_transfer_delegate_egl.cc', - 'command_buffer/service/async_pixel_transfer_delegate_egl.h', + 'command_buffer/service/async_pixel_transfer_manager_egl.cc', + 'command_buffer/service/async_pixel_transfer_manager_egl.h', ], }] ], diff --git a/gpu/gpu.gyp b/gpu/gpu.gyp index 026aad5..d806667 100644 --- a/gpu/gpu.gyp +++ b/gpu/gpu.gyp @@ -165,6 +165,8 @@ 'command_buffer/common/unittest_main.cc', 'command_buffer/service/async_pixel_transfer_delegate_mock.h', 'command_buffer/service/async_pixel_transfer_delegate_mock.cc', + 'command_buffer/service/async_pixel_transfer_manager_test.h', + 'command_buffer/service/async_pixel_transfer_manager_test.cc', 'command_buffer/service/buffer_manager_unittest.cc', 'command_buffer/service/cmd_parser_test.cc', 'command_buffer/service/command_buffer_service_unittest.cc', |