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

Unified Diff: content/common/gpu/gpu_memory_buffer_factory_surface_texture.cc

Issue 1846253003: Revert of Refactor content/common/gpu into gpu/ipc/service (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 9 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/gpu_memory_buffer_factory_surface_texture.cc
diff --git a/content/common/gpu/gpu_memory_buffer_factory_surface_texture.cc b/content/common/gpu/gpu_memory_buffer_factory_surface_texture.cc
new file mode 100644
index 0000000000000000000000000000000000000000..eb4b0a3c8dad332cfee69bf37523cf7b0e74594e
--- /dev/null
+++ b/content/common/gpu/gpu_memory_buffer_factory_surface_texture.cc
@@ -0,0 +1,108 @@
+// 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/gpu_memory_buffer_factory_surface_texture.h"
+
+#include "gpu/ipc/common/android/surface_texture_manager.h"
+#include "ui/gl/android/surface_texture.h"
+#include "ui/gl/gl_image_surface_texture.h"
+
+namespace content {
+
+GpuMemoryBufferFactorySurfaceTexture::GpuMemoryBufferFactorySurfaceTexture() {
+}
+
+GpuMemoryBufferFactorySurfaceTexture::~GpuMemoryBufferFactorySurfaceTexture() {
+}
+
+gfx::GpuMemoryBufferHandle
+GpuMemoryBufferFactorySurfaceTexture::CreateGpuMemoryBuffer(
+ gfx::GpuMemoryBufferId id,
+ const gfx::Size& size,
+ gfx::BufferFormat format,
+ gfx::BufferUsage usage,
+ int client_id,
+ gpu::SurfaceHandle surface_handle) {
+ // Note: this needs to be 0 as the surface texture implemenation will take
+ // ownership of the texture and call glDeleteTextures when the GPU service
+ // attaches the surface texture to a real texture id. glDeleteTextures
+ // silently ignores 0.
+ const int kDummyTextureId = 0;
+ scoped_refptr<gfx::SurfaceTexture> surface_texture =
+ gfx::SurfaceTexture::Create(kDummyTextureId);
+ if (!surface_texture.get())
+ return gfx::GpuMemoryBufferHandle();
+
+ gpu::SurfaceTextureManager::GetInstance()->RegisterSurfaceTexture(
+ id.id, client_id, surface_texture.get());
+
+ {
+ base::AutoLock lock(surface_textures_lock_);
+
+ SurfaceTextureMapKey key(id.id, client_id);
+ DCHECK(surface_textures_.find(key) == surface_textures_.end());
+ surface_textures_[key] = surface_texture;
+ }
+
+ gfx::GpuMemoryBufferHandle handle;
+ handle.type = gfx::SURFACE_TEXTURE_BUFFER;
+ handle.id = id;
+ return handle;
+}
+
+gfx::GpuMemoryBufferHandle
+GpuMemoryBufferFactorySurfaceTexture::CreateGpuMemoryBufferFromHandle(
+ const gfx::GpuMemoryBufferHandle& handle,
+ gfx::GpuMemoryBufferId id,
+ const gfx::Size& size,
+ gfx::BufferFormat format,
+ int client_id) {
+ NOTIMPLEMENTED();
+ return gfx::GpuMemoryBufferHandle();
+}
+
+void GpuMemoryBufferFactorySurfaceTexture::DestroyGpuMemoryBuffer(
+ gfx::GpuMemoryBufferId id,
+ int client_id) {
+ {
+ base::AutoLock lock(surface_textures_lock_);
+
+ SurfaceTextureMapKey key(id.id, client_id);
+ DCHECK(surface_textures_.find(key) != surface_textures_.end());
+ surface_textures_.erase(key);
+ }
+
+ gpu::SurfaceTextureManager::GetInstance()->UnregisterSurfaceTexture(
+ id.id, client_id);
+}
+
+gpu::ImageFactory* GpuMemoryBufferFactorySurfaceTexture::AsImageFactory() {
+ return this;
+}
+
+scoped_refptr<gl::GLImage>
+GpuMemoryBufferFactorySurfaceTexture::CreateImageForGpuMemoryBuffer(
+ const gfx::GpuMemoryBufferHandle& handle,
+ const gfx::Size& size,
+ gfx::BufferFormat format,
+ unsigned internalformat,
+ int client_id) {
+ base::AutoLock lock(surface_textures_lock_);
+
+ DCHECK_EQ(handle.type, gfx::SURFACE_TEXTURE_BUFFER);
+
+ SurfaceTextureMapKey key(handle.id.id, client_id);
+ SurfaceTextureMap::iterator it = surface_textures_.find(key);
+ if (it == surface_textures_.end())
+ return scoped_refptr<gl::GLImage>();
+
+ scoped_refptr<gl::GLImageSurfaceTexture> image(
+ new gl::GLImageSurfaceTexture(size));
+ if (!image->Initialize(it->second.get()))
+ return scoped_refptr<gl::GLImage>();
+
+ return image;
+}
+
+} // namespace content

Powered by Google App Engine
This is Rietveld 408576698