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

Side by Side Diff: ui/gl/gl_image_memory.cc

Issue 1078253002: gfx namespace cleanup. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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
« no previous file with comments | « ui/gl/gl_image_memory.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "ui/gl/gl_image_memory.h" 5 #include "ui/gl/gl_image_memory.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/trace_event/trace_event.h" 8 #include "base/trace_event/trace_event.h"
9 #include "ui/gl/gl_bindings.h" 9 #include "ui/gl/gl_bindings.h"
10 #include "ui/gl/scoped_binders.h" 10 #include "ui/gl/scoped_binders.h"
(...skipping 10 matching lines...) Expand all
21 switch (internalformat) { 21 switch (internalformat) {
22 case GL_R8: 22 case GL_R8:
23 case GL_RGBA: 23 case GL_RGBA:
24 case GL_BGRA_EXT: 24 case GL_BGRA_EXT:
25 return true; 25 return true;
26 default: 26 default:
27 return false; 27 return false;
28 } 28 }
29 } 29 }
30 30
31 bool ValidFormat(gfx::GpuMemoryBuffer::Format format) { 31 bool ValidFormat(GpuMemoryBuffer::Format format) {
32 switch (format) { 32 switch (format) {
33 case gfx::GpuMemoryBuffer::ATC: 33 case GpuMemoryBuffer::ATC:
34 case gfx::GpuMemoryBuffer::ATCIA: 34 case GpuMemoryBuffer::ATCIA:
35 case gfx::GpuMemoryBuffer::DXT1: 35 case GpuMemoryBuffer::DXT1:
36 case gfx::GpuMemoryBuffer::DXT5: 36 case GpuMemoryBuffer::DXT5:
37 case gfx::GpuMemoryBuffer::ETC1: 37 case GpuMemoryBuffer::ETC1:
38 case gfx::GpuMemoryBuffer::R_8: 38 case GpuMemoryBuffer::R_8:
39 case gfx::GpuMemoryBuffer::RGBA_8888: 39 case GpuMemoryBuffer::RGBA_8888:
40 case gfx::GpuMemoryBuffer::BGRA_8888: 40 case GpuMemoryBuffer::BGRA_8888:
41 return true; 41 return true;
42 case gfx::GpuMemoryBuffer::RGBX_8888: 42 case GpuMemoryBuffer::RGBX_8888:
43 case gfx::GpuMemoryBuffer::YUV_420: 43 case GpuMemoryBuffer::YUV_420:
44 return false; 44 return false;
45 } 45 }
46 46
47 NOTREACHED(); 47 NOTREACHED();
48 return false; 48 return false;
49 } 49 }
50 50
51 bool IsCompressedFormat(gfx::GpuMemoryBuffer::Format format) { 51 bool IsCompressedFormat(GpuMemoryBuffer::Format format) {
52 switch (format) { 52 switch (format) {
53 case gfx::GpuMemoryBuffer::ATC: 53 case GpuMemoryBuffer::ATC:
54 case gfx::GpuMemoryBuffer::ATCIA: 54 case GpuMemoryBuffer::ATCIA:
55 case gfx::GpuMemoryBuffer::DXT1: 55 case GpuMemoryBuffer::DXT1:
56 case gfx::GpuMemoryBuffer::DXT5: 56 case GpuMemoryBuffer::DXT5:
57 case gfx::GpuMemoryBuffer::ETC1: 57 case GpuMemoryBuffer::ETC1:
58 case gfx::GpuMemoryBuffer::YUV_420: 58 case GpuMemoryBuffer::YUV_420:
59 return true; 59 return true;
60 case gfx::GpuMemoryBuffer::R_8: 60 case GpuMemoryBuffer::R_8:
61 case gfx::GpuMemoryBuffer::RGBA_8888: 61 case GpuMemoryBuffer::RGBA_8888:
62 case gfx::GpuMemoryBuffer::BGRA_8888: 62 case GpuMemoryBuffer::BGRA_8888:
63 case gfx::GpuMemoryBuffer::RGBX_8888: 63 case GpuMemoryBuffer::RGBX_8888:
64 return false; 64 return false;
65 } 65 }
66 66
67 NOTREACHED(); 67 NOTREACHED();
68 return false; 68 return false;
69 } 69 }
70 70
71 GLenum TextureFormat(gfx::GpuMemoryBuffer::Format format) { 71 GLenum TextureFormat(GpuMemoryBuffer::Format format) {
72 switch (format) { 72 switch (format) {
73 case gfx::GpuMemoryBuffer::ATC: 73 case GpuMemoryBuffer::ATC:
74 return GL_ATC_RGB_AMD; 74 return GL_ATC_RGB_AMD;
75 case gfx::GpuMemoryBuffer::ATCIA: 75 case GpuMemoryBuffer::ATCIA:
76 return GL_ATC_RGBA_INTERPOLATED_ALPHA_AMD; 76 return GL_ATC_RGBA_INTERPOLATED_ALPHA_AMD;
77 case gfx::GpuMemoryBuffer::DXT1: 77 case GpuMemoryBuffer::DXT1:
78 return GL_COMPRESSED_RGB_S3TC_DXT1_EXT; 78 return GL_COMPRESSED_RGB_S3TC_DXT1_EXT;
79 case gfx::GpuMemoryBuffer::DXT5: 79 case GpuMemoryBuffer::DXT5:
80 return GL_COMPRESSED_RGBA_S3TC_DXT5_EXT; 80 return GL_COMPRESSED_RGBA_S3TC_DXT5_EXT;
81 case gfx::GpuMemoryBuffer::ETC1: 81 case GpuMemoryBuffer::ETC1:
82 return GL_ETC1_RGB8_OES; 82 return GL_ETC1_RGB8_OES;
83 case gfx::GpuMemoryBuffer::R_8: 83 case GpuMemoryBuffer::R_8:
84 return GL_RED; 84 return GL_RED;
85 case gfx::GpuMemoryBuffer::RGBA_8888: 85 case GpuMemoryBuffer::RGBA_8888:
86 return GL_RGBA; 86 return GL_RGBA;
87 case gfx::GpuMemoryBuffer::BGRA_8888: 87 case GpuMemoryBuffer::BGRA_8888:
88 return GL_BGRA_EXT; 88 return GL_BGRA_EXT;
89 case gfx::GpuMemoryBuffer::RGBX_8888: 89 case GpuMemoryBuffer::RGBX_8888:
90 case gfx::GpuMemoryBuffer::YUV_420: 90 case GpuMemoryBuffer::YUV_420:
91 NOTREACHED(); 91 NOTREACHED();
92 return 0; 92 return 0;
93 } 93 }
94 94
95 NOTREACHED(); 95 NOTREACHED();
96 return 0; 96 return 0;
97 } 97 }
98 98
99 GLenum DataFormat(gfx::GpuMemoryBuffer::Format format) { 99 GLenum DataFormat(GpuMemoryBuffer::Format format) {
100 return TextureFormat(format); 100 return TextureFormat(format);
101 } 101 }
102 102
103 GLenum DataType(gfx::GpuMemoryBuffer::Format format) { 103 GLenum DataType(GpuMemoryBuffer::Format format) {
104 switch (format) { 104 switch (format) {
105 case gfx::GpuMemoryBuffer::RGBA_8888: 105 case GpuMemoryBuffer::RGBA_8888:
106 case gfx::GpuMemoryBuffer::BGRA_8888: 106 case GpuMemoryBuffer::BGRA_8888:
107 case gfx::GpuMemoryBuffer::R_8: 107 case GpuMemoryBuffer::R_8:
108 return GL_UNSIGNED_BYTE; 108 return GL_UNSIGNED_BYTE;
109 case gfx::GpuMemoryBuffer::ATC: 109 case GpuMemoryBuffer::ATC:
110 case gfx::GpuMemoryBuffer::ATCIA: 110 case GpuMemoryBuffer::ATCIA:
111 case gfx::GpuMemoryBuffer::DXT1: 111 case GpuMemoryBuffer::DXT1:
112 case gfx::GpuMemoryBuffer::DXT5: 112 case GpuMemoryBuffer::DXT5:
113 case gfx::GpuMemoryBuffer::ETC1: 113 case GpuMemoryBuffer::ETC1:
114 case gfx::GpuMemoryBuffer::RGBX_8888: 114 case GpuMemoryBuffer::RGBX_8888:
115 case gfx::GpuMemoryBuffer::YUV_420: 115 case GpuMemoryBuffer::YUV_420:
116 NOTREACHED(); 116 NOTREACHED();
117 return 0; 117 return 0;
118 } 118 }
119 119
120 NOTREACHED(); 120 NOTREACHED();
121 return 0; 121 return 0;
122 } 122 }
123 123
124 GLsizei SizeInBytes(const gfx::Size& size, 124 GLsizei SizeInBytes(const Size& size,
125 gfx::GpuMemoryBuffer::Format format) { 125 GpuMemoryBuffer::Format format) {
126 size_t stride_in_bytes = 0; 126 size_t stride_in_bytes = 0;
127 bool valid_stride = GLImageMemory::StrideInBytes( 127 bool valid_stride = GLImageMemory::StrideInBytes(
128 size.width(), format, &stride_in_bytes); 128 size.width(), format, &stride_in_bytes);
129 DCHECK(valid_stride); 129 DCHECK(valid_stride);
130 return static_cast<GLsizei>(stride_in_bytes * size.height()); 130 return static_cast<GLsizei>(stride_in_bytes * size.height());
131 } 131 }
132 132
133 } // namespace 133 } // namespace
134 134
135 GLImageMemory::GLImageMemory(const gfx::Size& size, unsigned internalformat) 135 GLImageMemory::GLImageMemory(const Size& size, unsigned internalformat)
136 : size_(size), 136 : size_(size),
137 internalformat_(internalformat), 137 internalformat_(internalformat),
138 memory_(NULL), 138 memory_(NULL),
139 format_(gfx::GpuMemoryBuffer::RGBA_8888), 139 format_(GpuMemoryBuffer::RGBA_8888),
140 in_use_(false), 140 in_use_(false),
141 target_(0), 141 target_(0),
142 need_do_bind_tex_image_(false) 142 need_do_bind_tex_image_(false)
143 #if defined(OS_WIN) || defined(USE_X11) || defined(OS_ANDROID) || \ 143 #if defined(OS_WIN) || defined(USE_X11) || defined(OS_ANDROID) || \
144 defined(USE_OZONE) 144 defined(USE_OZONE)
145 , 145 ,
146 egl_texture_id_(0u), 146 egl_texture_id_(0u),
147 egl_image_(EGL_NO_IMAGE_KHR) 147 egl_image_(EGL_NO_IMAGE_KHR)
148 #endif 148 #endif
149 { 149 {
150 } 150 }
151 151
152 GLImageMemory::~GLImageMemory() { 152 GLImageMemory::~GLImageMemory() {
153 #if defined(OS_WIN) || defined(USE_X11) || defined(OS_ANDROID) || \ 153 #if defined(OS_WIN) || defined(USE_X11) || defined(OS_ANDROID) || \
154 defined(USE_OZONE) 154 defined(USE_OZONE)
155 DCHECK_EQ(EGL_NO_IMAGE_KHR, egl_image_); 155 DCHECK_EQ(EGL_NO_IMAGE_KHR, egl_image_);
156 DCHECK_EQ(0u, egl_texture_id_); 156 DCHECK_EQ(0u, egl_texture_id_);
157 #endif 157 #endif
158 } 158 }
159 159
160 // static 160 // static
161 bool GLImageMemory::StrideInBytes(size_t width, 161 bool GLImageMemory::StrideInBytes(size_t width,
162 gfx::GpuMemoryBuffer::Format format, 162 GpuMemoryBuffer::Format format,
163 size_t* stride_in_bytes) { 163 size_t* stride_in_bytes) {
164 base::CheckedNumeric<size_t> checked_stride = width; 164 base::CheckedNumeric<size_t> checked_stride = width;
165 switch (format) { 165 switch (format) {
166 case gfx::GpuMemoryBuffer::ATCIA: 166 case GpuMemoryBuffer::ATCIA:
167 case gfx::GpuMemoryBuffer::DXT5: 167 case GpuMemoryBuffer::DXT5:
168 *stride_in_bytes = width; 168 *stride_in_bytes = width;
169 return true; 169 return true;
170 case gfx::GpuMemoryBuffer::ATC: 170 case GpuMemoryBuffer::ATC:
171 case gfx::GpuMemoryBuffer::DXT1: 171 case GpuMemoryBuffer::DXT1:
172 case gfx::GpuMemoryBuffer::ETC1: 172 case GpuMemoryBuffer::ETC1:
173 DCHECK_EQ(width % 2, 0u); 173 DCHECK_EQ(width % 2, 0u);
174 *stride_in_bytes = width / 2; 174 *stride_in_bytes = width / 2;
175 return true; 175 return true;
176 case gfx::GpuMemoryBuffer::R_8: 176 case GpuMemoryBuffer::R_8:
177 checked_stride += 3; 177 checked_stride += 3;
178 if (!checked_stride.IsValid()) 178 if (!checked_stride.IsValid())
179 return false; 179 return false;
180 *stride_in_bytes = checked_stride.ValueOrDie() & ~0x3; 180 *stride_in_bytes = checked_stride.ValueOrDie() & ~0x3;
181 return true; 181 return true;
182 case gfx::GpuMemoryBuffer::RGBA_8888: 182 case GpuMemoryBuffer::RGBA_8888:
183 case gfx::GpuMemoryBuffer::BGRA_8888: 183 case GpuMemoryBuffer::BGRA_8888:
184 checked_stride *= 4; 184 checked_stride *= 4;
185 if (!checked_stride.IsValid()) 185 if (!checked_stride.IsValid())
186 return false; 186 return false;
187 *stride_in_bytes = checked_stride.ValueOrDie(); 187 *stride_in_bytes = checked_stride.ValueOrDie();
188 return true; 188 return true;
189 case gfx::GpuMemoryBuffer::RGBX_8888: 189 case GpuMemoryBuffer::RGBX_8888:
190 case gfx::GpuMemoryBuffer::YUV_420: 190 case GpuMemoryBuffer::YUV_420:
191 NOTREACHED(); 191 NOTREACHED();
192 return false; 192 return false;
193 } 193 }
194 194
195 NOTREACHED(); 195 NOTREACHED();
196 return false; 196 return false;
197 } 197 }
198 198
199 bool GLImageMemory::Initialize(const unsigned char* memory, 199 bool GLImageMemory::Initialize(const unsigned char* memory,
200 gfx::GpuMemoryBuffer::Format format) { 200 GpuMemoryBuffer::Format format) {
201 if (!ValidInternalFormat(internalformat_)) { 201 if (!ValidInternalFormat(internalformat_)) {
202 LOG(ERROR) << "Invalid internalformat: " << internalformat_; 202 LOG(ERROR) << "Invalid internalformat: " << internalformat_;
203 return false; 203 return false;
204 } 204 }
205 205
206 if (!ValidFormat(format)) { 206 if (!ValidFormat(format)) {
207 LOG(ERROR) << "Invalid format: " << format; 207 LOG(ERROR) << "Invalid format: " << format;
208 return false; 208 return false;
209 } 209 }
210 210
(...skipping 16 matching lines...) Expand all
227 227
228 if (egl_texture_id_) { 228 if (egl_texture_id_) {
229 if (have_context) 229 if (have_context)
230 glDeleteTextures(1, &egl_texture_id_); 230 glDeleteTextures(1, &egl_texture_id_);
231 egl_texture_id_ = 0u; 231 egl_texture_id_ = 0u;
232 } 232 }
233 #endif 233 #endif
234 memory_ = NULL; 234 memory_ = NULL;
235 } 235 }
236 236
237 gfx::Size GLImageMemory::GetSize() { 237 Size GLImageMemory::GetSize() {
238 return size_; 238 return size_;
239 } 239 }
240 240
241 bool GLImageMemory::BindTexImage(unsigned target) { 241 bool GLImageMemory::BindTexImage(unsigned target) {
242 if (target_ && target_ != target) { 242 if (target_ && target_ != target) {
243 LOG(ERROR) << "GLImage can only be bound to one target"; 243 LOG(ERROR) << "GLImage can only be bound to one target";
244 return false; 244 return false;
245 } 245 }
246 target_ = target; 246 target_ = target;
247 247
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
291 291
292 DCHECK(target_); 292 DCHECK(target_);
293 DoBindTexImage(target_); 293 DoBindTexImage(target_);
294 } 294 }
295 295
296 void GLImageMemory::DidUseTexImage() { 296 void GLImageMemory::DidUseTexImage() {
297 DCHECK(in_use_); 297 DCHECK(in_use_);
298 in_use_ = false; 298 in_use_ = false;
299 } 299 }
300 300
301 bool GLImageMemory::ScheduleOverlayPlane(gfx::AcceleratedWidget widget, 301 bool GLImageMemory::ScheduleOverlayPlane(AcceleratedWidget widget,
302 int z_order, 302 int z_order,
303 OverlayTransform transform, 303 OverlayTransform transform,
304 const Rect& bounds_rect, 304 const Rect& bounds_rect,
305 const RectF& crop_rect) { 305 const RectF& crop_rect) {
306 return false; 306 return false;
307 } 307 }
308 308
309 void GLImageMemory::DoBindTexImage(unsigned target) { 309 void GLImageMemory::DoBindTexImage(unsigned target) {
310 TRACE_EVENT0("gpu", "GLImageMemory::DoBindTexImage"); 310 TRACE_EVENT0("gpu", "GLImageMemory::DoBindTexImage");
311 311
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
402 size_.width(), 402 size_.width(),
403 size_.height(), 403 size_.height(),
404 0, // border 404 0, // border
405 DataFormat(format_), 405 DataFormat(format_),
406 DataType(format_), 406 DataType(format_),
407 memory_); 407 memory_);
408 } 408 }
409 } 409 }
410 410
411 } // namespace gfx 411 } // namespace gfx
OLDNEW
« no previous file with comments | « ui/gl/gl_image_memory.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698