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( |
| 15 const gfx::Size& size, |
| 16 unsigned internalformat) |
| 17 : GpuMemoryBufferImpl(size, internalformat), |
| 18 native_window_(NULL), |
| 19 stride_(0u) {} |
| 20 |
| 21 GpuMemoryBufferImplSurfaceTexture::~GpuMemoryBufferImplSurfaceTexture() { |
| 22 if (native_window_) |
| 23 ANativeWindow_release(native_window_); |
| 24 } |
| 25 |
14 // static | 26 // static |
15 bool GpuMemoryBufferImplSurfaceTexture::IsFormatSupported( | 27 bool GpuMemoryBufferImplSurfaceTexture::IsFormatSupported( |
16 unsigned internalformat) { | 28 unsigned internalformat) { |
17 switch (internalformat) { | 29 switch (internalformat) { |
18 case GL_RGBA8_OES: | 30 case GL_RGBA8_OES: |
19 return true; | 31 return true; |
20 default: | 32 default: |
21 return false; | 33 return false; |
22 } | 34 } |
23 } | 35 } |
24 | 36 |
25 // static | 37 // static |
26 int GpuMemoryBufferImplSurfaceTexture::WindowFormat(unsigned internalformat) { | 38 int GpuMemoryBufferImplSurfaceTexture::WindowFormat(unsigned internalformat) { |
27 switch (internalformat) { | 39 switch (internalformat) { |
28 case GL_RGBA8_OES: | 40 case GL_RGBA8_OES: |
29 return WINDOW_FORMAT_RGBA_8888; | 41 return WINDOW_FORMAT_RGBA_8888; |
30 default: | 42 default: |
31 NOTREACHED(); | 43 NOTREACHED(); |
32 return 0; | 44 return 0; |
33 } | 45 } |
34 } | 46 } |
35 | 47 |
36 GpuMemoryBufferImplSurfaceTexture::GpuMemoryBufferImplSurfaceTexture( | 48 bool GpuMemoryBufferImplSurfaceTexture::InitializeFromHandle( |
37 gfx::Size size, | |
38 unsigned internalformat) | |
39 : GpuMemoryBufferImpl(size, internalformat), | |
40 native_window_(NULL), | |
41 stride_(0u) {} | |
42 | |
43 GpuMemoryBufferImplSurfaceTexture::~GpuMemoryBufferImplSurfaceTexture() { | |
44 if (native_window_) | |
45 ANativeWindow_release(native_window_); | |
46 } | |
47 | |
48 bool GpuMemoryBufferImplSurfaceTexture::Initialize( | |
49 gfx::GpuMemoryBufferHandle handle) { | 49 gfx::GpuMemoryBufferHandle handle) { |
50 TRACE_EVENT0("gpu", "GpuMemoryBufferImplSurfaceTexture::Initialize"); | 50 TRACE_EVENT0("gpu", |
| 51 "GpuMemoryBufferImplSurfaceTexture::InitializeFromHandle"); |
51 | 52 |
52 DCHECK(!native_window_); | 53 DCHECK(!native_window_); |
53 native_window_ = SurfaceTextureLookup::GetInstance()->AcquireNativeWidget( | 54 native_window_ = SurfaceTextureLookup::GetInstance()->AcquireNativeWidget( |
54 handle.surface_texture_id.primary_id, | 55 handle.surface_texture_id.primary_id, |
55 handle.surface_texture_id.secondary_id); | 56 handle.surface_texture_id.secondary_id); |
56 if (!native_window_) | 57 if (!native_window_) |
57 return false; | 58 return false; |
58 | 59 |
59 ANativeWindow_setBuffersGeometry(native_window_, | 60 ANativeWindow_setBuffersGeometry(native_window_, |
60 size_.width(), | 61 size_.width(), |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
95 | 96 |
96 gfx::GpuMemoryBufferHandle GpuMemoryBufferImplSurfaceTexture::GetHandle() | 97 gfx::GpuMemoryBufferHandle GpuMemoryBufferImplSurfaceTexture::GetHandle() |
97 const { | 98 const { |
98 gfx::GpuMemoryBufferHandle handle; | 99 gfx::GpuMemoryBufferHandle handle; |
99 handle.type = gfx::SURFACE_TEXTURE_BUFFER; | 100 handle.type = gfx::SURFACE_TEXTURE_BUFFER; |
100 handle.surface_texture_id = surface_texture_id_; | 101 handle.surface_texture_id = surface_texture_id_; |
101 return handle; | 102 return handle; |
102 } | 103 } |
103 | 104 |
104 } // namespace content | 105 } // namespace content |
OLD | NEW |