Chromium Code Reviews| Index: content/common/gpu/client/gpu_memory_buffer_impl.cc |
| diff --git a/content/common/gpu/client/gpu_memory_buffer_impl.cc b/content/common/gpu/client/gpu_memory_buffer_impl.cc |
| index 65edde33f1259e49fb1c0fde177646b3f2d3ddff..5a63a7b6c8231175df8202baacd211c67329b12d 100644 |
| --- a/content/common/gpu/client/gpu_memory_buffer_impl.cc |
| +++ b/content/common/gpu/client/gpu_memory_buffer_impl.cc |
| @@ -4,9 +4,28 @@ |
| #include "content/common/gpu/client/gpu_memory_buffer_impl.h" |
| +#include "base/lazy_instance.h" |
| +#include "base/logging.h" |
| #include "ui/gl/gl_bindings.h" |
| namespace content { |
| +namespace { |
| + |
| +gfx::GpuMemoryBufferType g_preferred_type = gfx::EMPTY_BUFFER; |
| + |
| +struct DefaultPreferredType { |
| + DefaultPreferredType() : value(gfx::EMPTY_BUFFER) { |
| + std::vector<gfx::GpuMemoryBufferType> supported_types; |
| + GpuMemoryBufferImpl::GetSupportedTypes(&supported_types); |
| + DCHECK(!supported_types.empty()); |
| + value = supported_types[0]; |
| + } |
| + gfx::GpuMemoryBufferType value; |
| +}; |
| +base::LazyInstance<DefaultPreferredType>::Leaky g_default_preferred_type = |
|
piman
2014/11/11 22:38:30
Why leaky?
reveman
2014/11/12 05:09:20
In case someone would call GetPreferredType() from
piman
2014/11/14 03:59:44
I prefer to avoid leaking if we can...
reveman
2014/11/17 02:26:53
Done.
|
| + LAZY_INSTANCE_INITIALIZER; |
| + |
| +} // namespace |
| GpuMemoryBufferImpl::GpuMemoryBufferImpl(gfx::GpuMemoryBufferId id, |
| const gfx::Size& size, |
| @@ -25,6 +44,26 @@ GpuMemoryBufferImpl::~GpuMemoryBufferImpl() { |
| } |
| // static |
| +void GpuMemoryBufferImpl::SetPreferredType(gfx::GpuMemoryBufferType type) { |
| + // EMPTY_BUFFER is a reserved value and not a valid preferred type. |
| + DCHECK_NE(gfx::EMPTY_BUFFER, type); |
| + |
| + // Make sure this function is only called once before the first call |
| + // to GetPreferredType(). |
| + DCHECK_EQ(gfx::EMPTY_BUFFER, g_preferred_type); |
| + |
| + g_preferred_type = type; |
| +} |
| + |
| +// static |
| +gfx::GpuMemoryBufferType GpuMemoryBufferImpl::GetPreferredType() { |
| + if (g_preferred_type == gfx::EMPTY_BUFFER) |
| + g_preferred_type = g_default_preferred_type.Get().value; |
| + |
| + return g_preferred_type; |
| +} |
| + |
| +// static |
| GpuMemoryBufferImpl* GpuMemoryBufferImpl::FromClientBuffer( |
| ClientBuffer buffer) { |
| return reinterpret_cast<GpuMemoryBufferImpl*>(buffer); |