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 bool GpuMemoryBufferImplSurfaceTexture::IsUsageSupported(unsigned usage) { | 38 bool GpuMemoryBufferImplSurfaceTexture::IsUsageSupported(unsigned usage) { |
27 switch (usage) { | 39 switch (usage) { |
28 case GL_IMAGE_MAP_CHROMIUM: | 40 case GL_IMAGE_MAP_CHROMIUM: |
29 return true; | 41 return true; |
30 default: | 42 default: |
31 return false; | 43 return false; |
32 } | 44 } |
33 } | 45 } |
34 | 46 |
35 // static | 47 // static |
| 48 bool GpuMemoryBufferImplSurfaceTexture::IsConfigurationSupported( |
| 49 unsigned internalformat, |
| 50 unsigned usage) { |
| 51 return IsFormatSupported(internalformat) && IsUsageSupported(usage); |
| 52 } |
| 53 |
| 54 // static |
36 int GpuMemoryBufferImplSurfaceTexture::WindowFormat(unsigned internalformat) { | 55 int GpuMemoryBufferImplSurfaceTexture::WindowFormat(unsigned internalformat) { |
37 switch (internalformat) { | 56 switch (internalformat) { |
38 case GL_RGBA8_OES: | 57 case GL_RGBA8_OES: |
39 return WINDOW_FORMAT_RGBA_8888; | 58 return WINDOW_FORMAT_RGBA_8888; |
40 default: | 59 default: |
41 NOTREACHED(); | 60 NOTREACHED(); |
42 return 0; | 61 return 0; |
43 } | 62 } |
44 } | 63 } |
45 | 64 |
46 GpuMemoryBufferImplSurfaceTexture::GpuMemoryBufferImplSurfaceTexture( | 65 bool GpuMemoryBufferImplSurfaceTexture::InitializeFromHandle( |
47 gfx::Size size, | 66 gfx::GpuMemoryBufferHandle handle) { |
48 unsigned internalformat) | 67 TRACE_EVENT0("gpu", |
49 : GpuMemoryBufferImpl(size, internalformat), | 68 "GpuMemoryBufferImplSurfaceTexture::InitializeFromHandle"); |
50 native_window_(NULL), | |
51 stride_(0u) {} | |
52 | 69 |
53 GpuMemoryBufferImplSurfaceTexture::~GpuMemoryBufferImplSurfaceTexture() { | 70 DCHECK(IsFormatSupported(internalformat_)); |
54 if (native_window_) | |
55 ANativeWindow_release(native_window_); | |
56 } | |
57 | |
58 bool GpuMemoryBufferImplSurfaceTexture::Initialize( | |
59 gfx::GpuMemoryBufferHandle handle) { | |
60 TRACE_EVENT0("gpu", "GpuMemoryBufferImplSurfaceTexture::Initialize"); | |
61 | |
62 DCHECK(!native_window_); | 71 DCHECK(!native_window_); |
63 native_window_ = SurfaceTextureLookup::GetInstance()->AcquireNativeWidget( | 72 native_window_ = SurfaceTextureLookup::GetInstance()->AcquireNativeWidget( |
64 handle.surface_texture_id.primary_id, | 73 handle.surface_texture_id.primary_id, |
65 handle.surface_texture_id.secondary_id); | 74 handle.surface_texture_id.secondary_id); |
66 if (!native_window_) | 75 if (!native_window_) |
67 return false; | 76 return false; |
68 | 77 |
69 ANativeWindow_setBuffersGeometry(native_window_, | 78 ANativeWindow_setBuffersGeometry(native_window_, |
70 size_.width(), | 79 size_.width(), |
71 size_.height(), | 80 size_.height(), |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
105 | 114 |
106 gfx::GpuMemoryBufferHandle GpuMemoryBufferImplSurfaceTexture::GetHandle() | 115 gfx::GpuMemoryBufferHandle GpuMemoryBufferImplSurfaceTexture::GetHandle() |
107 const { | 116 const { |
108 gfx::GpuMemoryBufferHandle handle; | 117 gfx::GpuMemoryBufferHandle handle; |
109 handle.type = gfx::SURFACE_TEXTURE_BUFFER; | 118 handle.type = gfx::SURFACE_TEXTURE_BUFFER; |
110 handle.surface_texture_id = surface_texture_id_; | 119 handle.surface_texture_id = surface_texture_id_; |
111 return handle; | 120 return handle; |
112 } | 121 } |
113 | 122 |
114 } // namespace content | 123 } // namespace content |
OLD | NEW |