OLD | NEW |
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.h" | 5 #include "content/common/gpu/client/gpu_memory_buffer_impl.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/numerics/safe_math.h" | 8 #include "base/numerics/safe_math.h" |
9 #include "content/common/gpu/client/gpu_memory_buffer_impl_shared_memory.h" | 9 #include "content/common/gpu/client/gpu_memory_buffer_impl_shared_memory.h" |
10 #include "ui/gl/gl_bindings.h" | 10 #include "ui/gl/gl_bindings.h" |
11 #include "ui/gl/gl_image_memory.h" | |
12 | 11 |
13 #if defined(OS_MACOSX) | 12 #if defined(OS_MACOSX) |
14 #include "content/common/gpu/client/gpu_memory_buffer_impl_io_surface.h" | 13 #include "content/common/gpu/client/gpu_memory_buffer_impl_io_surface.h" |
15 #endif | 14 #endif |
16 | 15 |
17 #if defined(OS_ANDROID) | 16 #if defined(OS_ANDROID) |
18 #include "content/common/gpu/client/gpu_memory_buffer_impl_surface_texture.h" | 17 #include "content/common/gpu/client/gpu_memory_buffer_impl_surface_texture.h" |
19 #endif | 18 #endif |
20 | 19 |
21 #if defined(USE_OZONE) | 20 #if defined(USE_OZONE) |
22 #include "content/common/gpu/client/gpu_memory_buffer_impl_ozone_native_buffer.h
" | 21 #include "content/common/gpu/client/gpu_memory_buffer_impl_ozone_native_buffer.h
" |
23 #endif | 22 #endif |
24 | 23 |
25 namespace content { | 24 namespace content { |
26 | 25 |
27 GpuMemoryBufferImpl::GpuMemoryBufferImpl(gfx::GpuMemoryBufferId id, | 26 GpuMemoryBufferImpl::GpuMemoryBufferImpl(gfx::GpuMemoryBufferId id, |
28 const gfx::Size& size, | 27 const gfx::Size& size, |
29 Format format, | 28 Format format, |
30 const DestructionCallback& callback) | 29 const DestructionCallback& callback) |
31 : id_(id), | 30 : id_(id), |
32 size_(size), | 31 size_(size), |
33 format_(format), | 32 format_(format), |
34 callback_(callback), | 33 callback_(callback), |
35 mapped_(false), | 34 mapped_(false), |
36 destruction_sync_point_(0) { | 35 destruction_sync_point_(0) { |
37 DCHECK(gfx::GLImageMemory::ValidSize(size, format)); | |
38 } | 36 } |
39 | 37 |
40 GpuMemoryBufferImpl::~GpuMemoryBufferImpl() { | 38 GpuMemoryBufferImpl::~GpuMemoryBufferImpl() { |
41 callback_.Run(destruction_sync_point_); | 39 callback_.Run(destruction_sync_point_); |
42 } | 40 } |
43 | 41 |
44 // static | 42 // static |
45 scoped_ptr<GpuMemoryBufferImpl> GpuMemoryBufferImpl::CreateFromHandle( | 43 scoped_ptr<GpuMemoryBufferImpl> GpuMemoryBufferImpl::CreateFromHandle( |
46 const gfx::GpuMemoryBufferHandle& handle, | 44 const gfx::GpuMemoryBufferHandle& handle, |
47 const gfx::Size& size, | 45 const gfx::Size& size, |
(...skipping 29 matching lines...) Expand all Loading... |
77 ClientBuffer buffer) { | 75 ClientBuffer buffer) { |
78 return reinterpret_cast<GpuMemoryBufferImpl*>(buffer); | 76 return reinterpret_cast<GpuMemoryBufferImpl*>(buffer); |
79 } | 77 } |
80 | 78 |
81 // static | 79 // static |
82 bool GpuMemoryBufferImpl::StrideInBytes(size_t width, | 80 bool GpuMemoryBufferImpl::StrideInBytes(size_t width, |
83 Format format, | 81 Format format, |
84 size_t* stride_in_bytes) { | 82 size_t* stride_in_bytes) { |
85 base::CheckedNumeric<size_t> s = width; | 83 base::CheckedNumeric<size_t> s = width; |
86 switch (format) { | 84 switch (format) { |
87 case ATCIA: | |
88 case DXT5: | |
89 *stride_in_bytes = width; | |
90 return true; | |
91 case ATC: | |
92 case DXT1: | |
93 case ETC1: | |
94 DCHECK_EQ(width % 2, 0U); | |
95 s /= 2; | |
96 if (!s.IsValid()) | |
97 return false; | |
98 | |
99 *stride_in_bytes = s.ValueOrDie(); | |
100 return true; | |
101 case RGBA_8888: | 85 case RGBA_8888: |
102 case RGBX_8888: | 86 case RGBX_8888: |
103 case BGRA_8888: | 87 case BGRA_8888: |
104 s *= 4; | 88 s *= 4; |
105 if (!s.IsValid()) | 89 if (!s.IsValid()) |
106 return false; | 90 return false; |
107 | 91 |
108 *stride_in_bytes = s.ValueOrDie(); | 92 *stride_in_bytes = s.ValueOrDie(); |
109 return true; | 93 return true; |
110 } | 94 } |
111 | 95 |
112 NOTREACHED(); | 96 NOTREACHED(); |
113 return false; | 97 return false; |
114 } | 98 } |
115 | 99 |
116 gfx::GpuMemoryBuffer::Format GpuMemoryBufferImpl::GetFormat() const { | 100 gfx::GpuMemoryBuffer::Format GpuMemoryBufferImpl::GetFormat() const { |
117 return format_; | 101 return format_; |
118 } | 102 } |
119 | 103 |
120 bool GpuMemoryBufferImpl::IsMapped() const { | 104 bool GpuMemoryBufferImpl::IsMapped() const { |
121 return mapped_; | 105 return mapped_; |
122 } | 106 } |
123 | 107 |
124 ClientBuffer GpuMemoryBufferImpl::AsClientBuffer() { | 108 ClientBuffer GpuMemoryBufferImpl::AsClientBuffer() { |
125 return reinterpret_cast<ClientBuffer>(this); | 109 return reinterpret_cast<ClientBuffer>(this); |
126 } | 110 } |
127 | 111 |
128 } // namespace content | 112 } // namespace content |
OLD | NEW |