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

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

Issue 634083002: gpu: Compositor management of GpuMemoryBuffer instances. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@cc-pre-chromium-image-refactor
Patch Set: mac build fix Created 6 years, 2 months 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/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 Format format,
17 const DestructionCallback& callback, 17 const DestructionCallback& callback,
18 const gfx::SurfaceTextureId& surface_texture_id, 18 const gfx::SurfaceTextureId& surface_texture_id,
19 ANativeWindow* native_window) 19 ANativeWindow* native_window)
20 : GpuMemoryBufferImpl(size, internalformat, callback), 20 : GpuMemoryBufferImpl(size, format, callback),
21 surface_texture_id_(surface_texture_id), 21 surface_texture_id_(surface_texture_id),
22 native_window_(native_window), 22 native_window_(native_window),
23 stride_(0u) { 23 stride_(0u) {
24 } 24 }
25 25
26 GpuMemoryBufferImplSurfaceTexture::~GpuMemoryBufferImplSurfaceTexture() { 26 GpuMemoryBufferImplSurfaceTexture::~GpuMemoryBufferImplSurfaceTexture() {
27 ANativeWindow_release(native_window_); 27 ANativeWindow_release(native_window_);
28 } 28 }
29 29
30 // static 30 // static
31 scoped_ptr<GpuMemoryBufferImpl> 31 scoped_ptr<GpuMemoryBufferImpl>
32 GpuMemoryBufferImplSurfaceTexture::CreateFromHandle( 32 GpuMemoryBufferImplSurfaceTexture::CreateFromHandle(
33 const gfx::GpuMemoryBufferHandle& handle, 33 const gfx::GpuMemoryBufferHandle& handle,
34 const gfx::Size& size, 34 const gfx::Size& size,
35 unsigned internalformat, 35 Format format,
36 const DestructionCallback& callback) { 36 const DestructionCallback& callback) {
37 DCHECK(IsFormatSupported(internalformat)); 37 DCHECK(IsFormatSupported(format));
38 38
39 ANativeWindow* native_window = 39 ANativeWindow* native_window =
40 SurfaceTextureLookup::GetInstance()->AcquireNativeWidget( 40 SurfaceTextureLookup::GetInstance()->AcquireNativeWidget(
41 handle.surface_texture_id.primary_id, 41 handle.surface_texture_id.primary_id,
42 handle.surface_texture_id.secondary_id); 42 handle.surface_texture_id.secondary_id);
43 if (!native_window) 43 if (!native_window)
44 return scoped_ptr<GpuMemoryBufferImpl>(); 44 return scoped_ptr<GpuMemoryBufferImpl>();
45 45
46 ANativeWindow_setBuffersGeometry( 46 ANativeWindow_setBuffersGeometry(
47 native_window, size.width(), size.height(), WindowFormat(internalformat)); 47 native_window, size.width(), size.height(), WindowFormat(format));
48 48
49 return make_scoped_ptr<GpuMemoryBufferImpl>( 49 return make_scoped_ptr<GpuMemoryBufferImpl>(
50 new GpuMemoryBufferImplSurfaceTexture(size, 50 new GpuMemoryBufferImplSurfaceTexture(
51 internalformat, 51 size, format, callback, handle.surface_texture_id, native_window));
52 callback,
53 handle.surface_texture_id,
54 native_window));
55 } 52 }
56 53
57 // static 54 // static
58 bool GpuMemoryBufferImplSurfaceTexture::IsFormatSupported( 55 bool GpuMemoryBufferImplSurfaceTexture::IsFormatSupported(Format format) {
59 unsigned internalformat) { 56 switch (format) {
60 switch (internalformat) { 57 case RGBA_8888:
61 case GL_RGBA8_OES:
62 return true; 58 return true;
63 default: 59 case RGBX_8888:
60 case BGRA_8888:
64 return false; 61 return false;
65 } 62 }
63
64 NOTREACHED();
65 return false;
66 } 66 }
67 67
68 // static 68 // static
69 bool GpuMemoryBufferImplSurfaceTexture::IsUsageSupported(unsigned usage) { 69 bool GpuMemoryBufferImplSurfaceTexture::IsUsageSupported(Usage usage) {
70 switch (usage) { 70 switch (usage) {
71 case GL_IMAGE_MAP_CHROMIUM: 71 case MAP:
72 return true; 72 return true;
73 default: 73 case SCANOUT:
74 return false; 74 return false;
75 } 75 }
76
77 NOTREACHED();
78 return false;
76 } 79 }
77 80
78 // static 81 // static
79 bool GpuMemoryBufferImplSurfaceTexture::IsConfigurationSupported( 82 bool GpuMemoryBufferImplSurfaceTexture::IsConfigurationSupported(Format format,
80 unsigned internalformat, 83 Usage usage) {
81 unsigned usage) { 84 return IsFormatSupported(format) && IsUsageSupported(usage);
82 return IsFormatSupported(internalformat) && IsUsageSupported(usage);
83 } 85 }
84 86
85 // static 87 // static
86 int GpuMemoryBufferImplSurfaceTexture::WindowFormat(unsigned internalformat) { 88 int GpuMemoryBufferImplSurfaceTexture::WindowFormat(Format format) {
87 switch (internalformat) { 89 switch (format) {
88 case GL_RGBA8_OES: 90 case RGBA_8888:
89 return WINDOW_FORMAT_RGBA_8888; 91 return WINDOW_FORMAT_RGBA_8888;
90 default: 92 case RGBX_8888:
91 NOTREACHED(); 93 case BGRA_8888:
92 return 0; 94 break;
93 } 95 }
96
97 NOTREACHED();
98 return 0;
94 } 99 }
95 100
96 void* GpuMemoryBufferImplSurfaceTexture::Map() { 101 void* GpuMemoryBufferImplSurfaceTexture::Map() {
97 TRACE_EVENT0("gpu", "GpuMemoryBufferImplSurfaceTexture::Map"); 102 TRACE_EVENT0("gpu", "GpuMemoryBufferImplSurfaceTexture::Map");
98 103
99 DCHECK(!mapped_); 104 DCHECK(!mapped_);
100 DCHECK(native_window_); 105 DCHECK(native_window_);
101 ANativeWindow_Buffer buffer; 106 ANativeWindow_Buffer buffer;
102 int status = ANativeWindow_lock(native_window_, &buffer, NULL); 107 int status = ANativeWindow_lock(native_window_, &buffer, NULL);
103 if (status) { 108 if (status) {
104 VLOG(1) << "ANativeWindow_lock failed with error code: " << status; 109 VLOG(1) << "ANativeWindow_lock failed with error code: " << status;
105 return NULL; 110 return NULL;
106 } 111 }
107 112
108 DCHECK_LE(size_.width(), buffer.stride); 113 DCHECK_LE(size_.width(), buffer.stride);
109 stride_ = buffer.stride * BytesPerPixel(internalformat_); 114 stride_ = buffer.stride * BytesPerPixel(format_);
110 mapped_ = true; 115 mapped_ = true;
111 return buffer.bits; 116 return buffer.bits;
112 } 117 }
113 118
114 void GpuMemoryBufferImplSurfaceTexture::Unmap() { 119 void GpuMemoryBufferImplSurfaceTexture::Unmap() {
115 TRACE_EVENT0("gpu", "GpuMemoryBufferImplSurfaceTexture::Unmap"); 120 TRACE_EVENT0("gpu", "GpuMemoryBufferImplSurfaceTexture::Unmap");
116 121
117 DCHECK(mapped_); 122 DCHECK(mapped_);
118 ANativeWindow_unlockAndPost(native_window_); 123 ANativeWindow_unlockAndPost(native_window_);
119 mapped_ = false; 124 mapped_ = false;
120 } 125 }
121 126
122 uint32 GpuMemoryBufferImplSurfaceTexture::GetStride() const { return stride_; } 127 uint32 GpuMemoryBufferImplSurfaceTexture::GetStride() const {
128 return stride_;
129 }
123 130
124 gfx::GpuMemoryBufferHandle GpuMemoryBufferImplSurfaceTexture::GetHandle() 131 gfx::GpuMemoryBufferHandle GpuMemoryBufferImplSurfaceTexture::GetHandle()
125 const { 132 const {
126 gfx::GpuMemoryBufferHandle handle; 133 gfx::GpuMemoryBufferHandle handle;
127 handle.type = gfx::SURFACE_TEXTURE_BUFFER; 134 handle.type = gfx::SURFACE_TEXTURE_BUFFER;
128 handle.surface_texture_id = surface_texture_id_; 135 handle.surface_texture_id = surface_texture_id_;
129 return handle; 136 return handle;
130 } 137 }
131 138
132 } // namespace content 139 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698