summaryrefslogtreecommitdiffstats
path: root/gpu
diff options
context:
space:
mode:
authorbacker@chromium.org <backer@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-06-12 17:27:18 +0000
committerbacker@chromium.org <backer@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-06-12 17:27:18 +0000
commit896425e12942f2c4ffa3ba8c22017cf0c247e522 (patch)
tree88e7e743bd1c0a427cdbf09602de32fdf7ad1323 /gpu
parentb6c1d9e8c516896e616e8f1924c1a237175ddd59 (diff)
downloadchromium_src-896425e12942f2c4ffa3ba8c22017cf0c247e522.zip
chromium_src-896425e12942f2c4ffa3ba8c22017cf0c247e522.tar.gz
chromium_src-896425e12942f2c4ffa3ba8c22017cf0c247e522.tar.bz2
GPU: Replace AsyncPixelTransferState with AsyncPixelTransferDelegate.
Manager now manages Delegates instead of States. Delegate now owns State. State is now hidden in the implementation files. BUG=240504 Review URL: https://chromiumcodereview.appspot.com/16175005 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@205849 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'gpu')
-rw-r--r--gpu/command_buffer/service/async_pixel_transfer_delegate.cc4
-rw-r--r--gpu/command_buffer/service/async_pixel_transfer_delegate.h33
-rw-r--r--gpu/command_buffer/service/async_pixel_transfer_delegate_mock.cc8
-rw-r--r--gpu/command_buffer/service/async_pixel_transfer_delegate_mock.h41
-rw-r--r--gpu/command_buffer/service/async_pixel_transfer_manager.cc40
-rw-r--r--gpu/command_buffer/service/async_pixel_transfer_manager.h23
-rw-r--r--gpu/command_buffer/service/async_pixel_transfer_manager_egl.cc174
-rw-r--r--gpu/command_buffer/service/async_pixel_transfer_manager_egl.h11
-rw-r--r--gpu/command_buffer/service/async_pixel_transfer_manager_idle.cc88
-rw-r--r--gpu/command_buffer/service/async_pixel_transfer_manager_idle.h8
-rw-r--r--gpu/command_buffer/service/async_pixel_transfer_manager_mock.h6
-rw-r--r--gpu/command_buffer/service/async_pixel_transfer_manager_share_group.cc132
-rw-r--r--gpu/command_buffer/service/async_pixel_transfer_manager_share_group.h11
-rw-r--r--gpu/command_buffer/service/async_pixel_transfer_manager_stub.cc49
-rw-r--r--gpu/command_buffer/service/async_pixel_transfer_manager_stub.h8
-rw-r--r--gpu/command_buffer/service/async_pixel_transfer_manager_sync.cc54
-rw-r--r--gpu/command_buffer/service/async_pixel_transfer_manager_sync.h8
-rw-r--r--gpu/command_buffer/service/gles2_cmd_decoder.cc35
-rw-r--r--gpu/command_buffer/service/gles2_cmd_decoder.h1
-rw-r--r--gpu/command_buffer/service/gles2_cmd_decoder_unittest.cc123
20 files changed, 327 insertions, 530 deletions
diff --git a/gpu/command_buffer/service/async_pixel_transfer_delegate.cc b/gpu/command_buffer/service/async_pixel_transfer_delegate.cc
index 9df9c60..074f675 100644
--- a/gpu/command_buffer/service/async_pixel_transfer_delegate.cc
+++ b/gpu/command_buffer/service/async_pixel_transfer_delegate.cc
@@ -44,10 +44,6 @@ int AsyncPixelTransferUploadStats::GetStats(
return texture_upload_count_;
}
-AsyncPixelTransferState::AsyncPixelTransferState(){}
-
-AsyncPixelTransferState::~AsyncPixelTransferState(){}
-
AsyncPixelTransferDelegate::AsyncPixelTransferDelegate(){}
AsyncPixelTransferDelegate::~AsyncPixelTransferDelegate(){}
diff --git a/gpu/command_buffer/service/async_pixel_transfer_delegate.h b/gpu/command_buffer/service/async_pixel_transfer_delegate.h
index b8e33a6..31bb372 100644
--- a/gpu/command_buffer/service/async_pixel_transfer_delegate.h
+++ b/gpu/command_buffer/service/async_pixel_transfer_delegate.h
@@ -9,7 +9,6 @@
#include "base/callback.h"
#include "base/memory/ref_counted.h"
#include "base/memory/scoped_ptr.h"
-#include "base/memory/weak_ptr.h"
#include "base/synchronization/lock.h"
#include "base/time.h"
#include "gpu/gpu_export.h"
@@ -72,50 +71,26 @@ class AsyncPixelTransferUploadStats
DISALLOW_COPY_AND_ASSIGN(AsyncPixelTransferUploadStats);
};
-// AsyncPixelTransferState holds the resources required to do async
-// transfers on one texture. It should stay alive for the lifetime
-// of the texture to allow multiple transfers.
-class GPU_EXPORT AsyncPixelTransferState
- : public base::RefCounted<AsyncPixelTransferState>,
- public base::SupportsWeakPtr<AsyncPixelTransferState> {
- public:
- // Returns true if there is a transfer in progress.
- virtual bool TransferIsInProgress() = 0;
-
- protected:
- AsyncPixelTransferState();
- virtual ~AsyncPixelTransferState();
-
- private:
- friend class base::RefCounted<AsyncPixelTransferState>;
-
- DISALLOW_COPY_AND_ASSIGN(AsyncPixelTransferState);
-};
-
class GPU_EXPORT AsyncPixelTransferDelegate {
public:
virtual ~AsyncPixelTransferDelegate();
- virtual AsyncPixelTransferState* CreatePixelTransferState(
- GLuint texture_id,
- const AsyncTexImage2DParams& define_params) = 0;
-
// The callback occurs on the caller thread, once the texture is
// safe/ready to be used.
virtual void AsyncTexImage2D(
- AsyncPixelTransferState* state,
const AsyncTexImage2DParams& tex_params,
const AsyncMemoryParams& mem_params,
const base::Closure& bind_callback) = 0;
virtual void AsyncTexSubImage2D(
- AsyncPixelTransferState* state,
const AsyncTexSubImage2DParams& tex_params,
const AsyncMemoryParams& mem_params) = 0;
+ // Returns true if there is a transfer in progress.
+ virtual bool TransferIsInProgress() = 0;
+
// Block until the specified transfer completes.
- virtual void WaitForTransferCompletion(
- AsyncPixelTransferState* state) = 0;
+ virtual void WaitForTransferCompletion() = 0;
// Gets the address of the data from shared memory.
static void* GetAddress(const AsyncMemoryParams& mem_params);
diff --git a/gpu/command_buffer/service/async_pixel_transfer_delegate_mock.cc b/gpu/command_buffer/service/async_pixel_transfer_delegate_mock.cc
index 17d2b65..8e2d75f 100644
--- a/gpu/command_buffer/service/async_pixel_transfer_delegate_mock.cc
+++ b/gpu/command_buffer/service/async_pixel_transfer_delegate_mock.cc
@@ -6,17 +6,11 @@
namespace gpu {
-MockAsyncPixelTransferState::MockAsyncPixelTransferState() {
-}
-
-MockAsyncPixelTransferState::~MockAsyncPixelTransferState() {
- Destroy();
-}
-
MockAsyncPixelTransferDelegate::MockAsyncPixelTransferDelegate() {
}
MockAsyncPixelTransferDelegate::~MockAsyncPixelTransferDelegate() {
+ Destroy();
}
} // namespace gpu
diff --git a/gpu/command_buffer/service/async_pixel_transfer_delegate_mock.h b/gpu/command_buffer/service/async_pixel_transfer_delegate_mock.h
index 55f43e8..9d28730 100644
--- a/gpu/command_buffer/service/async_pixel_transfer_delegate_mock.h
+++ b/gpu/command_buffer/service/async_pixel_transfer_delegate_mock.h
@@ -11,41 +11,24 @@
namespace gpu {
-class MockAsyncPixelTransferState : public AsyncPixelTransferState {
- public:
- MockAsyncPixelTransferState();
-
- // Called in ~MockAsyncPixelTransferState.
- MOCK_METHOD0(Destroy, void());
-
- // Implement AsyncPixelTransferState.
- MOCK_METHOD0(TransferIsInProgress, bool());
- MOCK_METHOD1(BindTransfer, void(AsyncTexImage2DParams* level_params));
-
- protected:
- virtual ~MockAsyncPixelTransferState();
- DISALLOW_COPY_AND_ASSIGN(MockAsyncPixelTransferState);
-};
-
class MockAsyncPixelTransferDelegate : public AsyncPixelTransferDelegate {
public:
MockAsyncPixelTransferDelegate();
virtual ~MockAsyncPixelTransferDelegate();
+ // Called in ~MockAsyncPixelTransferDelegate.
+ MOCK_METHOD0(Destroy, void());
+
// Implement AsyncPixelTransferDelegate.
- MOCK_METHOD2(CreatePixelTransferState,
- AsyncPixelTransferState*(
- GLuint service_id, const AsyncTexImage2DParams& define_params));
- MOCK_METHOD4(AsyncTexImage2D,
- void(AsyncPixelTransferState*,
- const AsyncTexImage2DParams& tex_params,
- const AsyncMemoryParams& mem_params,
- const base::Closure& bind_callback));
- MOCK_METHOD3(AsyncTexSubImage2D,
- void(AsyncPixelTransferState*,
- const AsyncTexSubImage2DParams& tex_params,
- const AsyncMemoryParams& mem_params));
- MOCK_METHOD1(WaitForTransferCompletion, void(AsyncPixelTransferState*));
+ MOCK_METHOD3(AsyncTexImage2D,
+ void(const AsyncTexImage2DParams& tex_params,
+ const AsyncMemoryParams& mem_params,
+ const base::Closure& bind_callback));
+ MOCK_METHOD2(AsyncTexSubImage2D,
+ void(const AsyncTexSubImage2DParams& tex_params,
+ const AsyncMemoryParams& mem_params));
+ MOCK_METHOD0(TransferIsInProgress, bool());
+ MOCK_METHOD0(WaitForTransferCompletion, void());
private:
DISALLOW_COPY_AND_ASSIGN(MockAsyncPixelTransferDelegate);
diff --git a/gpu/command_buffer/service/async_pixel_transfer_manager.cc b/gpu/command_buffer/service/async_pixel_transfer_manager.cc
index e82444e..59a1462 100644
--- a/gpu/command_buffer/service/async_pixel_transfer_manager.cc
+++ b/gpu/command_buffer/service/async_pixel_transfer_manager.cc
@@ -20,39 +20,39 @@ void AsyncPixelTransferManager::Initialize(gles2::TextureManager* manager) {
manager_->AddObserver(this);
}
-AsyncPixelTransferState* AsyncPixelTransferManager::CreatePixelTransferState(
+AsyncPixelTransferDelegate*
+AsyncPixelTransferManager::CreatePixelTransferDelegate(
gles2::TextureRef* ref,
const AsyncTexImage2DParams& define_params) {
- DCHECK(!GetPixelTransferState(ref));
- AsyncPixelTransferState* state =
- GetAsyncPixelTransferDelegate()->CreatePixelTransferState(
- ref->texture()->service_id(), define_params);
- state_map_[ref] = state;
- return state;
+ DCHECK(!GetPixelTransferDelegate(ref));
+ AsyncPixelTransferDelegate* delegate =
+ CreatePixelTransferDelegateImpl(ref, define_params);
+ delegate_map_[ref] = make_linked_ptr(delegate);
+ return delegate;
}
-AsyncPixelTransferState*
-AsyncPixelTransferManager::GetPixelTransferState(
+AsyncPixelTransferDelegate*
+AsyncPixelTransferManager::GetPixelTransferDelegate(
gles2::TextureRef* ref) {
- TextureToStateMap::iterator it = state_map_.find(ref);
- if (it == state_map_.end()) {
+ TextureToDelegateMap::iterator it = delegate_map_.find(ref);
+ if (it == delegate_map_.end()) {
return NULL;
} else {
return it->second.get();
}
}
-void AsyncPixelTransferManager::ClearPixelTransferStateForTest(
+void AsyncPixelTransferManager::ClearPixelTransferDelegateForTest(
gles2::TextureRef* ref) {
- TextureToStateMap::iterator it = state_map_.find(ref);
- if (it != state_map_.end())
- state_map_.erase(it);
+ TextureToDelegateMap::iterator it = delegate_map_.find(ref);
+ if (it != delegate_map_.end())
+ delegate_map_.erase(it);
}
bool AsyncPixelTransferManager::AsyncTransferIsInProgress(
gles2::TextureRef* ref) {
- AsyncPixelTransferState* state = GetPixelTransferState(ref);
- return state && state->TransferIsInProgress();
+ AsyncPixelTransferDelegate* delegate = GetPixelTransferDelegate(ref);
+ return delegate && delegate->TransferIsInProgress();
}
void AsyncPixelTransferManager::OnTextureManagerDestroying(
@@ -64,9 +64,9 @@ void AsyncPixelTransferManager::OnTextureManagerDestroying(
void AsyncPixelTransferManager::OnTextureRefDestroying(
gles2::TextureRef* texture) {
- TextureToStateMap::iterator it = state_map_.find(texture);
- if (it != state_map_.end())
- state_map_.erase(it);
+ TextureToDelegateMap::iterator it = delegate_map_.find(texture);
+ if (it != delegate_map_.end())
+ delegate_map_.erase(it);
}
} // namespace gpu
diff --git a/gpu/command_buffer/service/async_pixel_transfer_manager.h b/gpu/command_buffer/service/async_pixel_transfer_manager.h
index 9dc9c67..1d8786d 100644
--- a/gpu/command_buffer/service/async_pixel_transfer_manager.h
+++ b/gpu/command_buffer/service/async_pixel_transfer_manager.h
@@ -10,7 +10,7 @@
#include "base/basictypes.h"
#include "base/callback.h"
#include "base/containers/hash_tables.h"
-#include "base/memory/ref_counted.h"
+#include "base/memory/linked_ptr.h"
#include "gpu/command_buffer/service/texture_manager.h"
#include "gpu/gpu_export.h"
@@ -31,7 +31,6 @@ class GLContext;
namespace gpu {
class AsyncPixelTransferDelegate;
-class AsyncPixelTransferState;
struct AsyncMemoryParams;
struct AsyncTexImage2DParams;
@@ -64,16 +63,14 @@ class GPU_EXPORT AsyncPixelTransferManager
virtual void ProcessMorePendingTransfers() = 0;
virtual bool NeedsProcessMorePendingTransfers() = 0;
- virtual AsyncPixelTransferDelegate* GetAsyncPixelTransferDelegate() = 0;
-
- AsyncPixelTransferState* CreatePixelTransferState(
+ AsyncPixelTransferDelegate* CreatePixelTransferDelegate(
gles2::TextureRef* ref,
const AsyncTexImage2DParams& define_params);
- AsyncPixelTransferState* GetPixelTransferState(
+ AsyncPixelTransferDelegate* GetPixelTransferDelegate(
gles2::TextureRef* ref);
- void ClearPixelTransferStateForTest(gles2::TextureRef* ref);
+ void ClearPixelTransferDelegateForTest(gles2::TextureRef* ref);
bool AsyncTransferIsInProgress(gles2::TextureRef* ref);
@@ -89,9 +86,15 @@ class GPU_EXPORT AsyncPixelTransferManager
gles2::TextureManager* manager_;
typedef base::hash_map<gles2::TextureRef*,
- scoped_refptr<AsyncPixelTransferState> >
- TextureToStateMap;
- TextureToStateMap state_map_;
+ linked_ptr<AsyncPixelTransferDelegate> >
+ TextureToDelegateMap;
+ TextureToDelegateMap delegate_map_;
+
+ // A factory method called by CreatePixelTransferDelegate that is overriden
+ // by each implementation.
+ virtual AsyncPixelTransferDelegate* CreatePixelTransferDelegateImpl(
+ gles2::TextureRef* ref,
+ const AsyncTexImage2DParams& define_params) = 0;
DISALLOW_COPY_AND_ASSIGN(AsyncPixelTransferManager);
};
diff --git a/gpu/command_buffer/service/async_pixel_transfer_manager_egl.cc b/gpu/command_buffer/service/async_pixel_transfer_manager_egl.cc
index 50d2a84..d6c17ce 100644
--- a/gpu/command_buffer/service/async_pixel_transfer_manager_egl.cc
+++ b/gpu/command_buffer/service/async_pixel_transfer_manager_egl.cc
@@ -389,36 +389,6 @@ class TransferStateInternal
bool use_image_preserved_;
};
-// EGL needs thread-safe ref-counting, so this just wraps
-// an internal thread-safe ref-counted state object.
-class AsyncTransferStateImpl : public AsyncPixelTransferState {
- public:
- AsyncTransferStateImpl(GLuint texture_id,
- const AsyncTexImage2DParams& define_params,
- bool wait_for_uploads,
- bool wait_for_creation,
- bool use_image_preserved)
- : internal_(new TransferStateInternal(texture_id,
- define_params,
- wait_for_uploads,
- wait_for_creation,
- use_image_preserved)) {
- }
-
- virtual bool TransferIsInProgress() OVERRIDE {
- return internal_->TransferIsInProgress();
- }
-
- void BindTransfer() {
- internal_->BindTransfer();
- }
-
- scoped_refptr<TransferStateInternal> internal_;
-
- private:
- virtual ~AsyncTransferStateImpl() {}
-};
-
} // namespace
// Class which handles async pixel transfers using EGLImageKHR and another
@@ -427,55 +397,48 @@ class AsyncPixelTransferDelegateEGL
: public AsyncPixelTransferDelegate,
public base::SupportsWeakPtr<AsyncPixelTransferDelegateEGL> {
public:
- explicit AsyncPixelTransferDelegateEGL(
- AsyncPixelTransferManagerEGL::SharedState* shared_state);
+ AsyncPixelTransferDelegateEGL(
+ AsyncPixelTransferManagerEGL::SharedState* shared_state,
+ GLuint texture_id,
+ const AsyncTexImage2DParams& define_params);
virtual ~AsyncPixelTransferDelegateEGL();
+ void BindTransfer() { state_->BindTransfer(); }
+
// Implement AsyncPixelTransferDelegate:
- virtual AsyncPixelTransferState* CreatePixelTransferState(
- GLuint texture_id,
- const AsyncTexImage2DParams& define_params) 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 bool TransferIsInProgress() OVERRIDE;
+ virtual void WaitForTransferCompletion() OVERRIDE;
private:
// 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);
// A raw pointer is safe because the SharedState is owned by the Manager,
// which owns this Delegate.
AsyncPixelTransferManagerEGL::SharedState* shared_state_;
+ scoped_refptr<TransferStateInternal> state_;
DISALLOW_COPY_AND_ASSIGN(AsyncPixelTransferDelegateEGL);
};
AsyncPixelTransferDelegateEGL::AsyncPixelTransferDelegateEGL(
- AsyncPixelTransferManagerEGL::SharedState* shared_state)
+ AsyncPixelTransferManagerEGL::SharedState* shared_state,
+ GLuint texture_id,
+ const AsyncTexImage2DParams& define_params)
: shared_state_(shared_state) {
-}
-
-AsyncPixelTransferDelegateEGL::~AsyncPixelTransferDelegateEGL() {}
-
-AsyncPixelTransferState* AsyncPixelTransferDelegateEGL::
- CreatePixelTransferState(GLuint texture_id,
- const AsyncTexImage2DParams& define_params) {
// We can't wait on uploads on imagination (it can take 200ms+).
// In practice, they are complete when the CPU glTexSubImage2D completes.
bool wait_for_uploads = !shared_state_->is_imagination;
@@ -493,27 +456,27 @@ AsyncPixelTransferState* AsyncPixelTransferDelegateEGL::
bool use_image_preserved =
shared_state_->is_qualcomm || shared_state_->is_imagination;
- return new AsyncTransferStateImpl(texture_id,
- define_params,
- wait_for_uploads,
- wait_for_creation,
- use_image_preserved);
+ state_ = new TransferStateInternal(texture_id,
+ define_params,
+ wait_for_uploads,
+ wait_for_creation,
+ use_image_preserved);
}
-void AsyncPixelTransferDelegateEGL::WaitForTransferCompletion(
- AsyncPixelTransferState* transfer_state) {
- scoped_refptr<TransferStateInternal> state =
- static_cast<AsyncTransferStateImpl*>(transfer_state)->internal_.get();
- DCHECK(state.get());
- DCHECK(state->texture_id_);
+AsyncPixelTransferDelegateEGL::~AsyncPixelTransferDelegateEGL() {}
+
+bool AsyncPixelTransferDelegateEGL::TransferIsInProgress() {
+ return state_->TransferIsInProgress();
+}
- if (state->TransferIsInProgress()) {
+void AsyncPixelTransferDelegateEGL::WaitForTransferCompletion() {
+ if (state_->TransferIsInProgress()) {
#if defined(OS_ANDROID) || defined(OS_LINUX)
g_transfer_thread.Pointer()->SetPriority(base::kThreadPriority_Display);
#endif
- state->WaitForTransferCompletion();
- DCHECK(!state->TransferIsInProgress());
+ state_->WaitForTransferCompletion();
+ DCHECK(!state_->TransferIsInProgress());
#if defined(OS_ANDROID) || defined(OS_LINUX)
g_transfer_thread.Pointer()->SetPriority(base::kThreadPriority_Background);
@@ -522,40 +485,34 @@ void AsyncPixelTransferDelegateEGL::WaitForTransferCompletion(
}
void AsyncPixelTransferDelegateEGL::AsyncTexImage2D(
- AsyncPixelTransferState* transfer_state,
const AsyncTexImage2DParams& tex_params,
const AsyncMemoryParams& mem_params,
const base::Closure& bind_callback) {
- if (WorkAroundAsyncTexImage2D(transfer_state, tex_params,
- mem_params, bind_callback))
+ if (WorkAroundAsyncTexImage2D(tex_params, mem_params, bind_callback))
return;
- scoped_refptr<TransferStateInternal> state =
- static_cast<AsyncTransferStateImpl*>(transfer_state)->internal_.get();
DCHECK(mem_params.shared_memory);
DCHECK_LE(mem_params.shm_data_offset + mem_params.shm_data_size,
mem_params.shm_size);
- DCHECK(state.get());
- DCHECK(state->texture_id_);
- DCHECK(!state->TransferIsInProgress());
- DCHECK_EQ(state->egl_image_, EGL_NO_IMAGE_KHR);
+ DCHECK(!state_->TransferIsInProgress());
+ DCHECK_EQ(state_->egl_image_, EGL_NO_IMAGE_KHR);
DCHECK_EQ(static_cast<GLenum>(GL_TEXTURE_2D), tex_params.target);
DCHECK_EQ(tex_params.level, 0);
// Mark the transfer in progress and save the late bind
// callback, so we can notify the client when it is bound.
- shared_state_->pending_allocations.push_back(transfer_state->AsWeakPtr());
- state->bind_callback_ = bind_callback;
+ shared_state_->pending_allocations.push_back(AsWeakPtr());
+ state_->bind_callback_ = bind_callback;
// Mark the transfer in progress.
- state->MarkAsTransferIsInProgress();
+ state_->MarkAsTransferIsInProgress();
// Duplicate the shared memory so there is no way we can get
// a use-after-free of the raw pixels.
transfer_message_loop_proxy()->PostTask(FROM_HERE,
base::Bind(
&TransferStateInternal::PerformAsyncTexImage2D,
- state,
+ state_,
tex_params,
mem_params,
base::Owned(new ScopedSafeSharedMemory(safe_shared_memory_pool(),
@@ -567,19 +524,14 @@ void AsyncPixelTransferDelegateEGL::AsyncTexImage2D(
}
void AsyncPixelTransferDelegateEGL::AsyncTexSubImage2D(
- AsyncPixelTransferState* transfer_state,
const AsyncTexSubImage2DParams& tex_params,
const AsyncMemoryParams& mem_params) {
TRACE_EVENT2("gpu", "AsyncTexSubImage2D",
"width", tex_params.width,
"height", tex_params.height);
- if (WorkAroundAsyncTexSubImage2D(transfer_state, tex_params, mem_params))
+ if (WorkAroundAsyncTexSubImage2D(tex_params, mem_params))
return;
- scoped_refptr<TransferStateInternal> state =
- static_cast<AsyncTransferStateImpl*>(transfer_state)->internal_.get();
-
- DCHECK(state->texture_id_);
- DCHECK(!state->TransferIsInProgress());
+ DCHECK(!state_->TransferIsInProgress());
DCHECK(mem_params.shared_memory);
DCHECK_LE(mem_params.shm_data_offset + mem_params.shm_data_size,
mem_params.shm_size);
@@ -587,18 +539,18 @@ void AsyncPixelTransferDelegateEGL::AsyncTexSubImage2D(
DCHECK_EQ(tex_params.level, 0);
// Mark the transfer in progress.
- state->MarkAsTransferIsInProgress();
+ state_->MarkAsTransferIsInProgress();
// If this wasn't async allocated, we don't have an EGLImage yet.
// Create the EGLImage if it hasn't already been created.
- state->CreateEglImageOnMainThreadIfNeeded();
+ state_->CreateEglImageOnMainThreadIfNeeded();
// Duplicate the shared memory so there are no way we can get
// a use-after-free of the raw pixels.
transfer_message_loop_proxy()->PostTask(FROM_HERE,
base::Bind(
&TransferStateInternal::PerformAsyncTexSubImage2D,
- state,
+ state_,
tex_params,
mem_params,
base::Owned(new ScopedSafeSharedMemory(safe_shared_memory_pool(),
@@ -625,7 +577,7 @@ bool DimensionsSupportImgFastPath(int width, int height) {
!(IsPowerOfTwo(width) &&
IsPowerOfTwo(height));
}
-} // namespace
+} // namespace
// It is very difficult to stream uploads on Imagination GPUs:
// - glTexImage2D defers a swizzle/stall until draw-time
@@ -642,14 +594,11 @@ bool DimensionsSupportImgFastPath(int width, int height) {
// on purely synchronous allocation/upload on the main thread.
bool AsyncPixelTransferDelegateEGL::WorkAroundAsyncTexImage2D(
- AsyncPixelTransferState* transfer_state,
const AsyncTexImage2DParams& tex_params,
const AsyncMemoryParams& mem_params,
const base::Closure& bind_callback) {
if (!shared_state_->is_imagination)
return false;
- scoped_refptr<TransferStateInternal> state =
- static_cast<AsyncTransferStateImpl*>(transfer_state)->internal_.get();
// On imagination we allocate synchronously all the time, even
// if the dimensions support fast uploads. This is for part a.)
@@ -664,16 +613,16 @@ bool AsyncPixelTransferDelegateEGL::WorkAroundAsyncTexImage2D(
// The allocation has already occured, so mark it as finished
// and ready for binding.
- CHECK(!state->TransferIsInProgress());
+ CHECK(!state_->TransferIsInProgress());
// If the dimensions support fast async uploads, create the
// EGLImage for future uploads. The late bind should not
// be needed since the EGLImage was created from the main thread
// texture, but this is required to prevent an imagination driver crash.
if (DimensionsSupportImgFastPath(tex_params.width, tex_params.height)) {
- state->CreateEglImageOnMainThreadIfNeeded();
- shared_state_->pending_allocations.push_back(transfer_state->AsWeakPtr());
- state->bind_callback_ = bind_callback;
+ state_->CreateEglImageOnMainThreadIfNeeded();
+ shared_state_->pending_allocations.push_back(AsWeakPtr());
+ state_->bind_callback_ = bind_callback;
}
DCHECK(CHECK_GL());
@@ -681,7 +630,6 @@ bool AsyncPixelTransferDelegateEGL::WorkAroundAsyncTexImage2D(
}
bool AsyncPixelTransferDelegateEGL::WorkAroundAsyncTexSubImage2D(
- AsyncPixelTransferState* transfer_state,
const AsyncTexSubImage2DParams& tex_params,
const AsyncMemoryParams& mem_params) {
if (!shared_state_->is_imagination)
@@ -692,22 +640,19 @@ bool AsyncPixelTransferDelegateEGL::WorkAroundAsyncTexSubImage2D(
if (DimensionsSupportImgFastPath(tex_params.width, tex_params.height))
return false;
- scoped_refptr<TransferStateInternal> state =
- static_cast<AsyncTransferStateImpl*>(transfer_state)->internal_.get();
-
// Fall back on a synchronous stub as we don't have a known fast path.
// Also, older ICS drivers crash when we do any glTexSubImage2D on the
// same thread. To work around this we do glTexImage2D instead. Since
// we didn't create an EGLImage for this texture (see above), this is
// okay, but it limits this API to full updates for now.
- DCHECK(!state->egl_image_);
+ DCHECK(!state_->egl_image_);
DCHECK_EQ(tex_params.xoffset, 0);
DCHECK_EQ(tex_params.yoffset, 0);
- DCHECK_EQ(state->define_params_.width, tex_params.width);
- DCHECK_EQ(state->define_params_.height, tex_params.height);
- DCHECK_EQ(state->define_params_.level, tex_params.level);
- DCHECK_EQ(state->define_params_.format, tex_params.format);
- DCHECK_EQ(state->define_params_.type, tex_params.type);
+ DCHECK_EQ(state_->define_params_.width, tex_params.width);
+ DCHECK_EQ(state_->define_params_.height, tex_params.height);
+ DCHECK_EQ(state_->define_params_.level, tex_params.level);
+ DCHECK_EQ(state_->define_params_.format, tex_params.format);
+ DCHECK_EQ(state_->define_params_.type, tex_params.type);
void* data = GetAddress(mem_params);
base::TimeTicks begin_time;
@@ -717,7 +662,7 @@ bool AsyncPixelTransferDelegateEGL::WorkAroundAsyncTexSubImage2D(
TRACE_EVENT0("gpu", "glTexSubImage2D");
// Note we use define_params_ instead of tex_params.
// The DCHECKs above verify this is always the same.
- DoTexImage2D(state->define_params_, data);
+ DoTexImage2D(state_->define_params_, data);
}
if (shared_state_->texture_upload_stats.get()) {
shared_state_->texture_upload_stats
@@ -739,8 +684,7 @@ AsyncPixelTransferManagerEGL::SharedState::SharedState()
AsyncPixelTransferManagerEGL::SharedState::~SharedState() {}
-AsyncPixelTransferManagerEGL::AsyncPixelTransferManagerEGL()
- : delegate_(new AsyncPixelTransferDelegateEGL(&shared_state_)) {}
+AsyncPixelTransferManagerEGL::AsyncPixelTransferManagerEGL() {}
AsyncPixelTransferManagerEGL::~AsyncPixelTransferManagerEGL() {}
@@ -752,11 +696,10 @@ void AsyncPixelTransferManagerEGL::BindCompletedAsyncTransfers() {
shared_state_.pending_allocations.pop_front();
continue;
}
- scoped_refptr<TransferStateInternal> state =
- static_cast<AsyncTransferStateImpl*>
- (shared_state_.pending_allocations.front().get())->internal_.get();
+ AsyncPixelTransferDelegateEGL* delegate =
+ shared_state_.pending_allocations.front().get();
// Terminate early, as all transfers finish in order, currently.
- if (state->TransferIsInProgress())
+ if (delegate->TransferIsInProgress())
break;
if (!texture_binder)
@@ -764,7 +707,7 @@ void AsyncPixelTransferManagerEGL::BindCompletedAsyncTransfers() {
// If the transfer is finished, bind it to the texture
// and remove it from pending list.
- state->BindTransfer();
+ delegate->BindTransfer();
shared_state_.pending_allocations.pop_front();
}
}
@@ -806,8 +749,11 @@ bool AsyncPixelTransferManagerEGL::NeedsProcessMorePendingTransfers() {
}
AsyncPixelTransferDelegate*
-AsyncPixelTransferManagerEGL::GetAsyncPixelTransferDelegate() {
- return delegate_.get();
+AsyncPixelTransferManagerEGL::CreatePixelTransferDelegateImpl(
+ gles2::TextureRef* ref,
+ const AsyncTexImage2DParams& define_params) {
+ return new AsyncPixelTransferDelegateEGL(
+ &shared_state_, ref->service_id(), define_params);
}
} // 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
index 6354b2f..b70732e 100644
--- a/gpu/command_buffer/service/async_pixel_transfer_manager_egl.h
+++ b/gpu/command_buffer/service/async_pixel_transfer_manager_egl.h
@@ -8,7 +8,6 @@
#include "gpu/command_buffer/service/async_pixel_transfer_manager.h"
#include "base/memory/ref_counted.h"
-#include "base/memory/scoped_ptr.h"
namespace gpu {
class AsyncPixelTransferDelegateEGL;
@@ -28,7 +27,6 @@ class AsyncPixelTransferManagerEGL : public AsyncPixelTransferManager {
virtual base::TimeDelta GetTotalTextureUploadTime() OVERRIDE;
virtual void ProcessMorePendingTransfers() OVERRIDE;
virtual bool NeedsProcessMorePendingTransfers() OVERRIDE;
- virtual AsyncPixelTransferDelegate* GetAsyncPixelTransferDelegate() OVERRIDE;
// State shared between Managers and Delegates.
struct SharedState {
@@ -38,13 +36,18 @@ class AsyncPixelTransferManagerEGL : public AsyncPixelTransferManager {
scoped_refptr<AsyncPixelTransferUploadStats> texture_upload_stats;
bool is_imagination;
bool is_qualcomm;
- typedef std::list<base::WeakPtr<AsyncPixelTransferState> > TransferQueue;
+ typedef std::list<base::WeakPtr<AsyncPixelTransferDelegateEGL> >
+ TransferQueue;
TransferQueue pending_allocations;
};
private:
+ // AsyncPixelTransferManager implementation:
+ virtual AsyncPixelTransferDelegate* CreatePixelTransferDelegateImpl(
+ gles2::TextureRef* ref,
+ const AsyncTexImage2DParams& define_params) OVERRIDE;
+
SharedState shared_state_;
- scoped_ptr<AsyncPixelTransferDelegateEGL> delegate_;
DISALLOW_COPY_AND_ASSIGN(AsyncPixelTransferManagerEGL);
};
diff --git a/gpu/command_buffer/service/async_pixel_transfer_manager_idle.cc b/gpu/command_buffer/service/async_pixel_transfer_manager_idle.cc
index dcb34a4..acf33ef 100644
--- a/gpu/command_buffer/service/async_pixel_transfer_manager_idle.cc
+++ b/gpu/command_buffer/service/async_pixel_transfer_manager_idle.cc
@@ -7,6 +7,7 @@
#include "base/bind.h"
#include "base/debug/trace_event.h"
#include "base/lazy_instance.h"
+#include "base/memory/weak_ptr.h"
#include "gpu/command_buffer/service/safe_shared_memory_pool.h"
#include "ui/gl/scoped_binders.h"
@@ -33,18 +34,21 @@ void PerformNotifyCompletion(
callback.Run(safe_mem_params);
}
-class AsyncPixelTransferStateImpl : public AsyncPixelTransferState {
+// TODO(backer): Merge this with Delegate in follow-up CL. It serves no purpose.
+class AsyncPixelTransferState
+ : public base::SupportsWeakPtr<AsyncPixelTransferState> {
public:
typedef base::Callback<void(GLuint)> TransferCallback;
- explicit AsyncPixelTransferStateImpl(GLuint texture_id)
+ explicit AsyncPixelTransferState(GLuint texture_id)
: id_(g_next_pixel_transfer_state_id++),
texture_id_(texture_id),
transfer_in_progress_(false) {
}
- // Implement AsyncPixelTransferState:
- virtual bool TransferIsInProgress() OVERRIDE {
+ virtual ~AsyncPixelTransferState() {}
+
+ bool TransferIsInProgress() {
return transfer_in_progress_;
}
@@ -62,11 +66,11 @@ class AsyncPixelTransferStateImpl : public AsyncPixelTransferState {
}
private:
- virtual ~AsyncPixelTransferStateImpl() {}
-
uint64 id_;
GLuint texture_id_;
bool transfer_in_progress_;
+
+ DISALLOW_COPY_AND_ASSIGN(AsyncPixelTransferState);
};
} // namespace
@@ -76,25 +80,21 @@ class AsyncPixelTransferStateImpl : public AsyncPixelTransferState {
class AsyncPixelTransferDelegateIdle : public AsyncPixelTransferDelegate,
public base::SupportsWeakPtr<AsyncPixelTransferDelegateIdle> {
public:
- explicit AsyncPixelTransferDelegateIdle(
- AsyncPixelTransferManagerIdle::SharedState* state);
+ AsyncPixelTransferDelegateIdle(
+ AsyncPixelTransferManagerIdle::SharedState* state,
+ GLuint texture_id);
virtual ~AsyncPixelTransferDelegateIdle();
// Implement AsyncPixelTransferDelegate:
- virtual AsyncPixelTransferState* CreatePixelTransferState(
- GLuint texture_id,
- const AsyncTexImage2DParams& define_params) 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 bool TransferIsInProgress() OVERRIDE;
+ virtual void WaitForTransferCompletion() OVERRIDE;
private:
void PerformAsyncTexImage2D(
@@ -112,40 +112,33 @@ class AsyncPixelTransferDelegateIdle : public AsyncPixelTransferDelegate,
// Safe to hold a raw pointer because SharedState is owned by the Manager
// which owns the Delegate.
AsyncPixelTransferManagerIdle::SharedState* shared_state_;
+ scoped_ptr<AsyncPixelTransferState> state_;
DISALLOW_COPY_AND_ASSIGN(AsyncPixelTransferDelegateIdle);
};
AsyncPixelTransferDelegateIdle::AsyncPixelTransferDelegateIdle(
- AsyncPixelTransferManagerIdle::SharedState* shared_state)
- : shared_state_(shared_state) {}
+ AsyncPixelTransferManagerIdle::SharedState* shared_state,
+ GLuint texture_id)
+ : shared_state_(shared_state),
+ state_(new AsyncPixelTransferState(texture_id)) {}
AsyncPixelTransferDelegateIdle::~AsyncPixelTransferDelegateIdle() {}
-AsyncPixelTransferState* AsyncPixelTransferDelegateIdle::
- CreatePixelTransferState(GLuint texture_id,
- const AsyncTexImage2DParams& define_params) {
- return new AsyncPixelTransferStateImpl(texture_id);
-}
-
void AsyncPixelTransferDelegateIdle::AsyncTexImage2D(
- AsyncPixelTransferState* transfer_state,
const AsyncTexImage2DParams& tex_params,
const AsyncMemoryParams& mem_params,
const base::Closure& bind_callback) {
- AsyncPixelTransferStateImpl* state =
- static_cast<AsyncPixelTransferStateImpl*>(transfer_state);
DCHECK_EQ(static_cast<GLenum>(GL_TEXTURE_2D), tex_params.target);
DCHECK(mem_params.shared_memory);
DCHECK_LE(mem_params.shm_data_offset + mem_params.shm_data_size,
mem_params.shm_size);
- DCHECK(state);
shared_state_->tasks.push_back(AsyncPixelTransferManagerIdle::Task(
- state->id(),
+ state_->id(),
base::Bind(
- &AsyncPixelTransferStateImpl::PerformTransfer,
- base::AsWeakPtr(state),
+ &AsyncPixelTransferState::PerformTransfer,
+ state_->AsWeakPtr(),
base::Bind(
&AsyncPixelTransferDelegateIdle::PerformAsyncTexImage2D,
AsWeakPtr(),
@@ -156,26 +149,22 @@ void AsyncPixelTransferDelegateIdle::AsyncTexImage2D(
mem_params.shared_memory,
mem_params.shm_size))))));
- state->set_transfer_in_progress(true);
+ state_->set_transfer_in_progress(true);
}
void AsyncPixelTransferDelegateIdle::AsyncTexSubImage2D(
- AsyncPixelTransferState* transfer_state,
const AsyncTexSubImage2DParams& tex_params,
const AsyncMemoryParams& mem_params) {
- AsyncPixelTransferStateImpl* state =
- static_cast<AsyncPixelTransferStateImpl*>(transfer_state);
DCHECK_EQ(static_cast<GLenum>(GL_TEXTURE_2D), tex_params.target);
DCHECK(mem_params.shared_memory);
DCHECK_LE(mem_params.shm_data_offset + mem_params.shm_data_size,
mem_params.shm_size);
- DCHECK(state);
shared_state_->tasks.push_back(AsyncPixelTransferManagerIdle::Task(
- state->id(),
+ state_->id(),
base::Bind(
- &AsyncPixelTransferStateImpl::PerformTransfer,
- base::AsWeakPtr(state),
+ &AsyncPixelTransferState::PerformTransfer,
+ state_->AsWeakPtr(),
base::Bind(
&AsyncPixelTransferDelegateIdle::PerformAsyncTexSubImage2D,
AsWeakPtr(),
@@ -185,20 +174,19 @@ void AsyncPixelTransferDelegateIdle::AsyncTexSubImage2D(
mem_params.shared_memory,
mem_params.shm_size))))));
- state->set_transfer_in_progress(true);
+ state_->set_transfer_in_progress(true);
}
-void AsyncPixelTransferDelegateIdle::WaitForTransferCompletion(
- AsyncPixelTransferState* transfer_state) {
- AsyncPixelTransferStateImpl* state =
- static_cast<AsyncPixelTransferStateImpl*>(transfer_state);
- DCHECK(state);
+bool AsyncPixelTransferDelegateIdle::TransferIsInProgress() {
+ return state_->TransferIsInProgress();
+}
+void AsyncPixelTransferDelegateIdle::WaitForTransferCompletion() {
for (std::list<AsyncPixelTransferManagerIdle::Task>::iterator iter =
shared_state_->tasks.begin();
iter != shared_state_->tasks.end();
++iter) {
- if (iter->transfer_id != state->id())
+ if (iter->transfer_id != state_->id())
continue;
(*iter).task.Run();
@@ -299,8 +287,8 @@ void AsyncPixelTransferManagerIdle::SharedState::ProcessNotificationTasks() {
}
AsyncPixelTransferManagerIdle::AsyncPixelTransferManagerIdle()
- : shared_state_(),
- delegate_(new AsyncPixelTransferDelegateIdle(&shared_state_)) {}
+ : shared_state_() {
+}
AsyncPixelTransferManagerIdle::~AsyncPixelTransferManagerIdle() {}
@@ -352,8 +340,10 @@ bool AsyncPixelTransferManagerIdle::NeedsProcessMorePendingTransfers() {
}
AsyncPixelTransferDelegate*
-AsyncPixelTransferManagerIdle::GetAsyncPixelTransferDelegate() {
- return delegate_.get();
+AsyncPixelTransferManagerIdle::CreatePixelTransferDelegateImpl(
+ gles2::TextureRef* ref,
+ const AsyncTexImage2DParams& define_params) {
+ return new AsyncPixelTransferDelegateIdle(&shared_state_, ref->service_id());
}
} // 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
index 6a59910..04463b1 100644
--- a/gpu/command_buffer/service/async_pixel_transfer_manager_idle.h
+++ b/gpu/command_buffer/service/async_pixel_transfer_manager_idle.h
@@ -10,7 +10,6 @@
#include "gpu/command_buffer/service/async_pixel_transfer_manager.h"
namespace gpu {
-class AsyncPixelTransferDelegateIdle;
class AsyncPixelTransferManagerIdle : public AsyncPixelTransferManager {
public:
@@ -26,7 +25,6 @@ class AsyncPixelTransferManagerIdle : public AsyncPixelTransferManager {
virtual base::TimeDelta GetTotalTextureUploadTime() OVERRIDE;
virtual void ProcessMorePendingTransfers() OVERRIDE;
virtual bool NeedsProcessMorePendingTransfers() OVERRIDE;
- virtual AsyncPixelTransferDelegate* GetAsyncPixelTransferDelegate() OVERRIDE;
struct Task {
Task(uint64 transfer_id, const base::Closure& task);
@@ -50,8 +48,12 @@ class AsyncPixelTransferManagerIdle : public AsyncPixelTransferManager {
};
private:
+ // AsyncPixelTransferManager implementation:
+ virtual AsyncPixelTransferDelegate* CreatePixelTransferDelegateImpl(
+ gles2::TextureRef* ref,
+ const AsyncTexImage2DParams& define_params) OVERRIDE;
+
SharedState shared_state_;
- scoped_ptr<AsyncPixelTransferDelegateIdle> delegate_;
DISALLOW_COPY_AND_ASSIGN(AsyncPixelTransferManagerIdle);
};
diff --git a/gpu/command_buffer/service/async_pixel_transfer_manager_mock.h b/gpu/command_buffer/service/async_pixel_transfer_manager_mock.h
index 5f50a31..f10c77a 100644
--- a/gpu/command_buffer/service/async_pixel_transfer_manager_mock.h
+++ b/gpu/command_buffer/service/async_pixel_transfer_manager_mock.h
@@ -24,8 +24,12 @@ class MockAsyncPixelTransferManager : public AsyncPixelTransferManager {
MOCK_METHOD0(GetTotalTextureUploadTime, base::TimeDelta());
MOCK_METHOD0(ProcessMorePendingTransfers, void());
MOCK_METHOD0(NeedsProcessMorePendingTransfers, bool());
- MOCK_METHOD0(GetAsyncPixelTransferDelegate, AsyncPixelTransferDelegate*());
+ MOCK_METHOD2(
+ CreatePixelTransferDelegateImpl,
+ AsyncPixelTransferDelegate*(gles2::TextureRef* ref,
+ const AsyncTexImage2DParams& define_params));
+ private:
DISALLOW_COPY_AND_ASSIGN(MockAsyncPixelTransferManager);
};
diff --git a/gpu/command_buffer/service/async_pixel_transfer_manager_share_group.cc b/gpu/command_buffer/service/async_pixel_transfer_manager_share_group.cc
index 683f6a8..e9b7659 100644
--- a/gpu/command_buffer/service/async_pixel_transfer_manager_share_group.cc
+++ b/gpu/command_buffer/service/async_pixel_transfer_manager_share_group.cc
@@ -151,7 +151,6 @@ class TransferStateInternal
define_params_ = define_params;
}
- // Implement AsyncPixelTransferState:
bool TransferIsInProgress() {
return !transfer_completion_.IsSignaled();
}
@@ -183,8 +182,6 @@ class TransferStateInternal
transfer_completion_.Wait();
}
- GLuint texture_id() { return texture_id_; }
-
void SetBindCallback(base::Closure bind_callback) {
bind_callback_ = bind_callback;
}
@@ -301,94 +298,63 @@ class TransferStateInternal
} // namespace
-// ShareGroup needs thread-safe ref-counting, so this just wraps
-// an internal thread-safe ref-counted state object.
-class AsyncTransferStateImpl : public AsyncPixelTransferState {
- public:
- AsyncTransferStateImpl(GLuint texture_id,
- const AsyncTexImage2DParams& define_params)
- : internal_(new TransferStateInternal(texture_id, define_params)) {}
-
- virtual bool TransferIsInProgress() OVERRIDE {
- return internal_->TransferIsInProgress();
- }
-
- TransferStateInternal* internal() { return internal_.get(); }
-
- private:
- virtual ~AsyncTransferStateImpl() {
- TRACE_EVENT0("gpu", " ~AsyncTransferStateImpl");
- base::AutoLock locked(*internal_->upload_lock());
- internal_->cancel_upload_flag()->Set();
- }
-
- scoped_refptr<TransferStateInternal> internal_;
-};
-
-class AsyncPixelTransferDelegateShareGroup : public AsyncPixelTransferDelegate {
+class AsyncPixelTransferDelegateShareGroup
+ : public AsyncPixelTransferDelegate,
+ public base::SupportsWeakPtr<AsyncPixelTransferDelegateShareGroup> {
public:
AsyncPixelTransferDelegateShareGroup(
- gfx::GLContext* context,
- AsyncPixelTransferManagerShareGroup::SharedState* shared_state);
+ AsyncPixelTransferManagerShareGroup::SharedState* shared_state,
+ GLuint texture_id,
+ const AsyncTexImage2DParams& define_params);
virtual ~AsyncPixelTransferDelegateShareGroup();
+ void BindTransfer() { state_->BindTransfer(); }
+
// Implement AsyncPixelTransferDelegate:
- virtual AsyncPixelTransferState* CreatePixelTransferState(
- GLuint texture_id,
- const AsyncTexImage2DParams& define_params) 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 bool TransferIsInProgress() OVERRIDE;
+ virtual void WaitForTransferCompletion() OVERRIDE;
private:
// A raw pointer is safe because the SharedState is owned by the Manager,
// which owns this Delegate.
AsyncPixelTransferManagerShareGroup::SharedState* shared_state_;
+ scoped_refptr<TransferStateInternal> state_;
DISALLOW_COPY_AND_ASSIGN(AsyncPixelTransferDelegateShareGroup);
};
AsyncPixelTransferDelegateShareGroup::AsyncPixelTransferDelegateShareGroup(
- gfx::GLContext* context,
- AsyncPixelTransferManagerShareGroup::SharedState* shared_state)
- : shared_state_(shared_state) {
- g_transfer_thread.Pointer()->InitializeOnMainThread(context);
-}
+ AsyncPixelTransferManagerShareGroup::SharedState* shared_state,
+ GLuint texture_id,
+ const AsyncTexImage2DParams& define_params)
+ : shared_state_(shared_state),
+ state_(new TransferStateInternal(texture_id, define_params)) {}
AsyncPixelTransferDelegateShareGroup::~AsyncPixelTransferDelegateShareGroup() {
+ TRACE_EVENT0("gpu", " ~AsyncPixelTransferDelegateShareGroup");
+ base::AutoLock locked(*state_->upload_lock());
+ state_->cancel_upload_flag()->Set();
}
-AsyncPixelTransferState*
- AsyncPixelTransferDelegateShareGroup::
- CreatePixelTransferState(
- GLuint texture_id,
- const AsyncTexImage2DParams& define_params) {
- return static_cast<AsyncPixelTransferState*>(
- new AsyncTransferStateImpl(texture_id, define_params));
+bool AsyncPixelTransferDelegateShareGroup::TransferIsInProgress() {
+ return state_->TransferIsInProgress();
}
-void AsyncPixelTransferDelegateShareGroup::WaitForTransferCompletion(
- AsyncPixelTransferState* transfer_state) {
- scoped_refptr<TransferStateInternal> state =
- static_cast<AsyncTransferStateImpl*>(transfer_state)->internal();
- DCHECK(state.get());
- DCHECK(state->texture_id());
-
- if (state->TransferIsInProgress()) {
+void AsyncPixelTransferDelegateShareGroup::WaitForTransferCompletion() {
+ if (state_->TransferIsInProgress()) {
#if defined(OS_ANDROID) || defined(OS_LINUX)
g_transfer_thread.Pointer()->SetPriority(base::kThreadPriority_Display);
#endif
- state->WaitForTransferCompletion();
- DCHECK(!state->TransferIsInProgress());
+ state_->WaitForTransferCompletion();
+ DCHECK(!state_->TransferIsInProgress());
#if defined(OS_ANDROID) || defined(OS_LINUX)
g_transfer_thread.Pointer()->SetPriority(base::kThreadPriority_Background);
@@ -397,28 +363,23 @@ void AsyncPixelTransferDelegateShareGroup::WaitForTransferCompletion(
}
void AsyncPixelTransferDelegateShareGroup::AsyncTexImage2D(
- AsyncPixelTransferState* transfer_state,
const AsyncTexImage2DParams& tex_params,
const AsyncMemoryParams& mem_params,
const base::Closure& bind_callback) {
- scoped_refptr<TransferStateInternal> state =
- static_cast<AsyncTransferStateImpl*>(transfer_state)->internal();
DCHECK(mem_params.shared_memory);
DCHECK_LE(mem_params.shm_data_offset + mem_params.shm_data_size,
mem_params.shm_size);
- DCHECK(state.get());
- DCHECK(state->texture_id());
- DCHECK(!state->TransferIsInProgress());
+ DCHECK(!state_->TransferIsInProgress());
DCHECK_EQ(static_cast<GLenum>(GL_TEXTURE_2D), tex_params.target);
DCHECK_EQ(tex_params.level, 0);
// Mark the transfer in progress and save the late bind
// callback, so we can notify the client when it is bound.
- shared_state_->pending_allocations.push_back(transfer_state->AsWeakPtr());
- state->SetBindCallback(bind_callback);
+ shared_state_->pending_allocations.push_back(AsWeakPtr());
+ state_->SetBindCallback(bind_callback);
// Mark the transfer in progress.
- state->MarkAsTransferIsInProgress();
+ state_->MarkAsTransferIsInProgress();
// Duplicate the shared memory so there is no way we can get
// a use-after-free of the raw pixels.
@@ -426,7 +387,7 @@ void AsyncPixelTransferDelegateShareGroup::AsyncTexImage2D(
FROM_HERE,
base::Bind(
&TransferStateInternal::PerformAsyncTexImage2D,
- state,
+ state_,
tex_params,
mem_params,
base::Owned(new ScopedSafeSharedMemory(safe_shared_memory_pool(),
@@ -435,17 +396,12 @@ void AsyncPixelTransferDelegateShareGroup::AsyncTexImage2D(
}
void AsyncPixelTransferDelegateShareGroup::AsyncTexSubImage2D(
- AsyncPixelTransferState* transfer_state,
const AsyncTexSubImage2DParams& tex_params,
const AsyncMemoryParams& mem_params) {
TRACE_EVENT2("gpu", "AsyncTexSubImage2D",
"width", tex_params.width,
"height", tex_params.height);
- scoped_refptr<TransferStateInternal> state =
- static_cast<AsyncTransferStateImpl*>(transfer_state)->internal();
-
- DCHECK(state->texture_id());
- DCHECK(!state->TransferIsInProgress());
+ DCHECK(!state_->TransferIsInProgress());
DCHECK(mem_params.shared_memory);
DCHECK_LE(mem_params.shm_data_offset + mem_params.shm_data_size,
mem_params.shm_size);
@@ -453,7 +409,7 @@ void AsyncPixelTransferDelegateShareGroup::AsyncTexSubImage2D(
DCHECK_EQ(tex_params.level, 0);
// Mark the transfer in progress.
- state->MarkAsTransferIsInProgress();
+ state_->MarkAsTransferIsInProgress();
// Duplicate the shared memory so there are no way we can get
// a use-after-free of the raw pixels.
@@ -461,7 +417,7 @@ void AsyncPixelTransferDelegateShareGroup::AsyncTexSubImage2D(
FROM_HERE,
base::Bind(
&TransferStateInternal::PerformAsyncTexSubImage2D,
- state,
+ state_,
tex_params,
mem_params,
base::Owned(new ScopedSafeSharedMemory(safe_shared_memory_pool(),
@@ -477,9 +433,9 @@ AsyncPixelTransferManagerShareGroup::SharedState::SharedState()
AsyncPixelTransferManagerShareGroup::SharedState::~SharedState() {}
AsyncPixelTransferManagerShareGroup::AsyncPixelTransferManagerShareGroup(
- gfx::GLContext* context)
- : delegate_(new AsyncPixelTransferDelegateShareGroup(context,
- &shared_state_)) {}
+ gfx::GLContext* context) {
+ g_transfer_thread.Pointer()->InitializeOnMainThread(context);
+}
AsyncPixelTransferManagerShareGroup::~AsyncPixelTransferManagerShareGroup() {}
@@ -491,11 +447,10 @@ void AsyncPixelTransferManagerShareGroup::BindCompletedAsyncTransfers() {
shared_state_.pending_allocations.pop_front();
continue;
}
- scoped_refptr<TransferStateInternal> state =
- static_cast<AsyncTransferStateImpl*>
- (shared_state_.pending_allocations.front().get())->internal();
+ AsyncPixelTransferDelegateShareGroup* delegate =
+ shared_state_.pending_allocations.front().get();
// Terminate early, as all transfers finish in order, currently.
- if (state->TransferIsInProgress())
+ if (delegate->TransferIsInProgress())
break;
if (!texture_binder)
@@ -503,7 +458,7 @@ void AsyncPixelTransferManagerShareGroup::BindCompletedAsyncTransfers() {
// Used to set tex info from the gles2 cmd decoder once upload has
// finished (it'll bind the texture and call a callback).
- state->BindTransfer();
+ delegate->BindTransfer();
shared_state_.pending_allocations.pop_front();
}
@@ -547,8 +502,11 @@ bool AsyncPixelTransferManagerShareGroup::NeedsProcessMorePendingTransfers() {
}
AsyncPixelTransferDelegate*
-AsyncPixelTransferManagerShareGroup::GetAsyncPixelTransferDelegate() {
- return delegate_.get();
+AsyncPixelTransferManagerShareGroup::CreatePixelTransferDelegateImpl(
+ gles2::TextureRef* ref,
+ const AsyncTexImage2DParams& define_params) {
+ return new AsyncPixelTransferDelegateShareGroup(
+ &shared_state_, ref->service_id(), define_params);
}
} // 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
index b415770..013fb1d 100644
--- a/gpu/command_buffer/service/async_pixel_transfer_manager_share_group.h
+++ b/gpu/command_buffer/service/async_pixel_transfer_manager_share_group.h
@@ -8,7 +8,6 @@
#include "gpu/command_buffer/service/async_pixel_transfer_manager.h"
#include "base/memory/ref_counted.h"
-#include "base/memory/scoped_ptr.h"
namespace gfx {
class GLContext;
@@ -32,7 +31,6 @@ class AsyncPixelTransferManagerShareGroup : public AsyncPixelTransferManager {
virtual base::TimeDelta GetTotalTextureUploadTime() OVERRIDE;
virtual void ProcessMorePendingTransfers() OVERRIDE;
virtual bool NeedsProcessMorePendingTransfers() OVERRIDE;
- virtual AsyncPixelTransferDelegate* GetAsyncPixelTransferDelegate() OVERRIDE;
// State shared between Managers and Delegates.
struct SharedState {
@@ -40,13 +38,18 @@ class AsyncPixelTransferManagerShareGroup : public AsyncPixelTransferManager {
~SharedState();
scoped_refptr<AsyncPixelTransferUploadStats> texture_upload_stats;
- typedef std::list<base::WeakPtr<AsyncPixelTransferState> > TransferQueue;
+ typedef std::list<base::WeakPtr<AsyncPixelTransferDelegateShareGroup> >
+ TransferQueue;
TransferQueue pending_allocations;
};
private:
+ // AsyncPixelTransferManager implementation:
+ virtual AsyncPixelTransferDelegate* CreatePixelTransferDelegateImpl(
+ gles2::TextureRef* ref,
+ const AsyncTexImage2DParams& define_params) OVERRIDE;
+
SharedState shared_state_;
- scoped_ptr<AsyncPixelTransferDelegateShareGroup> delegate_;
DISALLOW_COPY_AND_ASSIGN(AsyncPixelTransferManagerShareGroup);
};
diff --git a/gpu/command_buffer/service/async_pixel_transfer_manager_stub.cc b/gpu/command_buffer/service/async_pixel_transfer_manager_stub.cc
index 71338fb..6e4d6a3 100644
--- a/gpu/command_buffer/service/async_pixel_transfer_manager_stub.cc
+++ b/gpu/command_buffer/service/async_pixel_transfer_manager_stub.cc
@@ -8,43 +8,21 @@
namespace gpu {
-namespace {
-
-class AsyncPixelTransferStateImpl : public AsyncPixelTransferState {
- public:
- AsyncPixelTransferStateImpl() {}
-
- // Implement AsyncPixelTransferState:
- virtual bool TransferIsInProgress() OVERRIDE {
- return false;
- }
-
- private:
- virtual ~AsyncPixelTransferStateImpl() {}
-};
-
-} // namespace
-
class AsyncPixelTransferDelegateStub : public AsyncPixelTransferDelegate {
public:
AsyncPixelTransferDelegateStub();
virtual ~AsyncPixelTransferDelegateStub();
// Implement AsyncPixelTransferDelegate:
- virtual AsyncPixelTransferState* CreatePixelTransferState(
- GLuint texture_id,
- const AsyncTexImage2DParams& define_params) 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 bool TransferIsInProgress() OVERRIDE;
+ virtual void WaitForTransferCompletion() OVERRIDE;
private:
DISALLOW_COPY_AND_ASSIGN(AsyncPixelTransferDelegateStub);
@@ -54,14 +32,7 @@ AsyncPixelTransferDelegateStub::AsyncPixelTransferDelegateStub() {}
AsyncPixelTransferDelegateStub::~AsyncPixelTransferDelegateStub() {}
-AsyncPixelTransferState* AsyncPixelTransferDelegateStub::
- CreatePixelTransferState(GLuint texture_id,
- const AsyncTexImage2DParams& define_params) {
- return new AsyncPixelTransferStateImpl;
-}
-
void AsyncPixelTransferDelegateStub::AsyncTexImage2D(
- AsyncPixelTransferState* transfer_state,
const AsyncTexImage2DParams& tex_params,
const AsyncMemoryParams& mem_params,
const base::Closure& bind_callback) {
@@ -69,17 +40,17 @@ void AsyncPixelTransferDelegateStub::AsyncTexImage2D(
}
void AsyncPixelTransferDelegateStub::AsyncTexSubImage2D(
- AsyncPixelTransferState* transfer_state,
const AsyncTexSubImage2DParams& tex_params,
const AsyncMemoryParams& mem_params) {
}
-void AsyncPixelTransferDelegateStub::WaitForTransferCompletion(
- AsyncPixelTransferState* state) {
+bool AsyncPixelTransferDelegateStub::TransferIsInProgress() {
+ return false;
}
-AsyncPixelTransferManagerStub::AsyncPixelTransferManagerStub()
- : delegate_(new AsyncPixelTransferDelegateStub()) {}
+void AsyncPixelTransferDelegateStub::WaitForTransferCompletion() {}
+
+AsyncPixelTransferManagerStub::AsyncPixelTransferManagerStub() {}
AsyncPixelTransferManagerStub::~AsyncPixelTransferManagerStub() {}
@@ -108,8 +79,10 @@ bool AsyncPixelTransferManagerStub::NeedsProcessMorePendingTransfers() {
}
AsyncPixelTransferDelegate*
-AsyncPixelTransferManagerStub::GetAsyncPixelTransferDelegate() {
- return delegate_.get();
+AsyncPixelTransferManagerStub::CreatePixelTransferDelegateImpl(
+ gles2::TextureRef* ref,
+ const AsyncTexImage2DParams& define_params) {
+ return new AsyncPixelTransferDelegateStub();
}
} // 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
index 544c818..39c6a7f 100644
--- a/gpu/command_buffer/service/async_pixel_transfer_manager_stub.h
+++ b/gpu/command_buffer/service/async_pixel_transfer_manager_stub.h
@@ -9,8 +9,6 @@
namespace gpu {
-class AsyncPixelTransferDelegateStub;
-
class AsyncPixelTransferManagerStub : public AsyncPixelTransferManager {
public:
AsyncPixelTransferManagerStub();
@@ -25,10 +23,12 @@ class AsyncPixelTransferManagerStub : public AsyncPixelTransferManager {
virtual base::TimeDelta GetTotalTextureUploadTime() OVERRIDE;
virtual void ProcessMorePendingTransfers() OVERRIDE;
virtual bool NeedsProcessMorePendingTransfers() OVERRIDE;
- virtual AsyncPixelTransferDelegate* GetAsyncPixelTransferDelegate() OVERRIDE;
private:
- scoped_ptr<AsyncPixelTransferDelegateStub> delegate_;
+ // AsyncPixelTransferManager implementation:
+ virtual AsyncPixelTransferDelegate* CreatePixelTransferDelegateImpl(
+ gles2::TextureRef* ref,
+ const AsyncTexImage2DParams& define_params) OVERRIDE;
DISALLOW_COPY_AND_ASSIGN(AsyncPixelTransferManagerStub);
};
diff --git a/gpu/command_buffer/service/async_pixel_transfer_manager_sync.cc b/gpu/command_buffer/service/async_pixel_transfer_manager_sync.cc
index 8f7f3f4..dce95a6 100644
--- a/gpu/command_buffer/service/async_pixel_transfer_manager_sync.cc
+++ b/gpu/command_buffer/service/async_pixel_transfer_manager_sync.cc
@@ -8,23 +8,6 @@
namespace gpu {
-namespace {
-
-class AsyncPixelTransferStateImpl : public AsyncPixelTransferState {
- public:
- AsyncPixelTransferStateImpl() {}
-
- // Implement AsyncPixelTransferState:
- virtual bool TransferIsInProgress() OVERRIDE {
- return false;
- }
-
- private:
- virtual ~AsyncPixelTransferStateImpl() {}
-};
-
-} // namespace
-
// Class which handles async pixel transfers synchronously.
class AsyncPixelTransferDelegateSync : public AsyncPixelTransferDelegate {
public:
@@ -33,20 +16,15 @@ class AsyncPixelTransferDelegateSync : public AsyncPixelTransferDelegate {
virtual ~AsyncPixelTransferDelegateSync();
// Implement AsyncPixelTransferDelegate:
- virtual AsyncPixelTransferState* CreatePixelTransferState(
- GLuint texture_id,
- const AsyncTexImage2DParams& define_params) 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 bool TransferIsInProgress() OVERRIDE;
+ virtual void WaitForTransferCompletion() OVERRIDE;
private:
// Safe to hold a raw pointer because SharedState is owned by the Manager
@@ -62,20 +40,12 @@ AsyncPixelTransferDelegateSync::AsyncPixelTransferDelegateSync(
AsyncPixelTransferDelegateSync::~AsyncPixelTransferDelegateSync() {}
-AsyncPixelTransferState* AsyncPixelTransferDelegateSync::
- CreatePixelTransferState(GLuint texture_id,
- const AsyncTexImage2DParams& define_params) {
- return new AsyncPixelTransferStateImpl;
-}
-
void AsyncPixelTransferDelegateSync::AsyncTexImage2D(
- AsyncPixelTransferState* transfer_state,
const AsyncTexImage2DParams& tex_params,
const AsyncMemoryParams& mem_params,
const base::Closure& bind_callback) {
// Save the define params to return later during deferred
// binding of the transfer texture.
- DCHECK(transfer_state);
void* data = GetAddress(mem_params);
glTexImage2D(
tex_params.target,
@@ -92,11 +62,9 @@ void AsyncPixelTransferDelegateSync::AsyncTexImage2D(
}
void AsyncPixelTransferDelegateSync::AsyncTexSubImage2D(
- AsyncPixelTransferState* transfer_state,
const AsyncTexSubImage2DParams& tex_params,
const AsyncMemoryParams& mem_params) {
void* data = GetAddress(mem_params);
- DCHECK(transfer_state);
base::TimeTicks begin_time(base::TimeTicks::HighResNow());
glTexSubImage2D(
tex_params.target,
@@ -113,8 +81,12 @@ void AsyncPixelTransferDelegateSync::AsyncTexSubImage2D(
base::TimeTicks::HighResNow() - begin_time;
}
-void AsyncPixelTransferDelegateSync::WaitForTransferCompletion(
- AsyncPixelTransferState* state) {
+bool AsyncPixelTransferDelegateSync::TransferIsInProgress() {
+ // Already done.
+ return false;
+}
+
+void AsyncPixelTransferDelegateSync::WaitForTransferCompletion() {
// Already done.
}
@@ -123,8 +95,7 @@ AsyncPixelTransferManagerSync::SharedState::SharedState()
AsyncPixelTransferManagerSync::SharedState::~SharedState() {}
-AsyncPixelTransferManagerSync::AsyncPixelTransferManagerSync()
- : delegate_(new AsyncPixelTransferDelegateSync(&shared_state_)) {}
+AsyncPixelTransferManagerSync::AsyncPixelTransferManagerSync() {}
AsyncPixelTransferManagerSync::~AsyncPixelTransferManagerSync() {}
@@ -154,9 +125,10 @@ bool AsyncPixelTransferManagerSync::NeedsProcessMorePendingTransfers() {
}
AsyncPixelTransferDelegate*
-AsyncPixelTransferManagerSync::GetAsyncPixelTransferDelegate() {
- return delegate_.get();
+AsyncPixelTransferManagerSync::CreatePixelTransferDelegateImpl(
+ gles2::TextureRef* ref,
+ const AsyncTexImage2DParams& define_params) {
+ return new AsyncPixelTransferDelegateSync(&shared_state_);
}
} // 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
index 102f7fb..27d3964 100644
--- a/gpu/command_buffer/service/async_pixel_transfer_manager_sync.h
+++ b/gpu/command_buffer/service/async_pixel_transfer_manager_sync.h
@@ -8,7 +8,6 @@
#include "gpu/command_buffer/service/async_pixel_transfer_manager.h"
namespace gpu {
-class AsyncPixelTransferDelegateSync;
class AsyncPixelTransferManagerSync : public AsyncPixelTransferManager {
public:
@@ -24,7 +23,6 @@ class AsyncPixelTransferManagerSync : public AsyncPixelTransferManager {
virtual base::TimeDelta GetTotalTextureUploadTime() OVERRIDE;
virtual void ProcessMorePendingTransfers() OVERRIDE;
virtual bool NeedsProcessMorePendingTransfers() OVERRIDE;
- virtual AsyncPixelTransferDelegate* GetAsyncPixelTransferDelegate() OVERRIDE;
// State shared between Managers and Delegates.
struct SharedState {
@@ -36,8 +34,12 @@ class AsyncPixelTransferManagerSync : public AsyncPixelTransferManager {
};
private:
+ // AsyncPixelTransferManager implementation:
+ virtual AsyncPixelTransferDelegate* CreatePixelTransferDelegateImpl(
+ gles2::TextureRef* ref,
+ const AsyncTexImage2DParams& define_params) OVERRIDE;
+
SharedState shared_state_;
- scoped_ptr<AsyncPixelTransferDelegateSync> delegate_;
DISALLOW_COPY_AND_ASSIGN(AsyncPixelTransferManagerSync);
};
diff --git a/gpu/command_buffer/service/gles2_cmd_decoder.cc b/gpu/command_buffer/service/gles2_cmd_decoder.cc
index 339c60c..41d7c6d 100644
--- a/gpu/command_buffer/service/gles2_cmd_decoder.cc
+++ b/gpu/command_buffer/service/gles2_cmd_decoder.cc
@@ -599,8 +599,6 @@ class GLES2DecoderImpl : public GLES2Decoder {
virtual void SetStreamTextureManager(StreamTextureManager* manager) OVERRIDE;
- virtual AsyncPixelTransferDelegate*
- GetAsyncPixelTransferDelegate() OVERRIDE;
virtual AsyncPixelTransferManager*
GetAsyncPixelTransferManager() OVERRIDE;
virtual void ResetAsyncPixelTransferManagerForTest() OVERRIDE;
@@ -3071,11 +3069,6 @@ void GLES2DecoderImpl::SetStreamTextureManager(StreamTextureManager* manager) {
stream_texture_manager_ = manager;
}
-AsyncPixelTransferDelegate*
- GLES2DecoderImpl::GetAsyncPixelTransferDelegate() {
- return async_pixel_transfer_manager_->GetAsyncPixelTransferDelegate();
-}
-
AsyncPixelTransferManager*
GLES2DecoderImpl::GetAsyncPixelTransferManager() {
return async_pixel_transfer_manager_.get();
@@ -10204,13 +10197,12 @@ error::Error GLES2DecoderImpl::HandleAsyncTexImage2DCHROMIUM(
// Set up the async state if needed, and make the texture
// immutable so the async state stays valid. The level info
// is set up lazily when the transfer completes.
- AsyncPixelTransferState* state =
- async_pixel_transfer_manager_->CreatePixelTransferState(texture_ref,
- tex_params);
+ AsyncPixelTransferDelegate* delegate =
+ async_pixel_transfer_manager_->CreatePixelTransferDelegate(texture_ref,
+ tex_params);
texture->SetImmutable(true);
- GetAsyncPixelTransferDelegate()->AsyncTexImage2D(
- state,
+ delegate->AsyncTexImage2D(
tex_params,
mem_params,
base::Bind(&TextureManager::SetLevelInfoFromParams,
@@ -10289,9 +10281,9 @@ error::Error GLES2DecoderImpl::HandleAsyncTexSubImage2DCHROMIUM(
width, height, format, type};
AsyncMemoryParams mem_params = {shared_memory, shm_size,
shm_data_offset, shm_data_size};
- AsyncPixelTransferState* state =
- async_pixel_transfer_manager_->GetPixelTransferState(texture_ref);
- if (!state) {
+ AsyncPixelTransferDelegate* delegate =
+ async_pixel_transfer_manager_->GetPixelTransferDelegate(texture_ref);
+ if (!delegate) {
// TODO(epenner): We may want to enforce exclusive use
// of async APIs in which case this should become an error,
// (the texture should have been async defined).
@@ -10303,13 +10295,12 @@ error::Error GLES2DecoderImpl::HandleAsyncTexSubImage2DCHROMIUM(
&define_params.internal_format);
// Set up the async state if needed, and make the texture
// immutable so the async state stays valid.
- state = async_pixel_transfer_manager_->CreatePixelTransferState(
+ delegate = async_pixel_transfer_manager_->CreatePixelTransferDelegate(
texture_ref, define_params);
texture->SetImmutable(true);
}
- GetAsyncPixelTransferDelegate()->AsyncTexSubImage2D(
- state, tex_params, mem_params);
+ delegate->AsyncTexSubImage2D(tex_params, mem_params);
return error::kNoError;
}
@@ -10330,15 +10321,15 @@ error::Error GLES2DecoderImpl::HandleWaitAsyncTexImage2DCHROMIUM(
"glWaitAsyncTexImage2DCHROMIUM", "unknown texture");
return error::kNoError;
}
- AsyncPixelTransferState* state =
- async_pixel_transfer_manager_->GetPixelTransferState(texture_ref);
- if (!state) {
+ AsyncPixelTransferDelegate* delegate =
+ async_pixel_transfer_manager_->GetPixelTransferDelegate(texture_ref);
+ if (!delegate) {
LOCAL_SET_GL_ERROR(
GL_INVALID_OPERATION,
"glWaitAsyncTexImage2DCHROMIUM", "No async transfer started");
return error::kNoError;
}
- GetAsyncPixelTransferDelegate()->WaitForTransferCompletion(state);
+ delegate->WaitForTransferCompletion();
ProcessFinishedAsyncTransfers();
return error::kNoError;
}
diff --git a/gpu/command_buffer/service/gles2_cmd_decoder.h b/gpu/command_buffer/service/gles2_cmd_decoder.h
index b187b58..83647a3 100644
--- a/gpu/command_buffer/service/gles2_cmd_decoder.h
+++ b/gpu/command_buffer/service/gles2_cmd_decoder.h
@@ -179,7 +179,6 @@ class GPU_EXPORT GLES2Decoder : public base::SupportsWeakPtr<GLES2Decoder>,
virtual void SetStreamTextureManager(StreamTextureManager* manager) = 0;
// Interface to performing async pixel transfers.
- virtual AsyncPixelTransferDelegate* GetAsyncPixelTransferDelegate() = 0;
virtual AsyncPixelTransferManager* GetAsyncPixelTransferManager() = 0;
virtual void ResetAsyncPixelTransferManagerForTest() = 0;
virtual void SetAsyncPixelTransferManagerForTest(
diff --git a/gpu/command_buffer/service/gles2_cmd_decoder_unittest.cc b/gpu/command_buffer/service/gles2_cmd_decoder_unittest.cc
index b03d9f9..313323b 100644
--- a/gpu/command_buffer/service/gles2_cmd_decoder_unittest.cc
+++ b/gpu/command_buffer/service/gles2_cmd_decoder_unittest.cc
@@ -8086,11 +8086,7 @@ TEST_F(GLES2DecoderManualInitTest, AsyncPixelTransfers) {
new StrictMock<gpu::MockAsyncPixelTransferManager>;
manager->Initialize(group().texture_manager());
decoder_->SetAsyncPixelTransferManagerForTest(manager);
- scoped_ptr<StrictMock<gpu::MockAsyncPixelTransferDelegate> > delegate(
- new StrictMock<gpu::MockAsyncPixelTransferDelegate>);
- EXPECT_CALL(*manager, GetAsyncPixelTransferDelegate())
- .WillRepeatedly(Return(delegate.get()));
- StrictMock<gpu::MockAsyncPixelTransferState>* state = NULL;
+ StrictMock<gpu::MockAsyncPixelTransferDelegate>* delegate = NULL;
// Tex(Sub)Image2D upload commands.
AsyncTexImage2DCHROMIUM teximage_cmd;
@@ -8103,26 +8099,29 @@ TEST_F(GLES2DecoderManualInitTest, AsyncPixelTransfers) {
wait_cmd.Init(GL_TEXTURE_2D);
// No transfer state exists initially.
- EXPECT_FALSE(decoder_->GetAsyncPixelTransferManager()->GetPixelTransferState(
- texture_ref));
+ EXPECT_FALSE(
+ decoder_->GetAsyncPixelTransferManager()->GetPixelTransferDelegate(
+ texture_ref));
base::Closure bind_callback;
// AsyncTexImage2D
{
// Create transfer state since it doesn't exist.
- EXPECT_CALL(*delegate, CreatePixelTransferState(kServiceTextureId, _))
+ EXPECT_CALL(*manager, CreatePixelTransferDelegateImpl(texture_ref, _))
.WillOnce(Return(
- state = new StrictMock<gpu::MockAsyncPixelTransferState>))
+ delegate = new StrictMock<gpu::MockAsyncPixelTransferDelegate>))
.RetiresOnSaturation();
- EXPECT_CALL(*delegate, AsyncTexImage2D(state, _, _, _))
- .WillOnce(SaveArg<3>(&bind_callback))
+ EXPECT_CALL(*delegate, AsyncTexImage2D(_, _, _))
+ .WillOnce(SaveArg<2>(&bind_callback))
.RetiresOnSaturation();
// Command succeeds.
EXPECT_EQ(error::kNoError, ExecuteCmd(teximage_cmd));
EXPECT_EQ(GL_NO_ERROR, GetGLError());
- EXPECT_TRUE(decoder_->GetAsyncPixelTransferManager()->GetPixelTransferState(
- texture_ref));
+ EXPECT_EQ(
+ delegate,
+ decoder_->GetAsyncPixelTransferManager()->GetPixelTransferDelegate(
+ texture_ref));
EXPECT_TRUE(texture->IsImmutable());
// The texture is safe but the level has not been defined yet.
EXPECT_TRUE(texture->SafeToRenderFrom());
@@ -8134,15 +8133,17 @@ TEST_F(GLES2DecoderManualInitTest, AsyncPixelTransfers) {
// Command fails.
EXPECT_EQ(error::kNoError, ExecuteCmd(teximage_cmd));
EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
- EXPECT_TRUE(decoder_->GetAsyncPixelTransferManager()->GetPixelTransferState(
- texture_ref));
+ EXPECT_EQ(
+ delegate,
+ decoder_->GetAsyncPixelTransferManager()->GetPixelTransferDelegate(
+ texture_ref));
EXPECT_TRUE(texture->IsImmutable());
EXPECT_TRUE(texture->SafeToRenderFrom());
}
// Binding/defining of the async transfer
{
- // TODO(epenner): We should check that the delegate gets the
+ // TODO(epenner): We should check that the manager gets the
// BindCompletedAsyncTransfers() call, which is required to
// guarantee the delegate calls the bind callback.
@@ -8160,62 +8161,68 @@ TEST_F(GLES2DecoderManualInitTest, AsyncPixelTransfers) {
// AsyncTexSubImage2D
decoder_->GetAsyncPixelTransferManager()
- ->ClearPixelTransferStateForTest(texture_ref);
+ ->ClearPixelTransferDelegateForTest(texture_ref);
texture->SetImmutable(false);
{
// Create transfer state since it doesn't exist.
- EXPECT_CALL(*delegate, CreatePixelTransferState(kServiceTextureId, _))
+ EXPECT_CALL(*manager, CreatePixelTransferDelegateImpl(texture_ref, _))
.WillOnce(Return(
- state = new StrictMock<gpu::MockAsyncPixelTransferState>))
+ delegate = new StrictMock<gpu::MockAsyncPixelTransferDelegate>))
.RetiresOnSaturation();
- EXPECT_CALL(*delegate, AsyncTexSubImage2D(state, _, _))
+ EXPECT_CALL(*delegate, AsyncTexSubImage2D(_, _))
.RetiresOnSaturation();
// Command succeeds.
EXPECT_EQ(error::kNoError, ExecuteCmd(texsubimage_cmd));
EXPECT_EQ(GL_NO_ERROR, GetGLError());
- EXPECT_TRUE(decoder_->GetAsyncPixelTransferManager()->GetPixelTransferState(
- texture_ref));
+ EXPECT_EQ(
+ delegate,
+ decoder_->GetAsyncPixelTransferManager()->GetPixelTransferDelegate(
+ texture_ref));
EXPECT_TRUE(texture->IsImmutable());
EXPECT_TRUE(texture->SafeToRenderFrom());
}
{
// No transfer is in progress.
- EXPECT_CALL(*state, TransferIsInProgress())
+ EXPECT_CALL(*delegate, TransferIsInProgress())
.WillOnce(Return(false)) // texSubImage validation
.WillOnce(Return(false)) // async validation
.RetiresOnSaturation();
- EXPECT_CALL(*delegate, AsyncTexSubImage2D(state, _, _))
+ EXPECT_CALL(*delegate, AsyncTexSubImage2D(_, _))
.RetiresOnSaturation();
// Command succeeds.
EXPECT_EQ(error::kNoError, ExecuteCmd(texsubimage_cmd));
EXPECT_EQ(GL_NO_ERROR, GetGLError());
- EXPECT_TRUE(decoder_->GetAsyncPixelTransferManager()->GetPixelTransferState(
- texture_ref));
+ EXPECT_EQ(
+ delegate,
+ decoder_->GetAsyncPixelTransferManager()->GetPixelTransferDelegate(
+ texture_ref));
EXPECT_TRUE(texture->IsImmutable());
EXPECT_TRUE(texture->SafeToRenderFrom());
}
{
// A transfer is still in progress!
- EXPECT_CALL(*state, TransferIsInProgress())
+ EXPECT_CALL(*delegate, TransferIsInProgress())
.WillOnce(Return(true))
.RetiresOnSaturation();
// No async call, command fails.
EXPECT_EQ(error::kNoError, ExecuteCmd(texsubimage_cmd));
EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
- EXPECT_TRUE(decoder_->GetAsyncPixelTransferManager()->GetPixelTransferState(
- texture_ref));
+ EXPECT_EQ(
+ delegate,
+ decoder_->GetAsyncPixelTransferManager()->GetPixelTransferDelegate(
+ texture_ref));
EXPECT_TRUE(texture->IsImmutable());
EXPECT_TRUE(texture->SafeToRenderFrom());
}
- // Delete state on DeleteTexture.
+ // Delete delegate on DeleteTexture.
{
- EXPECT_CALL(*state, Destroy()).RetiresOnSaturation();
+ EXPECT_CALL(*delegate, Destroy()).RetiresOnSaturation();
DoDeleteTexture(client_texture_id_, kServiceTextureId);
EXPECT_FALSE(
- decoder_->GetAsyncPixelTransferManager()->GetPixelTransferState(
+ decoder_->GetAsyncPixelTransferManager()->GetPixelTransferDelegate(
texture_ref));
- state = NULL;
+ delegate = NULL;
}
// WaitAsyncTexImage2D
@@ -8227,25 +8234,25 @@ TEST_F(GLES2DecoderManualInitTest, AsyncPixelTransfers) {
DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId);
texture_ref = GetTexture(client_texture_id_);
texture = texture_ref->texture();
- decoder_->GetAsyncPixelTransferManager()
- ->ClearPixelTransferStateForTest(texture_ref);
texture->SetImmutable(false);
// Create transfer state since it doesn't exist.
- EXPECT_CALL(*delegate, CreatePixelTransferState(kServiceTextureId, _))
+ EXPECT_CALL(*manager, CreatePixelTransferDelegateImpl(texture_ref, _))
.WillOnce(Return(
- state = new StrictMock<gpu::MockAsyncPixelTransferState>))
+ delegate = new StrictMock<gpu::MockAsyncPixelTransferDelegate>))
.RetiresOnSaturation();
- EXPECT_CALL(*delegate, AsyncTexImage2D(state, _, _, _))
+ EXPECT_CALL(*delegate, AsyncTexImage2D(_, _, _))
.RetiresOnSaturation();
// Start async transfer.
EXPECT_EQ(error::kNoError, ExecuteCmd(teximage_cmd));
EXPECT_EQ(GL_NO_ERROR, GetGLError());
- EXPECT_TRUE(decoder_->GetAsyncPixelTransferManager()->GetPixelTransferState(
- texture_ref));
+ EXPECT_EQ(
+ delegate,
+ decoder_->GetAsyncPixelTransferManager()->GetPixelTransferDelegate(
+ texture_ref));
EXPECT_TRUE(texture->IsImmutable());
// Wait for completion.
- EXPECT_CALL(*delegate, WaitForTransferCompletion(state));
+ EXPECT_CALL(*delegate, WaitForTransferCompletion());
EXPECT_CALL(*manager, BindCompletedAsyncTransfers());
EXPECT_EQ(error::kNoError, ExecuteCmd(wait_cmd));
EXPECT_EQ(GL_NO_ERROR, GetGLError());
@@ -8268,42 +8275,38 @@ TEST_F(GLES2DecoderManualInitTest, AsyncPixelTransferManager) {
new StrictMock<gpu::MockAsyncPixelTransferManager>;
manager->Initialize(group().texture_manager());
decoder_->SetAsyncPixelTransferManagerForTest(manager);
- scoped_ptr<StrictMock<gpu::MockAsyncPixelTransferDelegate> > delegate(
- new StrictMock<gpu::MockAsyncPixelTransferDelegate>);
- EXPECT_CALL(*manager, GetAsyncPixelTransferDelegate())
- .WillRepeatedly(Return(delegate.get()));
- StrictMock<gpu::MockAsyncPixelTransferState>* state = NULL;
+ StrictMock<gpu::MockAsyncPixelTransferDelegate>* delegate = NULL;
AsyncTexImage2DCHROMIUM teximage_cmd;
teximage_cmd.Init(GL_TEXTURE_2D, 0, GL_RGBA, 8, 8, 0, GL_RGBA,
GL_UNSIGNED_BYTE, kSharedMemoryId, kSharedMemoryOffset);
- // No transfer state exists initially.
- EXPECT_FALSE(decoder_->GetAsyncPixelTransferManager()->GetPixelTransferState(
- texture_ref));
+ // No transfer delegate exists initially.
+ EXPECT_FALSE(
+ decoder_->GetAsyncPixelTransferManager()->GetPixelTransferDelegate(
+ texture_ref));
- // Create state on AsyncTexImage2D.
+ // Create delegate on AsyncTexImage2D.
{
- EXPECT_CALL(*delegate, CreatePixelTransferState(kServiceTextureId, _))
- .WillOnce(
- Return(state = new StrictMock<gpu::MockAsyncPixelTransferState>))
- .RetiresOnSaturation();
- EXPECT_CALL(*delegate, AsyncTexImage2D(state, _, _, _))
+ EXPECT_CALL(*manager, CreatePixelTransferDelegateImpl(texture_ref, _))
+ .WillOnce(Return(
+ delegate = new StrictMock<gpu::MockAsyncPixelTransferDelegate>))
.RetiresOnSaturation();
+ EXPECT_CALL(*delegate, AsyncTexImage2D(_, _, _)).RetiresOnSaturation();
// Command succeeds.
EXPECT_EQ(error::kNoError, ExecuteCmd(teximage_cmd));
EXPECT_EQ(GL_NO_ERROR, GetGLError());
}
- // State is cached.
- EXPECT_EQ(state,
- decoder_->GetAsyncPixelTransferManager()->GetPixelTransferState(
+ // Delegate is cached.
+ EXPECT_EQ(delegate,
+ decoder_->GetAsyncPixelTransferManager()->GetPixelTransferDelegate(
texture_ref));
- // Delete state on manager teardown.
+ // Delete delegate on manager teardown.
{
- EXPECT_CALL(*state, Destroy()).RetiresOnSaturation();
+ EXPECT_CALL(*delegate, Destroy()).RetiresOnSaturation();
decoder_->ResetAsyncPixelTransferManagerForTest();
// Texture ref still valid.