Index: ui/gl/async_pixel_transfer_delegate_stub.cc |
diff --git a/ui/gl/async_pixel_transfer_delegate_stub.cc b/ui/gl/async_pixel_transfer_delegate_stub.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..9d2fd866df36f7c91becdd67ba2b48bbe253db75 |
--- /dev/null |
+++ b/ui/gl/async_pixel_transfer_delegate_stub.cc |
@@ -0,0 +1,100 @@ |
+// Copyright (c) 2012 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 "ui/gl/async_pixel_transfer_delegate_stub.h" |
+ |
+#include "base/bind.h" |
+#include "base/lazy_instance.h" |
+#include "base/memory/scoped_ptr.h" |
+#include "base/shared_memory.h" |
+#include "build/build_config.h" |
+#include "third_party/angle/include/EGL/egl.h" |
+#include "third_party/angle/include/EGL/eglext.h" |
+#include "ui/gl/async_pixel_transfer_delegate.h" |
+#include "ui/gl/gl_bindings.h" |
+ |
+using base::SharedMemory; |
+using base::SharedMemoryHandle; |
+ |
+// Gets the address of the data from shared memory. |
+void* GetAddress(SharedMemory* shared_memory, |
greggman
2012/12/12 03:51:36
style: this wants to be in an anonymous namespace
epennerAtGoogle
2012/12/12 04:49:49
Done.
|
+ uint32 shm_size, |
+ uint32 shm_data_offset, |
+ uint32 shm_data_size) { |
+ // Memory bounds have already been validated, so there |
+ // is just DCHECKS here. |
+ DCHECK(shared_memory); |
+ DCHECK(shared_memory->memory()); |
+ DCHECK_LE(shm_data_offset + shm_data_size, shm_size); |
+ return static_cast<int8*>(shared_memory->memory()) + shm_data_offset; |
+} |
+ |
+namespace gfx { |
+ |
+class AsyncTransferStateStub : public AsyncPixelTransferState { |
+ public: |
+ explicit AsyncTransferStateStub(GLuint texture_id) {} |
+ // implement AsyncPixelTransferState: |
+ virtual bool TransferIsInProgress() { return false; } |
+ virtual bool BindAsyncTransferToTexture(GLenum target) { return true; } |
+ |
+ private: |
+ virtual ~AsyncTransferStateStub() {} |
+ DISALLOW_COPY_AND_ASSIGN(AsyncTransferStateStub); |
+}; |
+ |
+// Class which handles async pixel transfers on Android (using |
+// EGLImageKHR and another upload thread) |
+class AsyncPixelTransferDelegateStub : public AsyncPixelTransferDelegate { |
+ public: |
+ AsyncPixelTransferDelegateStub() {} |
+ virtual ~AsyncPixelTransferDelegateStub() {} |
+ |
+ // implement AsyncPixelTransferDelegate: |
+ virtual scoped_refptr<AsyncPixelTransferState> |
+ CreatePixelTransferState(GLuint texture_id) OVERRIDE { |
+ return make_scoped_refptr( |
+ static_cast<AsyncPixelTransferState*>( |
+ new AsyncTransferStateStub(texture_id))); |
+ } |
+ |
+ virtual void AsyncNotifyCompletion( |
+ const base::Closure& task) OVERRIDE { |
+ task.Run(); |
+ } |
+ |
+ virtual void AsyncTexImage2D( |
+ AsyncPixelTransferState*, |
+ AsyncTexImage2DParams t, |
greggman
2012/12/12 03:51:36
style: single letter names are discouraged in the
epennerAtGoogle
2012/12/12 04:49:49
Done.
|
+ AsyncMemoryParams m) { |
+ void* data = GetAddress(m.shared_memory, m.shm_size, |
+ m.shm_data_offset, m.shm_data_size); |
+ glTexImage2D( |
greggman
2012/12/12 03:51:36
I'm a little confused. This is temporary impl that
epennerAtGoogle
2012/12/12 04:49:49
Yes this is a stub that allows the API to work by
|
+ t.target, t.level, t.internal_format, |
+ t.width, t.height, t.border, t.format, t.type, data); |
+ } |
+ |
+ virtual void AsyncTexSubImage2D( |
+ AsyncPixelTransferState*, |
+ AsyncTexSubImage2DParams t, |
+ AsyncMemoryParams m) { |
+ void* data = GetAddress(m.shared_memory, m.shm_size, |
+ m.shm_data_offset, m.shm_data_size); |
+ glTexSubImage2D( |
+ t.target, t.level, t.xoffset, t.yoffset, |
+ t.width, t.height, t.format, t.type, data); |
+ } |
+ |
+ private: |
+ DISALLOW_COPY_AND_ASSIGN(AsyncPixelTransferDelegateStub); |
+}; |
+ |
+scoped_ptr<AsyncPixelTransferDelegate> AsyncPixelTransferDelegate::Create() { |
+ return make_scoped_ptr( |
+ static_cast<AsyncPixelTransferDelegate*>( |
+ new AsyncPixelTransferDelegateStub())); |
+} |
+ |
+} // namespace gfx |
+ |