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/lazy_instance.h" | |
8 #include "base/logging.h" | |
7 #include "ui/gl/gl_bindings.h" | 9 #include "ui/gl/gl_bindings.h" |
8 | 10 |
9 namespace content { | 11 namespace content { |
12 namespace { | |
13 | |
14 gfx::GpuMemoryBufferType g_preferred_type = gfx::EMPTY_BUFFER; | |
15 | |
16 struct DefaultPreferredType { | |
17 DefaultPreferredType() : value(gfx::EMPTY_BUFFER) { | |
18 std::vector<gfx::GpuMemoryBufferType> supported_types; | |
19 GpuMemoryBufferImpl::GetSupportedTypes(&supported_types); | |
20 DCHECK(!supported_types.empty()); | |
21 value = supported_types[0]; | |
22 } | |
23 gfx::GpuMemoryBufferType value; | |
24 }; | |
25 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.
| |
26 LAZY_INSTANCE_INITIALIZER; | |
27 | |
28 } // namespace | |
10 | 29 |
11 GpuMemoryBufferImpl::GpuMemoryBufferImpl(gfx::GpuMemoryBufferId id, | 30 GpuMemoryBufferImpl::GpuMemoryBufferImpl(gfx::GpuMemoryBufferId id, |
12 const gfx::Size& size, | 31 const gfx::Size& size, |
13 Format format, | 32 Format format, |
14 const DestructionCallback& callback) | 33 const DestructionCallback& callback) |
15 : id_(id), | 34 : id_(id), |
16 size_(size), | 35 size_(size), |
17 format_(format), | 36 format_(format), |
18 callback_(callback), | 37 callback_(callback), |
19 mapped_(false), | 38 mapped_(false), |
20 destruction_sync_point_(0) { | 39 destruction_sync_point_(0) { |
21 } | 40 } |
22 | 41 |
23 GpuMemoryBufferImpl::~GpuMemoryBufferImpl() { | 42 GpuMemoryBufferImpl::~GpuMemoryBufferImpl() { |
24 callback_.Run(destruction_sync_point_); | 43 callback_.Run(destruction_sync_point_); |
25 } | 44 } |
26 | 45 |
27 // static | 46 // static |
47 void GpuMemoryBufferImpl::SetPreferredType(gfx::GpuMemoryBufferType type) { | |
48 // EMPTY_BUFFER is a reserved value and not a valid preferred type. | |
49 DCHECK_NE(gfx::EMPTY_BUFFER, type); | |
50 | |
51 // Make sure this function is only called once before the first call | |
52 // to GetPreferredType(). | |
53 DCHECK_EQ(gfx::EMPTY_BUFFER, g_preferred_type); | |
54 | |
55 g_preferred_type = type; | |
56 } | |
57 | |
58 // static | |
59 gfx::GpuMemoryBufferType GpuMemoryBufferImpl::GetPreferredType() { | |
60 if (g_preferred_type == gfx::EMPTY_BUFFER) | |
61 g_preferred_type = g_default_preferred_type.Get().value; | |
62 | |
63 return g_preferred_type; | |
64 } | |
65 | |
66 // static | |
28 GpuMemoryBufferImpl* GpuMemoryBufferImpl::FromClientBuffer( | 67 GpuMemoryBufferImpl* GpuMemoryBufferImpl::FromClientBuffer( |
29 ClientBuffer buffer) { | 68 ClientBuffer buffer) { |
30 return reinterpret_cast<GpuMemoryBufferImpl*>(buffer); | 69 return reinterpret_cast<GpuMemoryBufferImpl*>(buffer); |
31 } | 70 } |
32 | 71 |
33 // static | 72 // static |
34 size_t GpuMemoryBufferImpl::BytesPerPixel(Format format) { | 73 size_t GpuMemoryBufferImpl::BytesPerPixel(Format format) { |
35 switch (format) { | 74 switch (format) { |
36 case RGBA_8888: | 75 case RGBA_8888: |
37 case RGBX_8888: | 76 case RGBX_8888: |
(...skipping 11 matching lines...) Expand all Loading... | |
49 | 88 |
50 bool GpuMemoryBufferImpl::IsMapped() const { | 89 bool GpuMemoryBufferImpl::IsMapped() const { |
51 return mapped_; | 90 return mapped_; |
52 } | 91 } |
53 | 92 |
54 ClientBuffer GpuMemoryBufferImpl::AsClientBuffer() { | 93 ClientBuffer GpuMemoryBufferImpl::AsClientBuffer() { |
55 return reinterpret_cast<ClientBuffer>(this); | 94 return reinterpret_cast<ClientBuffer>(this); |
56 } | 95 } |
57 | 96 |
58 } // namespace content | 97 } // namespace content |
OLD | NEW |