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 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 63 NOTREACHED(); | 63 NOTREACHED(); |
| 64 return 0; | 64 return 0; |
| 65 } | 65 } |
| 66 } | 66 } |
| 67 | 67 |
| 68 } // namespace | 68 } // namespace |
| 69 | 69 |
| 70 GLImageMemory::GLImageMemory(const gfx::Size& size, unsigned internalformat) | 70 GLImageMemory::GLImageMemory(const gfx::Size& size, unsigned internalformat) |
| 71 : memory_(NULL), | 71 : memory_(NULL), |
| 72 size_(size), | 72 size_(size), |
| 73 internalformat_(internalformat) | 73 internalformat_(internalformat), |
| 74 in_use_(false), | |
| 75 target_(0), | |
| 76 need_do_bind_tex_image_(false) | |
| 74 #if defined(OS_WIN) || defined(USE_X11) || defined(OS_ANDROID) || \ | 77 #if defined(OS_WIN) || defined(USE_X11) || defined(OS_ANDROID) || \ |
| 75 defined(USE_OZONE) | 78 defined(USE_OZONE) |
| 76 , | 79 , |
| 77 egl_texture_id_(0u), | 80 egl_texture_id_(0u), |
| 78 egl_image_(EGL_NO_IMAGE_KHR) | 81 egl_image_(EGL_NO_IMAGE_KHR) |
| 79 #endif | 82 #endif |
| 80 { | 83 { |
| 81 } | 84 } |
| 82 | 85 |
| 83 GLImageMemory::~GLImageMemory() { | 86 GLImageMemory::~GLImageMemory() { |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 115 } | 118 } |
| 116 #endif | 119 #endif |
| 117 memory_ = NULL; | 120 memory_ = NULL; |
| 118 } | 121 } |
| 119 | 122 |
| 120 gfx::Size GLImageMemory::GetSize() { | 123 gfx::Size GLImageMemory::GetSize() { |
| 121 return size_; | 124 return size_; |
| 122 } | 125 } |
| 123 | 126 |
| 124 bool GLImageMemory::BindTexImage(unsigned target) { | 127 bool GLImageMemory::BindTexImage(unsigned target) { |
| 125 TRACE_EVENT0("gpu", "GLImageMemory::BindTexImage"); | 128 target_ = target; |
| 129 | |
| 130 // Defer DoBindTexImage if not currently in use. | |
| 131 if (!in_use_) { | |
| 132 need_do_bind_tex_image_ = true; | |
| 133 return true; | |
| 134 } | |
| 135 | |
| 136 DoBindTexImage(target); | |
| 137 need_do_bind_tex_image_ = false; | |
|
piman
2014/09/04 17:32:54
nit: move this to DoBindTexImage and save a line.
reveman
2014/09/04 18:57:43
Done.
| |
| 138 return true; | |
| 139 } | |
| 140 | |
| 141 bool GLImageMemory::CopyTexImage(unsigned target) { | |
| 142 TRACE_EVENT0("gpu", "GLImageMemory::CopyTexImage"); | |
| 143 | |
| 144 // GL_TEXTURE_EXTERNAL_OES is not a supported CopyTexImage target. | |
| 145 if (target == GL_TEXTURE_EXTERNAL_OES) | |
| 146 return false; | |
| 147 | |
| 148 DCHECK(memory_); | |
| 149 glTexImage2D(target, | |
| 150 0, // mip level | |
| 151 TextureFormat(internalformat_), | |
| 152 size_.width(), | |
| 153 size_.height(), | |
| 154 0, // border | |
| 155 DataFormat(internalformat_), | |
| 156 DataType(internalformat_), | |
| 157 memory_); | |
|
piman
2014/09/04 17:32:54
If the data was already uploaded to the source tex
reveman
2014/09/04 18:57:43
Good point. I made this work by tracking if the im
| |
| 158 | |
| 159 return true; | |
| 160 } | |
| 161 | |
| 162 void GLImageMemory::WillUseTexImage() { | |
| 163 DCHECK(!in_use_); | |
| 164 in_use_ = true; | |
| 165 | |
| 166 if (!need_do_bind_tex_image_) | |
| 167 return; | |
| 168 | |
| 169 DoBindTexImage(target_); | |
| 170 need_do_bind_tex_image_ = false; | |
| 171 } | |
| 172 | |
| 173 void GLImageMemory::DidUseTexImage() { | |
| 174 DCHECK(in_use_); | |
| 175 in_use_ = false; | |
| 176 } | |
| 177 | |
| 178 bool GLImageMemory::ScheduleOverlayPlane(gfx::AcceleratedWidget widget, | |
| 179 int z_order, | |
| 180 OverlayTransform transform, | |
| 181 const Rect& bounds_rect, | |
| 182 const RectF& crop_rect) { | |
| 183 return false; | |
| 184 } | |
| 185 | |
| 186 bool GLImageMemory::HasValidFormat() const { | |
| 187 return ValidFormat(internalformat_); | |
| 188 } | |
| 189 | |
| 190 size_t GLImageMemory::Bytes() const { | |
| 191 return size_.GetArea() * BytesPerPixel(internalformat_); | |
| 192 } | |
| 193 | |
| 194 void GLImageMemory::DoBindTexImage(unsigned target) { | |
| 195 TRACE_EVENT0("gpu", "GLImageMemory::DoBindTexImage"); | |
| 126 | 196 |
| 127 DCHECK(memory_); | 197 DCHECK(memory_); |
| 128 #if defined(OS_WIN) || defined(USE_X11) || defined(OS_ANDROID) || \ | 198 #if defined(OS_WIN) || defined(USE_X11) || defined(OS_ANDROID) || \ |
| 129 defined(USE_OZONE) | 199 defined(USE_OZONE) |
| 130 if (target == GL_TEXTURE_EXTERNAL_OES) { | 200 if (target == GL_TEXTURE_EXTERNAL_OES) { |
| 131 if (egl_image_ == EGL_NO_IMAGE_KHR) { | 201 if (egl_image_ == EGL_NO_IMAGE_KHR) { |
| 132 DCHECK_EQ(0u, egl_texture_id_); | 202 DCHECK_EQ(0u, egl_texture_id_); |
| 133 glGenTextures(1, &egl_texture_id_); | 203 glGenTextures(1, &egl_texture_id_); |
| 134 | 204 |
| 135 { | 205 { |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 169 0, // y-offset | 239 0, // y-offset |
| 170 size_.width(), | 240 size_.width(), |
| 171 size_.height(), | 241 size_.height(), |
| 172 DataFormat(internalformat_), | 242 DataFormat(internalformat_), |
| 173 DataType(internalformat_), | 243 DataType(internalformat_), |
| 174 memory_); | 244 memory_); |
| 175 } | 245 } |
| 176 | 246 |
| 177 glEGLImageTargetTexture2DOES(target, egl_image_); | 247 glEGLImageTargetTexture2DOES(target, egl_image_); |
| 178 DCHECK_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError()); | 248 DCHECK_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError()); |
| 179 | 249 return; |
| 180 return true; | |
| 181 } | 250 } |
| 182 #endif | 251 #endif |
| 183 | 252 |
| 184 DCHECK_NE(static_cast<GLenum>(GL_TEXTURE_EXTERNAL_OES), target); | 253 DCHECK_NE(static_cast<GLenum>(GL_TEXTURE_EXTERNAL_OES), target); |
| 185 glTexImage2D(target, | 254 glTexImage2D(target, |
| 186 0, // mip level | 255 0, // mip level |
| 187 TextureFormat(internalformat_), | 256 TextureFormat(internalformat_), |
| 188 size_.width(), | 257 size_.width(), |
| 189 size_.height(), | 258 size_.height(), |
| 190 0, // border | 259 0, // border |
| 191 DataFormat(internalformat_), | 260 DataFormat(internalformat_), |
| 192 DataType(internalformat_), | 261 DataType(internalformat_), |
| 193 memory_); | 262 memory_); |
| 194 | |
| 195 return true; | |
| 196 } | |
| 197 | |
| 198 bool GLImageMemory::HasValidFormat() const { | |
| 199 return ValidFormat(internalformat_); | |
| 200 } | |
| 201 | |
| 202 size_t GLImageMemory::Bytes() const { | |
| 203 return size_.GetArea() * BytesPerPixel(internalformat_); | |
| 204 } | |
| 205 | |
| 206 bool GLImageMemory::ScheduleOverlayPlane(gfx::AcceleratedWidget widget, | |
| 207 int z_order, | |
| 208 OverlayTransform transform, | |
| 209 const Rect& bounds_rect, | |
| 210 const RectF& crop_rect) { | |
| 211 return false; | |
| 212 } | 263 } |
| 213 | 264 |
| 214 } // namespace gfx | 265 } // namespace gfx |
| OLD | NEW |