| 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 if (target_ && target_ != target) { |
| 129 LOG(ERROR) << "GLImage can only be bound to one target"; |
| 130 return false; |
| 131 } |
| 132 target_ = target; |
| 133 |
| 134 // Defer DoBindTexImage if not currently in use. |
| 135 if (!in_use_) { |
| 136 need_do_bind_tex_image_ = true; |
| 137 return true; |
| 138 } |
| 139 |
| 140 DoBindTexImage(target); |
| 141 return true; |
| 142 } |
| 143 |
| 144 bool GLImageMemory::CopyTexImage(unsigned target) { |
| 145 TRACE_EVENT0("gpu", "GLImageMemory::CopyTexImage"); |
| 146 |
| 147 // GL_TEXTURE_EXTERNAL_OES is not a supported CopyTexImage target. |
| 148 if (target == GL_TEXTURE_EXTERNAL_OES) |
| 149 return false; |
| 150 |
| 151 DCHECK(memory_); |
| 152 glTexImage2D(target, |
| 153 0, // mip level |
| 154 TextureFormat(internalformat_), |
| 155 size_.width(), |
| 156 size_.height(), |
| 157 0, // border |
| 158 DataFormat(internalformat_), |
| 159 DataType(internalformat_), |
| 160 memory_); |
| 161 |
| 162 return true; |
| 163 } |
| 164 |
| 165 void GLImageMemory::WillUseTexImage() { |
| 166 DCHECK(!in_use_); |
| 167 in_use_ = true; |
| 168 |
| 169 if (!need_do_bind_tex_image_) |
| 170 return; |
| 171 |
| 172 DCHECK(target_); |
| 173 DoBindTexImage(target_); |
| 174 } |
| 175 |
| 176 void GLImageMemory::DidUseTexImage() { |
| 177 DCHECK(in_use_); |
| 178 in_use_ = false; |
| 179 } |
| 180 |
| 181 bool GLImageMemory::ScheduleOverlayPlane(gfx::AcceleratedWidget widget, |
| 182 int z_order, |
| 183 OverlayTransform transform, |
| 184 const Rect& bounds_rect, |
| 185 const RectF& crop_rect) { |
| 186 return false; |
| 187 } |
| 188 |
| 189 bool GLImageMemory::HasValidFormat() const { |
| 190 return ValidFormat(internalformat_); |
| 191 } |
| 192 |
| 193 size_t GLImageMemory::Bytes() const { |
| 194 return size_.GetArea() * BytesPerPixel(internalformat_); |
| 195 } |
| 196 |
| 197 void GLImageMemory::DoBindTexImage(unsigned target) { |
| 198 TRACE_EVENT0("gpu", "GLImageMemory::DoBindTexImage"); |
| 199 |
| 200 DCHECK(need_do_bind_tex_image_); |
| 201 need_do_bind_tex_image_ = false; |
| 126 | 202 |
| 127 DCHECK(memory_); | 203 DCHECK(memory_); |
| 128 #if defined(OS_WIN) || defined(USE_X11) || defined(OS_ANDROID) || \ | 204 #if defined(OS_WIN) || defined(USE_X11) || defined(OS_ANDROID) || \ |
| 129 defined(USE_OZONE) | 205 defined(USE_OZONE) |
| 130 if (target == GL_TEXTURE_EXTERNAL_OES) { | 206 if (target == GL_TEXTURE_EXTERNAL_OES) { |
| 131 if (egl_image_ == EGL_NO_IMAGE_KHR) { | 207 if (egl_image_ == EGL_NO_IMAGE_KHR) { |
| 132 DCHECK_EQ(0u, egl_texture_id_); | 208 DCHECK_EQ(0u, egl_texture_id_); |
| 133 glGenTextures(1, &egl_texture_id_); | 209 glGenTextures(1, &egl_texture_id_); |
| 134 | 210 |
| 135 { | 211 { |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 169 0, // y-offset | 245 0, // y-offset |
| 170 size_.width(), | 246 size_.width(), |
| 171 size_.height(), | 247 size_.height(), |
| 172 DataFormat(internalformat_), | 248 DataFormat(internalformat_), |
| 173 DataType(internalformat_), | 249 DataType(internalformat_), |
| 174 memory_); | 250 memory_); |
| 175 } | 251 } |
| 176 | 252 |
| 177 glEGLImageTargetTexture2DOES(target, egl_image_); | 253 glEGLImageTargetTexture2DOES(target, egl_image_); |
| 178 DCHECK_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError()); | 254 DCHECK_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError()); |
| 179 | 255 return; |
| 180 return true; | |
| 181 } | 256 } |
| 182 #endif | 257 #endif |
| 183 | 258 |
| 184 DCHECK_NE(static_cast<GLenum>(GL_TEXTURE_EXTERNAL_OES), target); | 259 DCHECK_NE(static_cast<GLenum>(GL_TEXTURE_EXTERNAL_OES), target); |
| 185 glTexImage2D(target, | 260 glTexImage2D(target, |
| 186 0, // mip level | 261 0, // mip level |
| 187 TextureFormat(internalformat_), | 262 TextureFormat(internalformat_), |
| 188 size_.width(), | 263 size_.width(), |
| 189 size_.height(), | 264 size_.height(), |
| 190 0, // border | 265 0, // border |
| 191 DataFormat(internalformat_), | 266 DataFormat(internalformat_), |
| 192 DataType(internalformat_), | 267 DataType(internalformat_), |
| 193 memory_); | 268 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 } | 269 } |
| 213 | 270 |
| 214 } // namespace gfx | 271 } // namespace gfx |
| OLD | NEW |