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

Unified Diff: content/common/gpu/client/gpu_memory_buffer_impl.cc

Issue 701033005: content: Move type selection logic out of GpuMemoryBufferImpl. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: remove blank line and add missing CONTENT_EXPORT Created 6 years, 1 month 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 side-by-side diff with in-line comments
Download patch
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);

Powered by Google App Engine
This is Rietveld 408576698