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/debug/trace_event.h" | 7 #include "base/debug/trace_event.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "content/common/android/surface_texture_lookup.h" | 9 #include "content/common/android/surface_texture_lookup.h" |
10 #include "ui/gl/gl_bindings.h" | 10 #include "ui/gl/gl_bindings.h" |
11 | 11 |
12 namespace content { | 12 namespace content { |
13 | 13 |
14 GpuMemoryBufferImplSurfaceTexture::GpuMemoryBufferImplSurfaceTexture( | 14 GpuMemoryBufferImplSurfaceTexture::GpuMemoryBufferImplSurfaceTexture( |
15 const gfx::Size& size, | 15 const gfx::Size& size, |
16 unsigned internalformat) | 16 unsigned internalformat, |
17 : GpuMemoryBufferImpl(size, internalformat), | 17 const DestructionCallback& callback, |
18 native_window_(NULL), | 18 const gfx::SurfaceTextureId& surface_texture_id, |
19 stride_(0u) {} | 19 ANativeWindow* native_window) |
| 20 : GpuMemoryBufferImpl(size, internalformat, callback), |
| 21 surface_texture_id_(surface_texture_id), |
| 22 native_window_(native_window), |
| 23 stride_(0u) { |
| 24 } |
20 | 25 |
21 GpuMemoryBufferImplSurfaceTexture::~GpuMemoryBufferImplSurfaceTexture() { | 26 GpuMemoryBufferImplSurfaceTexture::~GpuMemoryBufferImplSurfaceTexture() { |
22 if (native_window_) | 27 ANativeWindow_release(native_window_); |
23 ANativeWindow_release(native_window_); | |
24 } | 28 } |
25 | 29 |
26 // static | 30 // static |
| 31 scoped_ptr<GpuMemoryBufferImpl> |
| 32 GpuMemoryBufferImplSurfaceTexture::CreateFromHandle( |
| 33 const gfx::GpuMemoryBufferHandle& handle, |
| 34 const gfx::Size& size, |
| 35 unsigned internalformat, |
| 36 const DestructionCallback& callback) { |
| 37 DCHECK(IsFormatSupported(internalformat)); |
| 38 |
| 39 ANativeWindow* native_window = |
| 40 SurfaceTextureLookup::GetInstance()->AcquireNativeWidget( |
| 41 handle.surface_texture_id.primary_id, |
| 42 handle.surface_texture_id.secondary_id); |
| 43 if (!native_window) |
| 44 return scoped_ptr<GpuMemoryBufferImpl>(); |
| 45 |
| 46 ANativeWindow_setBuffersGeometry( |
| 47 native_window, size.width(), size.height(), WindowFormat(internalformat)); |
| 48 |
| 49 return make_scoped_ptr<GpuMemoryBufferImpl>( |
| 50 new GpuMemoryBufferImplSurfaceTexture(size, |
| 51 internalformat, |
| 52 callback, |
| 53 handle.surface_texture_id, |
| 54 native_window)); |
| 55 } |
| 56 |
| 57 // static |
27 bool GpuMemoryBufferImplSurfaceTexture::IsFormatSupported( | 58 bool GpuMemoryBufferImplSurfaceTexture::IsFormatSupported( |
28 unsigned internalformat) { | 59 unsigned internalformat) { |
29 switch (internalformat) { | 60 switch (internalformat) { |
30 case GL_RGBA8_OES: | 61 case GL_RGBA8_OES: |
31 return true; | 62 return true; |
32 default: | 63 default: |
33 return false; | 64 return false; |
34 } | 65 } |
35 } | 66 } |
36 | 67 |
(...skipping 18 matching lines...) Expand all Loading... |
55 int GpuMemoryBufferImplSurfaceTexture::WindowFormat(unsigned internalformat) { | 86 int GpuMemoryBufferImplSurfaceTexture::WindowFormat(unsigned internalformat) { |
56 switch (internalformat) { | 87 switch (internalformat) { |
57 case GL_RGBA8_OES: | 88 case GL_RGBA8_OES: |
58 return WINDOW_FORMAT_RGBA_8888; | 89 return WINDOW_FORMAT_RGBA_8888; |
59 default: | 90 default: |
60 NOTREACHED(); | 91 NOTREACHED(); |
61 return 0; | 92 return 0; |
62 } | 93 } |
63 } | 94 } |
64 | 95 |
65 bool GpuMemoryBufferImplSurfaceTexture::InitializeFromHandle( | |
66 const gfx::GpuMemoryBufferHandle& handle) { | |
67 TRACE_EVENT0("gpu", | |
68 "GpuMemoryBufferImplSurfaceTexture::InitializeFromHandle"); | |
69 | |
70 DCHECK(IsFormatSupported(internalformat_)); | |
71 DCHECK(!native_window_); | |
72 native_window_ = SurfaceTextureLookup::GetInstance()->AcquireNativeWidget( | |
73 handle.surface_texture_id.primary_id, | |
74 handle.surface_texture_id.secondary_id); | |
75 if (!native_window_) | |
76 return false; | |
77 | |
78 ANativeWindow_setBuffersGeometry(native_window_, | |
79 size_.width(), | |
80 size_.height(), | |
81 WindowFormat(internalformat_)); | |
82 | |
83 surface_texture_id_ = handle.surface_texture_id; | |
84 return true; | |
85 } | |
86 | |
87 void* GpuMemoryBufferImplSurfaceTexture::Map() { | 96 void* GpuMemoryBufferImplSurfaceTexture::Map() { |
88 TRACE_EVENT0("gpu", "GpuMemoryBufferImplSurfaceTexture::Map"); | 97 TRACE_EVENT0("gpu", "GpuMemoryBufferImplSurfaceTexture::Map"); |
89 | 98 |
90 DCHECK(!mapped_); | 99 DCHECK(!mapped_); |
91 DCHECK(native_window_); | 100 DCHECK(native_window_); |
92 ANativeWindow_Buffer buffer; | 101 ANativeWindow_Buffer buffer; |
93 int status = ANativeWindow_lock(native_window_, &buffer, NULL); | 102 int status = ANativeWindow_lock(native_window_, &buffer, NULL); |
94 if (status) { | 103 if (status) { |
95 VLOG(1) << "ANativeWindow_lock failed with error code: " << status; | 104 VLOG(1) << "ANativeWindow_lock failed with error code: " << status; |
96 return NULL; | 105 return NULL; |
(...skipping 17 matching lines...) Expand all Loading... |
114 | 123 |
115 gfx::GpuMemoryBufferHandle GpuMemoryBufferImplSurfaceTexture::GetHandle() | 124 gfx::GpuMemoryBufferHandle GpuMemoryBufferImplSurfaceTexture::GetHandle() |
116 const { | 125 const { |
117 gfx::GpuMemoryBufferHandle handle; | 126 gfx::GpuMemoryBufferHandle handle; |
118 handle.type = gfx::SURFACE_TEXTURE_BUFFER; | 127 handle.type = gfx::SURFACE_TEXTURE_BUFFER; |
119 handle.surface_texture_id = surface_texture_id_; | 128 handle.surface_texture_id = surface_texture_id_; |
120 return handle; | 129 return handle; |
121 } | 130 } |
122 | 131 |
123 } // namespace content | 132 } // namespace content |
OLD | NEW |