Chromium Code Reviews| OLD | NEW |
|---|---|
| 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/debug/trace_event.h" | 7 #include "base/debug/trace_event.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.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 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 93 | 93 |
| 94 GLImageMemory::~GLImageMemory() { | 94 GLImageMemory::~GLImageMemory() { |
| 95 #if defined(OS_WIN) || defined(USE_X11) || defined(OS_ANDROID) || \ | 95 #if defined(OS_WIN) || defined(USE_X11) || defined(OS_ANDROID) || \ |
| 96 defined(USE_OZONE) | 96 defined(USE_OZONE) |
| 97 DCHECK_EQ(EGL_NO_IMAGE_KHR, egl_image_); | 97 DCHECK_EQ(EGL_NO_IMAGE_KHR, egl_image_); |
| 98 DCHECK_EQ(0u, egl_texture_id_); | 98 DCHECK_EQ(0u, egl_texture_id_); |
| 99 #endif | 99 #endif |
| 100 } | 100 } |
| 101 | 101 |
| 102 // static | 102 // static |
| 103 size_t GLImageMemory::BytesPerPixel(gfx::GpuMemoryBuffer::Format format) { | 103 bool GLImageMemory::StrideInBytes(size_t width, |
| 104 gfx::GpuMemoryBuffer::Format format, | |
| 105 size_t* stride_in_bytes) { | |
| 106 base::CheckedNumeric<size_t> w = width; | |
|
reveman
2015/01/13 16:04:40
nit: s/w/s/ for stride?
| |
| 104 switch (format) { | 107 switch (format) { |
| 105 case gfx::GpuMemoryBuffer::RGBA_8888: | 108 case gfx::GpuMemoryBuffer::RGBA_8888: |
| 106 case gfx::GpuMemoryBuffer::BGRA_8888: | 109 case gfx::GpuMemoryBuffer::BGRA_8888: |
| 107 return 4; | 110 w *= 4; |
| 111 break; | |
| 108 case gfx::GpuMemoryBuffer::RGBX_8888: | 112 case gfx::GpuMemoryBuffer::RGBX_8888: |
| 109 NOTREACHED(); | 113 NOTREACHED(); |
| 110 return 0; | 114 return false; |
| 111 } | 115 } |
| 112 | 116 |
| 113 NOTREACHED(); | 117 if (!w.IsValid()) |
| 114 return 0; | 118 return false; |
| 119 | |
| 120 *stride_in_bytes = w.ValueOrDie(); | |
| 121 return true; | |
|
reveman
2015/01/13 16:04:40
nit: would be nice to have a NOTREACHED check here
| |
| 115 } | 122 } |
| 116 | 123 |
| 117 bool GLImageMemory::Initialize(const unsigned char* memory, | 124 bool GLImageMemory::Initialize(const unsigned char* memory, |
| 118 gfx::GpuMemoryBuffer::Format format) { | 125 gfx::GpuMemoryBuffer::Format format) { |
| 119 if (!ValidInternalFormat(internalformat_)) { | 126 if (!ValidInternalFormat(internalformat_)) { |
| 120 LOG(ERROR) << "Invalid internalformat: " << internalformat_; | 127 LOG(ERROR) << "Invalid internalformat: " << internalformat_; |
| 121 return false; | 128 return false; |
| 122 } | 129 } |
| 123 | 130 |
| 124 if (!ValidFormat(format)) { | 131 if (!ValidFormat(format)) { |
| (...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 280 TextureFormat(format_), | 287 TextureFormat(format_), |
| 281 size_.width(), | 288 size_.width(), |
| 282 size_.height(), | 289 size_.height(), |
| 283 0, // border | 290 0, // border |
| 284 DataFormat(format_), | 291 DataFormat(format_), |
| 285 DataType(format_), | 292 DataType(format_), |
| 286 memory_); | 293 memory_); |
| 287 } | 294 } |
| 288 | 295 |
| 289 } // namespace gfx | 296 } // namespace gfx |
| OLD | NEW |