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

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

Issue 1827123002: Move content/common/gpu/client to gpu/ipc/client (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Update Created 4 years, 8 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "content/common/gpu/client/gpu_memory_buffer_impl_surface_texture.h"
6
7 #include "base/logging.h"
8 #include "base/trace_event/trace_event.h"
9 #include "gpu/ipc/common/android/surface_texture_manager.h"
10 #include "gpu/ipc/common/gpu_memory_buffer_support.h"
11 #include "ui/gfx/buffer_format_util.h"
12 #include "ui/gl/android/surface_texture.h"
13 #include "ui/gl/gl_bindings.h"
14
15 namespace content {
16 namespace {
17
18 int WindowFormat(gfx::BufferFormat format) {
19 switch (format) {
20 case gfx::BufferFormat::RGBA_8888:
21 return WINDOW_FORMAT_RGBA_8888;
22 case gfx::BufferFormat::ATC:
23 case gfx::BufferFormat::ATCIA:
24 case gfx::BufferFormat::DXT1:
25 case gfx::BufferFormat::DXT5:
26 case gfx::BufferFormat::ETC1:
27 case gfx::BufferFormat::R_8:
28 case gfx::BufferFormat::RGBA_4444:
29 case gfx::BufferFormat::RGBX_8888:
30 case gfx::BufferFormat::BGRX_8888:
31 case gfx::BufferFormat::BGRA_8888:
32 case gfx::BufferFormat::YUV_420:
33 case gfx::BufferFormat::YUV_420_BIPLANAR:
34 case gfx::BufferFormat::UYVY_422:
35 NOTREACHED();
36 return 0;
37 }
38
39 NOTREACHED();
40 return 0;
41 }
42
43 void FreeSurfaceTextureForTesting(
44 scoped_refptr<gfx::SurfaceTexture> surface_texture,
45 gfx::GpuMemoryBufferId id) {
46 gpu::SurfaceTextureManager::GetInstance()->UnregisterSurfaceTexture(id.id, 0);
47 }
48
49 } // namespace
50
51 GpuMemoryBufferImplSurfaceTexture::GpuMemoryBufferImplSurfaceTexture(
52 gfx::GpuMemoryBufferId id,
53 const gfx::Size& size,
54 gfx::BufferFormat format,
55 const DestructionCallback& callback,
56 ANativeWindow* native_window)
57 : GpuMemoryBufferImpl(id, size, format, callback),
58 native_window_(native_window) {}
59
60 GpuMemoryBufferImplSurfaceTexture::~GpuMemoryBufferImplSurfaceTexture() {
61 ANativeWindow_release(native_window_);
62 }
63
64 // static
65 scoped_ptr<GpuMemoryBufferImplSurfaceTexture>
66 GpuMemoryBufferImplSurfaceTexture::CreateFromHandle(
67 const gfx::GpuMemoryBufferHandle& handle,
68 const gfx::Size& size,
69 gfx::BufferFormat format,
70 gfx::BufferUsage usage,
71 const DestructionCallback& callback) {
72 ANativeWindow* native_window =
73 gpu::SurfaceTextureManager::GetInstance()
74 ->AcquireNativeWidgetForSurfaceTexture(handle.id.id);
75 if (!native_window)
76 return nullptr;
77
78 ANativeWindow_setBuffersGeometry(
79 native_window, size.width(), size.height(), WindowFormat(format));
80
81 return make_scoped_ptr(new GpuMemoryBufferImplSurfaceTexture(
82 handle.id, size, format, callback, native_window));
83 }
84
85 // static
86 bool GpuMemoryBufferImplSurfaceTexture::IsConfigurationSupported(
87 gfx::BufferFormat format,
88 gfx::BufferUsage usage) {
89 return gpu::IsNativeGpuMemoryBufferConfigurationSupported(format, usage);
90 }
91
92 // static
93 base::Closure GpuMemoryBufferImplSurfaceTexture::AllocateForTesting(
94 const gfx::Size& size,
95 gfx::BufferFormat format,
96 gfx::BufferUsage usage,
97 gfx::GpuMemoryBufferHandle* handle) {
98 scoped_refptr<gfx::SurfaceTexture> surface_texture =
99 gfx::SurfaceTexture::Create(0);
100 DCHECK(surface_texture);
101 const gfx::GpuMemoryBufferId kBufferId(1);
102 gpu::SurfaceTextureManager::GetInstance()->RegisterSurfaceTexture(
103 kBufferId.id, 0, surface_texture.get());
104 handle->type = gfx::SURFACE_TEXTURE_BUFFER;
105 handle->id = kBufferId;
106 return base::Bind(&FreeSurfaceTextureForTesting, surface_texture, kBufferId);
107 }
108
109 bool GpuMemoryBufferImplSurfaceTexture::Map() {
110 TRACE_EVENT0("gpu", "GpuMemoryBufferImplSurfaceTexture::Map");
111 DCHECK(!mapped_);
112 DCHECK(native_window_);
113 if (ANativeWindow_lock(native_window_, &buffer_, NULL)) {
114 DPLOG(ERROR) << "ANativeWindow_lock failed";
115 return false;
116 }
117 DCHECK_LE(size_.width(), buffer_.stride);
118 mapped_ = true;
119 return true;
120 }
121
122 void* GpuMemoryBufferImplSurfaceTexture::memory(size_t plane) {
123 TRACE_EVENT0("gpu", "GpuMemoryBufferImplSurfaceTexture::memory");
124 DCHECK(mapped_);
125 DCHECK_EQ(0u, plane);
126 return buffer_.bits;
127 }
128
129 void GpuMemoryBufferImplSurfaceTexture::Unmap() {
130 TRACE_EVENT0("gpu", "GpuMemoryBufferImplSurfaceTexture::Unmap");
131 DCHECK(mapped_);
132 ANativeWindow_unlockAndPost(native_window_);
133 mapped_ = false;
134 }
135
136 int GpuMemoryBufferImplSurfaceTexture::stride(size_t plane) const {
137 DCHECK(mapped_);
138 DCHECK_EQ(0u, plane);
139 return gfx::RowSizeForBufferFormat(buffer_.stride, format_, 0);
140 }
141
142 gfx::GpuMemoryBufferHandle
143 GpuMemoryBufferImplSurfaceTexture::GetHandle() const {
144 gfx::GpuMemoryBufferHandle handle;
145 handle.type = gfx::SURFACE_TEXTURE_BUFFER;
146 handle.id = id_;
147 return handle;
148 }
149
150 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698