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

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

Issue 263553009: content: Cleanup GpuMemoryBuffer allocation. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: mac build fix Created 6 years, 7 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 | Annotate | Revision Log
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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_io_surface.h" 5 #include "content/common/gpu/client/gpu_memory_buffer_impl_io_surface.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "ui/gl/gl_bindings.h" 8 #include "ui/gl/gl_bindings.h"
9 #include "ui/gl/io_surface_support_mac.h" 9 #include "ui/gl/io_surface_support_mac.h"
10 10
11 namespace content { 11 namespace content {
12 12
13 GpuMemoryBufferImplIOSurface::GpuMemoryBufferImplIOSurface( 13 GpuMemoryBufferImplIOSurface::GpuMemoryBufferImplIOSurface(
14 gfx::Size size, 14 const gfx::Size& size,
15 unsigned internalformat) 15 unsigned internalformat)
16 : GpuMemoryBufferImpl(size, internalformat), 16 : GpuMemoryBufferImpl(size, internalformat),
17 io_surface_support_(IOSurfaceSupport::Initialize()) { 17 io_surface_support_(IOSurfaceSupport::Initialize()) {
18 CHECK(io_surface_support_); 18 CHECK(io_surface_support_);
19 } 19 }
20 20
21 GpuMemoryBufferImplIOSurface::~GpuMemoryBufferImplIOSurface() {} 21 GpuMemoryBufferImplIOSurface::~GpuMemoryBufferImplIOSurface() {}
22 22
23 // static 23 // static
24 bool GpuMemoryBufferImplIOSurface::IsFormatSupported(unsigned internalformat) { 24 bool GpuMemoryBufferImplIOSurface::IsFormatSupported(unsigned internalformat) {
25 switch (internalformat) { 25 switch (internalformat) {
26 case GL_BGRA8_EXT: 26 case GL_BGRA8_EXT:
27 return true; 27 return true;
28 default: 28 default:
29 return false; 29 return false;
30 } 30 }
31 } 31 }
32 32
33 // static 33 // static
34 bool GpuMemoryBufferImplIOSurface::IsUsageSupported(unsigned usage) { 34 bool GpuMemoryBufferImplIOSurface::IsUsageSupported(unsigned usage) {
35 switch (usage) { 35 switch (usage) {
36 case GL_IMAGE_MAP_CHROMIUM: 36 case GL_IMAGE_MAP_CHROMIUM:
37 return true; 37 return true;
38 default: 38 default:
39 return false; 39 return false;
40 } 40 }
41 } 41 }
42 42
43 // static 43 // static
44 bool GpuMemoryBufferImplIOSurface::IsConfigurationSupported(
45 unsigned internalformat,
46 unsigned usage) {
47 return IsFormatSupported(internalformat) && IsUsageSupported(usage);
48 }
49
50 // static
44 uint32 GpuMemoryBufferImplIOSurface::PixelFormat(unsigned internalformat) { 51 uint32 GpuMemoryBufferImplIOSurface::PixelFormat(unsigned internalformat) {
45 switch (internalformat) { 52 switch (internalformat) {
46 case GL_BGRA8_EXT: 53 case GL_BGRA8_EXT:
47 return 'BGRA'; 54 return 'BGRA';
48 default: 55 default:
49 NOTREACHED(); 56 NOTREACHED();
50 return 0; 57 return 0;
51 } 58 }
52 } 59 }
53 60
54 bool GpuMemoryBufferImplIOSurface::Initialize( 61 bool GpuMemoryBufferImplIOSurface::InitializeFromHandle(
55 gfx::GpuMemoryBufferHandle handle) { 62 gfx::GpuMemoryBufferHandle handle) {
63 DCHECK(IsFormatSupported(internalformat_));
56 io_surface_.reset(io_surface_support_->IOSurfaceLookup(handle.io_surface_id)); 64 io_surface_.reset(io_surface_support_->IOSurfaceLookup(handle.io_surface_id));
57 if (!io_surface_) { 65 if (!io_surface_) {
58 VLOG(1) << "IOSurface lookup failed"; 66 VLOG(1) << "IOSurface lookup failed";
59 return false; 67 return false;
60 } 68 }
61 69
62 return true; 70 return true;
63 } 71 }
64 72
65 void* GpuMemoryBufferImplIOSurface::Map() { 73 void* GpuMemoryBufferImplIOSurface::Map() {
(...skipping 14 matching lines...) Expand all
80 } 88 }
81 89
82 gfx::GpuMemoryBufferHandle GpuMemoryBufferImplIOSurface::GetHandle() const { 90 gfx::GpuMemoryBufferHandle GpuMemoryBufferImplIOSurface::GetHandle() const {
83 gfx::GpuMemoryBufferHandle handle; 91 gfx::GpuMemoryBufferHandle handle;
84 handle.type = gfx::IO_SURFACE_BUFFER; 92 handle.type = gfx::IO_SURFACE_BUFFER;
85 handle.io_surface_id = io_surface_support_->IOSurfaceGetID(io_surface_); 93 handle.io_surface_id = io_surface_support_->IOSurfaceGetID(io_surface_);
86 return handle; 94 return handle;
87 } 95 }
88 96
89 } // namespace content 97 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698