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

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

Issue 600693002: content: Cleanup GpuMemoryBufferImpl destruction. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: address review feedback 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 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> GpuMemoryBufferImplIOSurface::CreateFromHandle(
32 const gfx::GpuMemoryBufferHandle& handle,
33 const gfx::Size& size,
34 unsigned internalformat,
35 const DestructionCallback& callback) {
36 DCHECK(IsFormatSupported(internalformat));
37
38 ANativeWindow* native_window =
39 SurfaceTextureLookup::GetInstance()->AcquireNativeWidget(
40 handle.surface_texture_id.primary_id,
41 handle.surface_texture_id.secondary_id);
42 if (!native_window)
43 return scoped_ptr<GpuMemoryBufferImpl>();
44
45 ANativeWindow_setBuffersGeometry(
46 native_window, size.width(), size.height(), WindowFormat(internalformat));
47
48 return make_scoped_ptr<GpuMemoryBufferImpl>(
49 new GpuMemoryBufferImplSurfaceTexture(size,
50 internalformat,
51 callback,
52 handle.surface_texture_id,
53 native_window));
54 }
55
56 // static
27 bool GpuMemoryBufferImplSurfaceTexture::IsFormatSupported( 57 bool GpuMemoryBufferImplSurfaceTexture::IsFormatSupported(
28 unsigned internalformat) { 58 unsigned internalformat) {
29 switch (internalformat) { 59 switch (internalformat) {
30 case GL_RGBA8_OES: 60 case GL_RGBA8_OES:
31 return true; 61 return true;
32 default: 62 default:
33 return false; 63 return false;
34 } 64 }
35 } 65 }
36 66
(...skipping 18 matching lines...) Expand all
55 int GpuMemoryBufferImplSurfaceTexture::WindowFormat(unsigned internalformat) { 85 int GpuMemoryBufferImplSurfaceTexture::WindowFormat(unsigned internalformat) {
56 switch (internalformat) { 86 switch (internalformat) {
57 case GL_RGBA8_OES: 87 case GL_RGBA8_OES:
58 return WINDOW_FORMAT_RGBA_8888; 88 return WINDOW_FORMAT_RGBA_8888;
59 default: 89 default:
60 NOTREACHED(); 90 NOTREACHED();
61 return 0; 91 return 0;
62 } 92 }
63 } 93 }
64 94
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() { 95 void* GpuMemoryBufferImplSurfaceTexture::Map() {
88 TRACE_EVENT0("gpu", "GpuMemoryBufferImplSurfaceTexture::Map"); 96 TRACE_EVENT0("gpu", "GpuMemoryBufferImplSurfaceTexture::Map");
89 97
90 DCHECK(!mapped_); 98 DCHECK(!mapped_);
91 DCHECK(native_window_); 99 DCHECK(native_window_);
92 ANativeWindow_Buffer buffer; 100 ANativeWindow_Buffer buffer;
93 int status = ANativeWindow_lock(native_window_, &buffer, NULL); 101 int status = ANativeWindow_lock(native_window_, &buffer, NULL);
94 if (status) { 102 if (status) {
95 VLOG(1) << "ANativeWindow_lock failed with error code: " << status; 103 VLOG(1) << "ANativeWindow_lock failed with error code: " << status;
96 return NULL; 104 return NULL;
(...skipping 17 matching lines...) Expand all
114 122
115 gfx::GpuMemoryBufferHandle GpuMemoryBufferImplSurfaceTexture::GetHandle() 123 gfx::GpuMemoryBufferHandle GpuMemoryBufferImplSurfaceTexture::GetHandle()
116 const { 124 const {
117 gfx::GpuMemoryBufferHandle handle; 125 gfx::GpuMemoryBufferHandle handle;
118 handle.type = gfx::SURFACE_TEXTURE_BUFFER; 126 handle.type = gfx::SURFACE_TEXTURE_BUFFER;
119 handle.surface_texture_id = surface_texture_id_; 127 handle.surface_texture_id = surface_texture_id_;
120 return handle; 128 return handle;
121 } 129 }
122 130
123 } // namespace content 131 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698