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 DCHECK(!target_); |
piman
2014/09/04 19:11:10
I don't think we (currently) raise an error if the
reveman
2014/09/04 20:12:44
Ah, right. We should probably add some unit tests
| |
129 target_ = target; | |
130 | |
131 // Defer DoBindTexImage if not currently in use. | |
132 if (!in_use_) { | |
133 need_do_bind_tex_image_ = true; | |
134 return true; | |
135 } | |
136 | |
137 DoBindTexImage(target); | |
138 return true; | |
139 } | |
140 | |
141 void GLImageMemory::ReleaseTexImage(unsigned target) { | |
142 DCHECK_EQ(target_, target); | |
143 target_ = 0; | |
144 } | |
145 | |
146 bool GLImageMemory::CopyTexImage(unsigned target) { | |
147 TRACE_EVENT0("gpu", "GLImageMemory::CopyTexImage"); | |
148 | |
149 // GL_TEXTURE_EXTERNAL_OES is not a supported CopyTexImage target. | |
150 if (target == GL_TEXTURE_EXTERNAL_OES) | |
151 return false; | |
152 | |
153 // The caller can handle this copy more efficiently using general GPU-to-GPU | |
154 // code if image is bound to a texture and data has been uploaded to it. | |
155 if (target_ && !need_do_bind_tex_image_) | |
156 return false; | |
reveman
2014/09/04 20:12:44
I prefer to remove this as there's not really a wa
| |
157 | |
158 DCHECK(memory_); | |
159 glTexImage2D(target, | |
160 0, // mip level | |
161 TextureFormat(internalformat_), | |
162 size_.width(), | |
163 size_.height(), | |
164 0, // border | |
165 DataFormat(internalformat_), | |
166 DataType(internalformat_), | |
167 memory_); | |
168 | |
169 return true; | |
170 } | |
171 | |
172 void GLImageMemory::WillUseTexImage() { | |
173 DCHECK(!in_use_); | |
174 in_use_ = true; | |
175 | |
176 if (!need_do_bind_tex_image_) | |
177 return; | |
178 | |
179 DCHECK(target_); | |
180 DoBindTexImage(target_); | |
181 } | |
182 | |
183 void GLImageMemory::DidUseTexImage() { | |
184 DCHECK(in_use_); | |
185 in_use_ = false; | |
186 } | |
187 | |
188 bool GLImageMemory::ScheduleOverlayPlane(gfx::AcceleratedWidget widget, | |
189 int z_order, | |
190 OverlayTransform transform, | |
191 const Rect& bounds_rect, | |
192 const RectF& crop_rect) { | |
193 return false; | |
194 } | |
195 | |
196 bool GLImageMemory::HasValidFormat() const { | |
197 return ValidFormat(internalformat_); | |
198 } | |
199 | |
200 size_t GLImageMemory::Bytes() const { | |
201 return size_.GetArea() * BytesPerPixel(internalformat_); | |
202 } | |
203 | |
204 void GLImageMemory::DoBindTexImage(unsigned target) { | |
205 TRACE_EVENT0("gpu", "GLImageMemory::DoBindTexImage"); | |
206 | |
207 DCHECK(need_do_bind_tex_image_); | |
208 need_do_bind_tex_image_ = false; | |
126 | 209 |
127 DCHECK(memory_); | 210 DCHECK(memory_); |
128 #if defined(OS_WIN) || defined(USE_X11) || defined(OS_ANDROID) || \ | 211 #if defined(OS_WIN) || defined(USE_X11) || defined(OS_ANDROID) || \ |
129 defined(USE_OZONE) | 212 defined(USE_OZONE) |
130 if (target == GL_TEXTURE_EXTERNAL_OES) { | 213 if (target == GL_TEXTURE_EXTERNAL_OES) { |
131 if (egl_image_ == EGL_NO_IMAGE_KHR) { | 214 if (egl_image_ == EGL_NO_IMAGE_KHR) { |
132 DCHECK_EQ(0u, egl_texture_id_); | 215 DCHECK_EQ(0u, egl_texture_id_); |
133 glGenTextures(1, &egl_texture_id_); | 216 glGenTextures(1, &egl_texture_id_); |
134 | 217 |
135 { | 218 { |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
169 0, // y-offset | 252 0, // y-offset |
170 size_.width(), | 253 size_.width(), |
171 size_.height(), | 254 size_.height(), |
172 DataFormat(internalformat_), | 255 DataFormat(internalformat_), |
173 DataType(internalformat_), | 256 DataType(internalformat_), |
174 memory_); | 257 memory_); |
175 } | 258 } |
176 | 259 |
177 glEGLImageTargetTexture2DOES(target, egl_image_); | 260 glEGLImageTargetTexture2DOES(target, egl_image_); |
178 DCHECK_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError()); | 261 DCHECK_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError()); |
179 | 262 return; |
180 return true; | |
181 } | 263 } |
182 #endif | 264 #endif |
183 | 265 |
184 DCHECK_NE(static_cast<GLenum>(GL_TEXTURE_EXTERNAL_OES), target); | 266 DCHECK_NE(static_cast<GLenum>(GL_TEXTURE_EXTERNAL_OES), target); |
185 glTexImage2D(target, | 267 glTexImage2D(target, |
186 0, // mip level | 268 0, // mip level |
187 TextureFormat(internalformat_), | 269 TextureFormat(internalformat_), |
188 size_.width(), | 270 size_.width(), |
189 size_.height(), | 271 size_.height(), |
190 0, // border | 272 0, // border |
191 DataFormat(internalformat_), | 273 DataFormat(internalformat_), |
192 DataType(internalformat_), | 274 DataType(internalformat_), |
193 memory_); | 275 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 } | 276 } |
213 | 277 |
214 } // namespace gfx | 278 } // namespace gfx |
OLD | NEW |