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

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

Issue 1051503003: Add R_8 GPU memory buffers format. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix validation problem in StrideInBytes. Deals with GL_RED/GL_LUMINANCE. Created 5 years, 8 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
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.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"
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
73 // static 73 // static
74 GpuMemoryBufferImpl* GpuMemoryBufferImpl::FromClientBuffer( 74 GpuMemoryBufferImpl* GpuMemoryBufferImpl::FromClientBuffer(
75 ClientBuffer buffer) { 75 ClientBuffer buffer) {
76 return reinterpret_cast<GpuMemoryBufferImpl*>(buffer); 76 return reinterpret_cast<GpuMemoryBufferImpl*>(buffer);
77 } 77 }
78 78
79 // static 79 // static
80 bool GpuMemoryBufferImpl::StrideInBytes(size_t width, 80 bool GpuMemoryBufferImpl::StrideInBytes(size_t width,
81 Format format, 81 Format format,
82 size_t* stride_in_bytes) { 82 size_t* stride_in_bytes) {
83 base::CheckedNumeric<size_t> s = width; 83 base::CheckedNumeric<size_t> checked_stride = width;
84 switch (format) { 84 switch (format) {
85 case ATCIA: 85 case GpuMemoryBuffer::R_8:
86 case DXT5: 86 checked_stride = (checked_stride + 3) % 4;
reveman 2015/04/01 13:14:33 I assume this is a typo and should be "(width + 3)
Daniele Castagna 2015/04/01 21:58:34 Ops, I was trying to break some test to see if thi
87 *stride_in_bytes = width; 87 break;
88 return true; 88 case GpuMemoryBuffer::ATCIA:
89 case ATC: 89 case GpuMemoryBuffer::DXT5: // 'checked_stride' is the same as 'width'.
reveman 2015/04/01 13:14:33 nit: no need for checked_stride in this case
Daniele Castagna 2015/04/01 21:58:34 Done.
90 case DXT1: 90 break;
91 case ETC1: 91 case GpuMemoryBuffer::ATC:
92 case GpuMemoryBuffer::DXT1:
93 case GpuMemoryBuffer::ETC1:
92 DCHECK_EQ(width % 2, 0U); 94 DCHECK_EQ(width % 2, 0U);
reveman 2015/04/01 13:14:33 nit: ..., 0u);
Daniele Castagna 2015/04/01 21:58:34 Done.
93 s /= 2; 95 checked_stride /= 2;
reveman 2015/04/01 13:14:33 no need for checked_stride in this case.
Daniele Castagna 2015/04/01 21:58:34 Done.
94 if (!s.IsValid()) 96 break;
95 return false; 97 case GpuMemoryBuffer::RGBA_8888:
96 98 case GpuMemoryBuffer::RGBX_8888:
97 *stride_in_bytes = s.ValueOrDie(); 99 case GpuMemoryBuffer::BGRA_8888:
98 return true; 100 checked_stride *= 4;
99 case RGBA_8888: 101 break;
100 case RGBX_8888:
101 case BGRA_8888:
102 s *= 4;
103 if (!s.IsValid())
104 return false;
105
106 *stride_in_bytes = s.ValueOrDie();
107 return true;
108 } 102 }
109 103 if (!checked_stride.IsValid())
110 NOTREACHED(); 104 return false;
reveman 2015/04/01 13:14:33 I like to keep this condition. ie detect if format
Daniele Castagna 2015/04/01 21:58:34 Done as you suggested. For the sake of arguing: I
reveman 2015/04/01 23:38:55 Ok, fair enough.
111 return false; 105 *stride_in_bytes = checked_stride.ValueOrDie();
106 return true;
112 } 107 }
113 108
114 // static 109 // static
115 size_t GpuMemoryBufferImpl::NumberOfPlanesForGpuMemoryBufferFormat( 110 size_t GpuMemoryBufferImpl::NumberOfPlanesForGpuMemoryBufferFormat(
116 gfx::GpuMemoryBuffer::Format format) { 111 gfx::GpuMemoryBuffer::Format format) {
117 switch (format) { 112 switch (format) {
118 case gfx::GpuMemoryBuffer::Format::ATC: 113 case gfx::GpuMemoryBuffer::Format::ATC:
119 case gfx::GpuMemoryBuffer::Format::ATCIA: 114 case gfx::GpuMemoryBuffer::Format::ATCIA:
120 case gfx::GpuMemoryBuffer::Format::DXT1: 115 case gfx::GpuMemoryBuffer::Format::DXT1:
121 case gfx::GpuMemoryBuffer::Format::DXT5: 116 case gfx::GpuMemoryBuffer::Format::DXT5:
122 case gfx::GpuMemoryBuffer::Format::ETC1: 117 case gfx::GpuMemoryBuffer::Format::ETC1:
118 case gfx::GpuMemoryBuffer::Format::R_8:
123 case gfx::GpuMemoryBuffer::Format::RGBA_8888: 119 case gfx::GpuMemoryBuffer::Format::RGBA_8888:
124 case gfx::GpuMemoryBuffer::Format::RGBX_8888: 120 case gfx::GpuMemoryBuffer::Format::RGBX_8888:
125 case gfx::GpuMemoryBuffer::Format::BGRA_8888: 121 case gfx::GpuMemoryBuffer::Format::BGRA_8888:
126 return 1; 122 return 1;
127 default: 123 default:
128 NOTREACHED(); 124 NOTREACHED();
129 return 0; 125 return 0;
130 } 126 }
131 } 127 }
132 128
133 gfx::GpuMemoryBuffer::Format GpuMemoryBufferImpl::GetFormat() const { 129 gfx::GpuMemoryBuffer::Format GpuMemoryBufferImpl::GetFormat() const {
134 return format_; 130 return format_;
135 } 131 }
136 132
137 bool GpuMemoryBufferImpl::IsMapped() const { 133 bool GpuMemoryBufferImpl::IsMapped() const {
138 return mapped_; 134 return mapped_;
139 } 135 }
140 136
141 ClientBuffer GpuMemoryBufferImpl::AsClientBuffer() { 137 ClientBuffer GpuMemoryBufferImpl::AsClientBuffer() {
142 return reinterpret_cast<ClientBuffer>(this); 138 return reinterpret_cast<ClientBuffer>(this);
143 } 139 }
144 140
145 } // namespace content 141 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698