OLD | NEW |
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 "ui/gl/gl_bindings.h" | 10 #include "ui/gl/gl_bindings.h" |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
61 return scoped_ptr<GpuMemoryBufferImpl>(); | 61 return scoped_ptr<GpuMemoryBufferImpl>(); |
62 | 62 |
63 ANativeWindow_setBuffersGeometry( | 63 ANativeWindow_setBuffersGeometry( |
64 native_window, size.width(), size.height(), WindowFormat(format)); | 64 native_window, size.width(), size.height(), WindowFormat(format)); |
65 | 65 |
66 return make_scoped_ptr<GpuMemoryBufferImpl>( | 66 return make_scoped_ptr<GpuMemoryBufferImpl>( |
67 new GpuMemoryBufferImplSurfaceTexture( | 67 new GpuMemoryBufferImplSurfaceTexture( |
68 handle.id, size, format, callback, native_window)); | 68 handle.id, size, format, callback, native_window)); |
69 } | 69 } |
70 | 70 |
71 void* GpuMemoryBufferImplSurfaceTexture::Map() { | 71 bool GpuMemoryBufferImplSurfaceTexture::Map(void** data) { |
72 TRACE_EVENT0("gpu", "GpuMemoryBufferImplSurfaceTexture::Map"); | 72 TRACE_EVENT0("gpu", "GpuMemoryBufferImplSurfaceTexture::Map"); |
73 | 73 |
74 DCHECK(!mapped_); | 74 DCHECK(!mapped_); |
75 DCHECK(native_window_); | 75 DCHECK(native_window_); |
76 ANativeWindow_Buffer buffer; | 76 ANativeWindow_Buffer buffer; |
77 int status = ANativeWindow_lock(native_window_, &buffer, NULL); | 77 int status = ANativeWindow_lock(native_window_, &buffer, NULL); |
78 if (status) { | 78 if (status) { |
79 VLOG(1) << "ANativeWindow_lock failed with error code: " << status; | 79 VLOG(1) << "ANativeWindow_lock failed with error code: " << status; |
80 return NULL; | 80 return false; |
81 } | 81 } |
82 | 82 |
83 size_t stride_in_bytes = 0; | 83 size_t stride_in_bytes = 0; |
84 if (!StrideInBytes(buffer.stride, format_, &stride_in_bytes)) | 84 if (!StrideInBytes(buffer.stride, format_, &stride_in_bytes)) |
85 return NULL; | 85 return false; |
86 | 86 |
87 DCHECK_LE(size_.width(), buffer.stride); | 87 DCHECK_LE(size_.width(), buffer.stride); |
88 stride_ = stride_in_bytes; | 88 stride_ = stride_in_bytes; |
89 mapped_ = true; | 89 mapped_ = true; |
90 return buffer.bits; | 90 *data = buffer.bits; |
| 91 return true; |
91 } | 92 } |
92 | 93 |
93 void GpuMemoryBufferImplSurfaceTexture::Unmap() { | 94 void GpuMemoryBufferImplSurfaceTexture::Unmap() { |
94 TRACE_EVENT0("gpu", "GpuMemoryBufferImplSurfaceTexture::Unmap"); | 95 TRACE_EVENT0("gpu", "GpuMemoryBufferImplSurfaceTexture::Unmap"); |
95 | 96 |
96 DCHECK(mapped_); | 97 DCHECK(mapped_); |
97 ANativeWindow_unlockAndPost(native_window_); | 98 ANativeWindow_unlockAndPost(native_window_); |
98 mapped_ = false; | 99 mapped_ = false; |
99 } | 100 } |
100 | 101 |
101 uint32 GpuMemoryBufferImplSurfaceTexture::GetStride() const { | 102 void GpuMemoryBufferImplSurfaceTexture::GetStride(uint32* stride) const { |
102 return stride_; | 103 *stride = stride_; |
103 } | 104 } |
104 | 105 |
105 gfx::GpuMemoryBufferHandle GpuMemoryBufferImplSurfaceTexture::GetHandle() | 106 gfx::GpuMemoryBufferHandle GpuMemoryBufferImplSurfaceTexture::GetHandle() |
106 const { | 107 const { |
107 gfx::GpuMemoryBufferHandle handle; | 108 gfx::GpuMemoryBufferHandle handle; |
108 handle.type = gfx::SURFACE_TEXTURE_BUFFER; | 109 handle.type = gfx::SURFACE_TEXTURE_BUFFER; |
109 handle.id = id_; | 110 handle.id = id_; |
110 return handle; | 111 return handle; |
111 } | 112 } |
112 | 113 |
113 } // namespace content | 114 } // namespace content |
OLD | NEW |