Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(402)

Unified Diff: content/common/gpu/client/gpu_memory_buffer_impl_surface_texture.cc

Issue 177953004: Enable SurfaceTexture based zero-copy texture uploading on Android platform Base URL: http://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: content/common/gpu/client/gpu_memory_buffer_impl_surface_texture.cc
diff --git a/content/common/gpu/client/gpu_memory_buffer_impl_surface_texture.cc b/content/common/gpu/client/gpu_memory_buffer_impl_surface_texture.cc
new file mode 100644
index 0000000000000000000000000000000000000000..5fad9aa70ac113ff8eb275091618d72c3a0bae86
--- /dev/null
+++ b/content/common/gpu/client/gpu_memory_buffer_impl_surface_texture.cc
@@ -0,0 +1,83 @@
+// Copyright 2014 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 "content/common/gpu/client/gpu_memory_buffer_impl_surface_texture.h"
+
+#include "base/logging.h"
+#include <android/native_window_jni.h>
+
+namespace content {
+
+GpuMemoryBufferImplSurfaceTexture::GpuMemoryBufferImplSurfaceTexture(
+ gfx::Size size,
+ unsigned internalformat)
+ : GpuMemoryBufferImpl(size, internalformat),
+ texture_id_(0),
+ native_window_(NULL),
+ stride_(0),
+ stride_updated_(false) {}
+
+GpuMemoryBufferImplSurfaceTexture::~GpuMemoryBufferImplSurfaceTexture() {}
+
+bool GpuMemoryBufferImplSurfaceTexture::Initialize(
+ gfx::GpuMemoryBufferHandle handle) {
+ texture_id_ = handle.texture_id;
+ surface_texture_ =
+ reinterpret_cast<gfx::SurfaceTexture*>(handle.surface_texture_handle);
+ stride_ = GpuMemoryBufferImpl::GetStride();
+ return true;
+}
+
+void GpuMemoryBufferImplSurfaceTexture::setNativeWindow(ANativeWindow* window) {
+ native_window_ = window;
+ if (native_window_) {
+ if (ANativeWindow_setBuffersGeometry(native_window_,
+ size_.width(),
+ size_.height(),
+ WINDOW_FORMAT_RGBA_8888))
+ return;
Hongbo Min 2014/03/18 06:10:03 Error log if ANativeWindow_setBuffersGeometry fail
+ }
+}
+
+void GpuMemoryBufferImplSurfaceTexture::Map(AccessMode mode, void** vaddr) {
+ DCHECK(!mapped_);
+ *vaddr = NULL;
+ if (!native_window_)
Hongbo Min 2014/03/18 06:10:03 Need to return if it is already mapped.
+ return;
+ ANativeWindow_Buffer buffer;
+ if (ANativeWindow_lock(native_window_, &buffer, 0))
Hongbo Min 2014/03/18 06:10:03 It may need to have a pair calling of ANativeWindo
+ return;
+
+ *vaddr = reinterpret_cast<void*>(buffer.bits);
+ stride_ = buffer.stride * 4;
+ stride_updated_ = true;
+ mapped_ = true;
+}
+
+uint32 GpuMemoryBufferImplSurfaceTexture::GetStride() const {
+ if (!stride_updated_) {
+ LOG(WARNING) << "stride is not updated, a default stride is returned.";
+ LOG(WARNING) << "stride is: " << stride_ << ", width is " << size_.width();
+ }
+ return stride_;
+}
+
+void GpuMemoryBufferImplSurfaceTexture::Unmap() {
+ DCHECK(mapped_);
+ if (!native_window_)
Hongbo Min 2014/03/18 06:10:03 Does it also need to return if 'mapped' is false?
+ return;
+ ANativeWindow_unlockAndPost(native_window_);
+ mapped_ = false;
+}
+
+gfx::GpuMemoryBufferHandle GpuMemoryBufferImplSurfaceTexture::GetHandle()
+ const {
+ gfx::GpuMemoryBufferHandle handle;
+ handle.type = gfx::SURFACE_TEXTURE_BUFFER;
+ handle.texture_id = texture_id_;
+ handle.surface_texture_handle = reinterpret_cast<void*>(surface_texture_);
+ return handle;
+}
+
+} // namespace content

Powered by Google App Engine
This is Rietveld 408576698