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

Side by Side Diff: content/common/gpu/client/gpu_memory_buffer_impl_surface_texture.cc

Issue 1412223009: Reland: GpuMemoryBuffer interface change: Map(**) to Map() and memory(plane); stride(plane) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Win X64 compile fix Created 5 years, 1 month 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 unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "content/common/gpu/client/gpu_memory_buffer_impl_surface_texture.h" 5 #include "content/common/gpu/client/gpu_memory_buffer_impl_surface_texture.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/trace_event/trace_event.h" 8 #include "base/trace_event/trace_event.h"
9 #include "content/common/android/surface_texture_manager.h" 9 #include "content/common/android/surface_texture_manager.h"
10 #include "content/common/gpu/gpu_memory_buffer_factory_surface_texture.h" 10 #include "content/common/gpu/gpu_memory_buffer_factory_surface_texture.h"
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
47 47
48 } // namespace 48 } // namespace
49 49
50 GpuMemoryBufferImplSurfaceTexture::GpuMemoryBufferImplSurfaceTexture( 50 GpuMemoryBufferImplSurfaceTexture::GpuMemoryBufferImplSurfaceTexture(
51 gfx::GpuMemoryBufferId id, 51 gfx::GpuMemoryBufferId id,
52 const gfx::Size& size, 52 const gfx::Size& size,
53 gfx::BufferFormat format, 53 gfx::BufferFormat format,
54 const DestructionCallback& callback, 54 const DestructionCallback& callback,
55 ANativeWindow* native_window) 55 ANativeWindow* native_window)
56 : GpuMemoryBufferImpl(id, size, format, callback), 56 : GpuMemoryBufferImpl(id, size, format, callback),
57 native_window_(native_window), 57 native_window_(native_window) {}
58 stride_(0) {}
59 58
60 GpuMemoryBufferImplSurfaceTexture::~GpuMemoryBufferImplSurfaceTexture() { 59 GpuMemoryBufferImplSurfaceTexture::~GpuMemoryBufferImplSurfaceTexture() {
61 ANativeWindow_release(native_window_); 60 ANativeWindow_release(native_window_);
62 } 61 }
63 62
64 // static 63 // static
65 scoped_ptr<GpuMemoryBufferImplSurfaceTexture> 64 scoped_ptr<GpuMemoryBufferImplSurfaceTexture>
66 GpuMemoryBufferImplSurfaceTexture::CreateFromHandle( 65 GpuMemoryBufferImplSurfaceTexture::CreateFromHandle(
67 const gfx::GpuMemoryBufferHandle& handle, 66 const gfx::GpuMemoryBufferHandle& handle,
68 const gfx::Size& size, 67 const gfx::Size& size,
(...skipping 23 matching lines...) Expand all
92 91
93 // static 92 // static
94 base::Closure GpuMemoryBufferImplSurfaceTexture::AllocateForTesting( 93 base::Closure GpuMemoryBufferImplSurfaceTexture::AllocateForTesting(
95 const gfx::Size& size, 94 const gfx::Size& size,
96 gfx::BufferFormat format, 95 gfx::BufferFormat format,
97 gfx::BufferUsage usage, 96 gfx::BufferUsage usage,
98 gfx::GpuMemoryBufferHandle* handle) { 97 gfx::GpuMemoryBufferHandle* handle) {
99 scoped_refptr<gfx::SurfaceTexture> surface_texture = 98 scoped_refptr<gfx::SurfaceTexture> surface_texture =
100 gfx::SurfaceTexture::Create(0); 99 gfx::SurfaceTexture::Create(0);
101 DCHECK(surface_texture); 100 DCHECK(surface_texture);
102 gfx::GpuMemoryBufferId kBufferId(1); 101 const gfx::GpuMemoryBufferId kBufferId(1);
103 SurfaceTextureManager::GetInstance()->RegisterSurfaceTexture( 102 SurfaceTextureManager::GetInstance()->RegisterSurfaceTexture(
104 kBufferId.id, 0, surface_texture.get()); 103 kBufferId.id, 0, surface_texture.get());
105 handle->type = gfx::SURFACE_TEXTURE_BUFFER; 104 handle->type = gfx::SURFACE_TEXTURE_BUFFER;
106 handle->id = kBufferId; 105 handle->id = kBufferId;
107 return base::Bind(&FreeSurfaceTextureForTesting, surface_texture, kBufferId); 106 return base::Bind(&FreeSurfaceTextureForTesting, surface_texture, kBufferId);
108 } 107 }
109 108
110 bool GpuMemoryBufferImplSurfaceTexture::Map(void** data) { 109 bool GpuMemoryBufferImplSurfaceTexture::Map() {
111 TRACE_EVENT0("gpu", "GpuMemoryBufferImplSurfaceTexture::Map"); 110 TRACE_EVENT0("gpu", "GpuMemoryBufferImplSurfaceTexture::Map");
112
113 DCHECK(!mapped_); 111 DCHECK(!mapped_);
114 DCHECK(native_window_); 112 DCHECK(native_window_);
115 ANativeWindow_Buffer buffer; 113 if (ANativeWindow_lock(native_window_, &buffer_, NULL)) {
116 int status = ANativeWindow_lock(native_window_, &buffer, NULL); 114 DPLOG(ERROR) << "ANativeWindow_lock failed";
117 if (status) {
118 VLOG(1) << "ANativeWindow_lock failed with error code: " << status;
119 return false; 115 return false;
120 } 116 }
117 DCHECK_LE(size_.width(), buffer_.stride);
118 mapped_ = true;
119 return true;
120 }
121 121
122 DCHECK_LE(size_.width(), buffer.stride); 122 void* GpuMemoryBufferImplSurfaceTexture::memory(size_t plane) {
123 stride_ = gfx::RowSizeForBufferFormat(buffer.stride, format_, 0); 123 TRACE_EVENT0("gpu", "GpuMemoryBufferImplSurfaceTexture::memory");
124 mapped_ = true; 124 DCHECK(mapped_);
125 *data = buffer.bits; 125 DCHECK_EQ(0u, plane);
126 return true; 126 return buffer_.bits;
127 } 127 }
128 128
129 void GpuMemoryBufferImplSurfaceTexture::Unmap() { 129 void GpuMemoryBufferImplSurfaceTexture::Unmap() {
130 TRACE_EVENT0("gpu", "GpuMemoryBufferImplSurfaceTexture::Unmap"); 130 TRACE_EVENT0("gpu", "GpuMemoryBufferImplSurfaceTexture::Unmap");
131
132 DCHECK(mapped_); 131 DCHECK(mapped_);
133 ANativeWindow_unlockAndPost(native_window_); 132 ANativeWindow_unlockAndPost(native_window_);
134 mapped_ = false; 133 mapped_ = false;
135 } 134 }
136 135
137 void GpuMemoryBufferImplSurfaceTexture::GetStride(int* stride) const { 136 int GpuMemoryBufferImplSurfaceTexture::stride(size_t plane) const {
138 *stride = stride_; 137 DCHECK(mapped_);
138 DCHECK_EQ(0u, plane);
139 return gfx::RowSizeForBufferFormat(buffer_.stride, format_, 0);
139 } 140 }
140 141
141 gfx::GpuMemoryBufferHandle GpuMemoryBufferImplSurfaceTexture::GetHandle() 142 gfx::GpuMemoryBufferHandle
142 const { 143 GpuMemoryBufferImplSurfaceTexture::GetHandle() const {
143 gfx::GpuMemoryBufferHandle handle; 144 gfx::GpuMemoryBufferHandle handle;
144 handle.type = gfx::SURFACE_TEXTURE_BUFFER; 145 handle.type = gfx::SURFACE_TEXTURE_BUFFER;
145 handle.id = id_; 146 handle.id = id_;
146 return handle; 147 return handle;
147 } 148 }
148 149
149 } // namespace content 150 } // namespace content
OLDNEW
« no previous file with comments | « content/common/gpu/client/gpu_memory_buffer_impl_surface_texture.h ('k') | content/renderer/media/video_capture_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698