OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "gpu/command_buffer/service/gles2_cmd_copy_texture_chromium.h" | 5 #include "gpu/command_buffer/service/gles2_cmd_copy_texture_chromium.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
10 #include "gpu/command_buffer/common/gles2_cmd_utils.h" | |
10 #include "gpu/command_buffer/service/gl_utils.h" | 11 #include "gpu/command_buffer/service/gl_utils.h" |
11 #include "gpu/command_buffer/service/gles2_cmd_decoder.h" | 12 #include "gpu/command_buffer/service/gles2_cmd_decoder.h" |
12 | 13 |
13 #define SHADER(src) \ | 14 #define SHADER(src) \ |
14 "#ifdef GL_ES\n" \ | 15 "#ifdef GL_ES\n" \ |
15 "precision mediump float;\n" \ | 16 "precision mediump float;\n" \ |
16 "#define TexCoordPrecision mediump\n" \ | 17 "#define TexCoordPrecision mediump\n" \ |
17 "#else\n" \ | 18 "#else\n" \ |
18 "#define TexCoordPrecision\n" \ | 19 "#define TexCoordPrecision\n" \ |
19 "#endif\n" #src | 20 "#endif\n" #src |
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
193 } | 194 } |
194 | 195 |
195 void DeleteShader(GLuint shader) { | 196 void DeleteShader(GLuint shader) { |
196 if (shader) | 197 if (shader) |
197 glDeleteShader(shader); | 198 glDeleteShader(shader); |
198 } | 199 } |
199 | 200 |
200 bool BindFramebufferTexture2D(GLenum target, | 201 bool BindFramebufferTexture2D(GLenum target, |
201 GLuint texture_id, | 202 GLuint texture_id, |
202 GLuint framebuffer) { | 203 GLuint framebuffer) { |
203 DCHECK(target == GL_TEXTURE_2D || target == GL_TEXTURE_RECTANGLE_ARB); | 204 GLenum binding_target = |
205 gpu::gles2::GLES2Util::GLTextureTargetToBindingTarget(target); | |
206 DCHECK(binding_target == GL_TEXTURE_2D || | |
207 binding_target == GL_TEXTURE_RECTANGLE_ARB || | |
208 binding_target == GL_TEXTURE_CUBE_MAP); | |
204 glActiveTexture(GL_TEXTURE0); | 209 glActiveTexture(GL_TEXTURE0); |
205 glBindTexture(target, texture_id); | 210 glBindTexture(binding_target, texture_id); |
206 // NVidia drivers require texture settings to be a certain way | 211 // NVidia drivers require texture settings to be a certain way |
207 // or they won't report FRAMEBUFFER_COMPLETE. | 212 // or they won't report FRAMEBUFFER_COMPLETE. |
208 glTexParameterf(target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); | 213 glTexParameterf(binding_target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); |
209 glTexParameterf(target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); | 214 glTexParameterf(binding_target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); |
210 glTexParameteri(target, GL_TEXTURE_MAG_FILTER, GL_NEAREST); | 215 glTexParameteri(binding_target, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
211 glTexParameteri(target, GL_TEXTURE_MIN_FILTER, GL_NEAREST); | 216 glTexParameteri(binding_target, GL_TEXTURE_MIN_FILTER, GL_NEAREST); |
212 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, framebuffer); | 217 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, framebuffer); |
213 glFramebufferTexture2DEXT(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, target, | 218 glFramebufferTexture2DEXT(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, target, |
214 texture_id, 0); | 219 texture_id, 0); |
215 | 220 |
216 #ifndef NDEBUG | 221 #ifndef NDEBUG |
217 GLenum fb_status = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER); | 222 GLenum fb_status = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER); |
218 if (GL_FRAMEBUFFER_COMPLETE != fb_status) { | 223 if (GL_FRAMEBUFFER_COMPLETE != fb_status) { |
219 DLOG(ERROR) << "CopyTextureCHROMIUM: Incomplete framebuffer."; | 224 DLOG(ERROR) << "CopyTextureCHROMIUM: Incomplete framebuffer."; |
220 return false; | 225 return false; |
221 } | 226 } |
222 #endif | 227 #endif |
223 return true; | 228 return true; |
224 } | 229 } |
225 | 230 |
226 void DoCopyTexImage2D(const gpu::gles2::GLES2Decoder* decoder, | 231 void DoCopyTexImage2D(const gpu::gles2::GLES2Decoder* decoder, |
227 GLenum source_target, | 232 GLenum source_target, |
228 GLuint source_id, | 233 GLuint source_id, |
234 GLenum dest_target, | |
229 GLuint dest_id, | 235 GLuint dest_id, |
230 GLenum dest_internal_format, | 236 GLenum dest_internal_format, |
231 GLsizei width, | 237 GLsizei width, |
232 GLsizei height, | 238 GLsizei height, |
233 GLuint framebuffer) { | 239 GLuint framebuffer) { |
234 DCHECK(source_target == GL_TEXTURE_2D || | 240 DCHECK(source_target == GL_TEXTURE_2D || |
235 source_target == GL_TEXTURE_RECTANGLE_ARB); | 241 source_target == GL_TEXTURE_RECTANGLE_ARB); |
236 if (BindFramebufferTexture2D(source_target, source_id, framebuffer)) { | 242 if (BindFramebufferTexture2D(source_target, source_id, framebuffer)) { |
237 glBindTexture(GL_TEXTURE_2D, dest_id); | 243 GLenum binding_target = |
238 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); | 244 gpu::gles2::GLES2Util::GLTextureTargetToBindingTarget(dest_target); |
239 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); | 245 glBindTexture(binding_target, dest_id); |
240 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); | 246 glTexParameterf(binding_target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); |
241 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); | 247 glTexParameterf(binding_target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); |
242 glCopyTexImage2D(GL_TEXTURE_2D, 0 /* level */, dest_internal_format, | 248 glTexParameteri(binding_target, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
249 glTexParameteri(binding_target, GL_TEXTURE_MIN_FILTER, GL_NEAREST); | |
250 glCopyTexImage2D(dest_target, 0 /* level */, dest_internal_format, | |
243 0 /* x */, 0 /* y */, width, height, 0 /* border */); | 251 0 /* x */, 0 /* y */, width, height, 0 /* border */); |
244 } | 252 } |
245 | 253 |
246 decoder->RestoreTextureState(source_id); | 254 decoder->RestoreTextureState(source_id); |
247 decoder->RestoreTextureState(dest_id); | 255 decoder->RestoreTextureState(dest_id); |
248 decoder->RestoreTextureUnitBindings(0); | 256 decoder->RestoreTextureUnitBindings(0); |
249 decoder->RestoreActiveTexture(); | 257 decoder->RestoreActiveTexture(); |
250 decoder->RestoreFramebufferBindings(); | 258 decoder->RestoreFramebufferBindings(); |
251 } | 259 } |
252 | 260 |
253 void DoCopyTexSubImage2D(const gpu::gles2::GLES2Decoder* decoder, | 261 void DoCopyTexSubImage2D(const gpu::gles2::GLES2Decoder* decoder, |
254 GLenum source_target, | 262 GLenum source_target, |
255 GLuint source_id, | 263 GLuint source_id, |
264 GLenum dest_target, | |
256 GLuint dest_id, | 265 GLuint dest_id, |
257 GLint xoffset, | 266 GLint xoffset, |
258 GLint yoffset, | 267 GLint yoffset, |
259 GLint source_x, | 268 GLint source_x, |
260 GLint source_y, | 269 GLint source_y, |
261 GLsizei source_width, | 270 GLsizei source_width, |
262 GLsizei source_height, | 271 GLsizei source_height, |
263 GLuint framebuffer) { | 272 GLuint framebuffer) { |
264 DCHECK(source_target == GL_TEXTURE_2D || | 273 DCHECK(source_target == GL_TEXTURE_2D || |
265 source_target == GL_TEXTURE_RECTANGLE_ARB); | 274 source_target == GL_TEXTURE_RECTANGLE_ARB); |
266 if (BindFramebufferTexture2D(source_target, source_id, framebuffer)) { | 275 if (BindFramebufferTexture2D(source_target, source_id, framebuffer)) { |
267 glBindTexture(GL_TEXTURE_2D, dest_id); | 276 GLenum binding_target = |
268 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); | 277 gpu::gles2::GLES2Util::GLTextureTargetToBindingTarget(dest_target); |
269 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); | 278 glBindTexture(binding_target, dest_id); |
270 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); | 279 glTexParameterf(binding_target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); |
271 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); | 280 glTexParameterf(binding_target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); |
272 glCopyTexSubImage2D(GL_TEXTURE_2D, 0 /* level */, xoffset, yoffset, | 281 glTexParameteri(binding_target, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
273 source_x, source_y, source_width, source_height); | 282 glTexParameteri(binding_target, GL_TEXTURE_MIN_FILTER, GL_NEAREST); |
283 glCopyTexSubImage2D(dest_target, 0 /* level */, xoffset, yoffset, source_x, | |
284 source_y, source_width, source_height); | |
274 } | 285 } |
275 | 286 |
276 decoder->RestoreTextureState(source_id); | 287 decoder->RestoreTextureState(source_id); |
277 decoder->RestoreTextureState(dest_id); | 288 decoder->RestoreTextureState(dest_id); |
278 decoder->RestoreTextureUnitBindings(0); | 289 decoder->RestoreTextureUnitBindings(0); |
279 decoder->RestoreActiveTexture(); | 290 decoder->RestoreActiveTexture(); |
280 decoder->RestoreFramebufferBindings(); | 291 decoder->RestoreFramebufferBindings(); |
281 } | 292 } |
282 | 293 |
283 } // namespace | 294 } // namespace |
(...skipping 26 matching lines...) Expand all Loading... | |
310 glGenBuffersARB(1, &buffer_id_); | 321 glGenBuffersARB(1, &buffer_id_); |
311 glBindBuffer(GL_ARRAY_BUFFER, buffer_id_); | 322 glBindBuffer(GL_ARRAY_BUFFER, buffer_id_); |
312 const GLfloat kQuadVertices[] = {-1.0f, -1.0f, | 323 const GLfloat kQuadVertices[] = {-1.0f, -1.0f, |
313 1.0f, -1.0f, | 324 1.0f, -1.0f, |
314 1.0f, 1.0f, | 325 1.0f, 1.0f, |
315 -1.0f, 1.0f}; | 326 -1.0f, 1.0f}; |
316 glBufferData( | 327 glBufferData( |
317 GL_ARRAY_BUFFER, sizeof(kQuadVertices), kQuadVertices, GL_STATIC_DRAW); | 328 GL_ARRAY_BUFFER, sizeof(kQuadVertices), kQuadVertices, GL_STATIC_DRAW); |
318 | 329 |
319 glGenFramebuffersEXT(1, &framebuffer_); | 330 glGenFramebuffersEXT(1, &framebuffer_); |
331 glGenTextures(1, &staging_testure_); | |
320 | 332 |
321 decoder->RestoreBufferBindings(); | 333 decoder->RestoreBufferBindings(); |
322 | 334 |
323 initialized_ = true; | 335 initialized_ = true; |
324 } | 336 } |
325 | 337 |
326 void CopyTextureCHROMIUMResourceManager::Destroy() { | 338 void CopyTextureCHROMIUMResourceManager::Destroy() { |
327 if (!initialized_) | 339 if (!initialized_) |
328 return; | 340 return; |
329 | 341 |
330 glDeleteFramebuffersEXT(1, &framebuffer_); | 342 glDeleteFramebuffersEXT(1, &framebuffer_); |
331 framebuffer_ = 0; | 343 framebuffer_ = 0; |
332 | 344 |
345 glDeleteTextures(1, &staging_testure_); | |
346 staging_testure_ = 0; | |
347 | |
333 std::for_each(vertex_shaders_.begin(), vertex_shaders_.end(), DeleteShader); | 348 std::for_each(vertex_shaders_.begin(), vertex_shaders_.end(), DeleteShader); |
334 std::for_each( | 349 std::for_each( |
335 fragment_shaders_.begin(), fragment_shaders_.end(), DeleteShader); | 350 fragment_shaders_.begin(), fragment_shaders_.end(), DeleteShader); |
336 | 351 |
337 for (ProgramMap::const_iterator it = programs_.begin(); it != programs_.end(); | 352 for (ProgramMap::const_iterator it = programs_.begin(); it != programs_.end(); |
338 ++it) { | 353 ++it) { |
339 const ProgramInfo& info = it->second; | 354 const ProgramInfo& info = it->second; |
340 glDeleteProgram(info.program); | 355 glDeleteProgram(info.program); |
341 } | 356 } |
342 | 357 |
343 glDeleteBuffersARB(1, &buffer_id_); | 358 glDeleteBuffersARB(1, &buffer_id_); |
344 buffer_id_ = 0; | 359 buffer_id_ = 0; |
345 } | 360 } |
346 | 361 |
347 void CopyTextureCHROMIUMResourceManager::DoCopyTexture( | 362 void CopyTextureCHROMIUMResourceManager::DoCopyTexture( |
348 const gles2::GLES2Decoder* decoder, | 363 const gles2::GLES2Decoder* decoder, |
349 GLenum source_target, | 364 GLenum source_target, |
350 GLuint source_id, | 365 GLuint source_id, |
351 GLenum source_internal_format, | 366 GLenum source_internal_format, |
367 GLenum dest_target, | |
352 GLuint dest_id, | 368 GLuint dest_id, |
353 GLenum dest_internal_format, | 369 GLenum dest_internal_format, |
370 GLenum dest_type, | |
354 GLsizei width, | 371 GLsizei width, |
355 GLsizei height, | 372 GLsizei height, |
356 bool flip_y, | 373 bool flip_y, |
357 bool premultiply_alpha, | 374 bool premultiply_alpha, |
358 bool unpremultiply_alpha) { | 375 bool unpremultiply_alpha, |
376 bool dest_cube_complete) { | |
359 bool premultiply_alpha_change = premultiply_alpha ^ unpremultiply_alpha; | 377 bool premultiply_alpha_change = premultiply_alpha ^ unpremultiply_alpha; |
360 // GL_INVALID_OPERATION is generated if the currently bound framebuffer's | 378 // GL_INVALID_OPERATION is generated if the currently bound framebuffer's |
361 // format does not contain a superset of the components required by the base | 379 // format does not contain a superset of the components required by the base |
362 // format of internalformat. | 380 // format of internalformat. |
363 // https://www.khronos.org/opengles/sdk/docs/man/xhtml/glCopyTexImage2D.xml | 381 // https://www.khronos.org/opengles/sdk/docs/man/xhtml/glCopyTexImage2D.xml |
364 bool source_format_contain_superset_of_dest_format = | 382 bool source_format_contain_superset_of_dest_format = |
365 (source_internal_format == dest_internal_format && | 383 (source_internal_format == dest_internal_format && |
366 source_internal_format != GL_BGRA_EXT) || | 384 source_internal_format != GL_BGRA_EXT) || |
367 (source_internal_format == GL_RGBA && dest_internal_format == GL_RGB); | 385 (source_internal_format == GL_RGBA && dest_internal_format == GL_RGB); |
368 // GL_TEXTURE_RECTANGLE_ARB on FBO is supported by OpenGL, not GLES2, | 386 // GL_TEXTURE_RECTANGLE_ARB on FBO is supported by OpenGL, not GLES2, |
369 // so restrict this to GL_TEXTURE_2D. | 387 // so restrict this to GL_TEXTURE_2D. |
370 if (source_target == GL_TEXTURE_2D && !flip_y && !premultiply_alpha_change && | 388 if (source_target == GL_TEXTURE_2D && !flip_y && !premultiply_alpha_change && |
371 source_format_contain_superset_of_dest_format) { | 389 source_format_contain_superset_of_dest_format) { |
372 DoCopyTexImage2D(decoder, | 390 DoCopyTexImage2D(decoder, source_target, source_id, dest_target, dest_id, |
373 source_target, | 391 dest_internal_format, width, height, framebuffer_); |
374 source_id, | |
375 dest_id, | |
376 dest_internal_format, | |
377 width, | |
378 height, | |
379 framebuffer_); | |
380 return; | 392 return; |
381 } | 393 } |
382 | 394 |
383 // Use kIdentityMatrix if no transform passed in. | 395 // Use kIdentityMatrix if no transform passed in. |
384 DoCopyTextureWithTransform(decoder, source_target, source_id, dest_id, width, | 396 DoCopyTextureWithTransform( |
385 height, flip_y, premultiply_alpha, | 397 decoder, source_target, source_id, dest_target, dest_id, |
386 unpremultiply_alpha, kIdentityMatrix); | 398 dest_internal_format, dest_type, width, height, flip_y, premultiply_alpha, |
399 unpremultiply_alpha, dest_cube_complete, kIdentityMatrix); | |
387 } | 400 } |
388 | 401 |
389 void CopyTextureCHROMIUMResourceManager::DoCopySubTexture( | 402 void CopyTextureCHROMIUMResourceManager::DoCopySubTexture( |
390 const gles2::GLES2Decoder* decoder, | 403 const gles2::GLES2Decoder* decoder, |
391 GLenum source_target, | 404 GLenum source_target, |
392 GLuint source_id, | 405 GLuint source_id, |
393 GLenum source_internal_format, | 406 GLenum source_internal_format, |
407 GLenum dest_target, | |
394 GLuint dest_id, | 408 GLuint dest_id, |
395 GLenum dest_internal_format, | 409 GLenum dest_internal_format, |
410 GLenum dest_type, | |
396 GLint xoffset, | 411 GLint xoffset, |
397 GLint yoffset, | 412 GLint yoffset, |
398 GLint x, | 413 GLint x, |
399 GLint y, | 414 GLint y, |
400 GLsizei width, | 415 GLsizei width, |
401 GLsizei height, | 416 GLsizei height, |
402 GLsizei dest_width, | 417 GLsizei dest_width, |
403 GLsizei dest_height, | 418 GLsizei dest_height, |
404 GLsizei source_width, | 419 GLsizei source_width, |
405 GLsizei source_height, | 420 GLsizei source_height, |
406 bool flip_y, | 421 bool flip_y, |
407 bool premultiply_alpha, | 422 bool premultiply_alpha, |
408 bool unpremultiply_alpha) { | 423 bool unpremultiply_alpha, |
424 bool dest_cube_complete) { | |
409 bool premultiply_alpha_change = premultiply_alpha ^ unpremultiply_alpha; | 425 bool premultiply_alpha_change = premultiply_alpha ^ unpremultiply_alpha; |
410 // GL_INVALID_OPERATION is generated if the currently bound framebuffer's | 426 // GL_INVALID_OPERATION is generated if the currently bound framebuffer's |
411 // format does not contain a superset of the components required by the base | 427 // format does not contain a superset of the components required by the base |
412 // format of internalformat. | 428 // format of internalformat. |
413 // https://www.khronos.org/opengles/sdk/docs/man/xhtml/glCopyTexImage2D.xml | 429 // https://www.khronos.org/opengles/sdk/docs/man/xhtml/glCopyTexImage2D.xml |
414 bool source_format_contain_superset_of_dest_format = | 430 bool source_format_contain_superset_of_dest_format = |
415 (source_internal_format == dest_internal_format && | 431 (source_internal_format == dest_internal_format && |
416 source_internal_format != GL_BGRA_EXT) || | 432 source_internal_format != GL_BGRA_EXT) || |
417 (source_internal_format == GL_RGBA && dest_internal_format == GL_RGB); | 433 (source_internal_format == GL_RGBA && dest_internal_format == GL_RGB); |
418 // GL_TEXTURE_RECTANGLE_ARB on FBO is supported by OpenGL, not GLES2, | 434 // GL_TEXTURE_RECTANGLE_ARB on FBO is supported by OpenGL, not GLES2, |
419 // so restrict this to GL_TEXTURE_2D. | 435 // so restrict this to GL_TEXTURE_2D. |
420 if (source_target == GL_TEXTURE_2D && !flip_y && !premultiply_alpha_change && | 436 if (source_target == GL_TEXTURE_2D && !flip_y && !premultiply_alpha_change && |
421 source_format_contain_superset_of_dest_format) { | 437 source_format_contain_superset_of_dest_format) { |
422 DoCopyTexSubImage2D(decoder, source_target, source_id, dest_id, xoffset, | 438 DoCopyTexSubImage2D(decoder, source_target, source_id, dest_target, dest_id, |
423 yoffset, x, y, width, height, framebuffer_); | 439 xoffset, yoffset, x, y, width, height, framebuffer_); |
424 return; | 440 return; |
425 } | 441 } |
426 | 442 |
427 DoCopyTextureInternal(decoder, source_target, source_id, dest_id, xoffset, | 443 if (!dest_cube_complete) { |
428 yoffset, x, y, width, height, dest_width, dest_height, | 444 glBindTexture(GL_TEXTURE_2D, staging_testure_); |
429 source_width, source_height, flip_y, premultiply_alpha, | 445 glTexImage2D(GL_TEXTURE_2D, 0, dest_internal_format, width, height, 0, |
430 unpremultiply_alpha, kIdentityMatrix); | 446 dest_internal_format, dest_type, nullptr); |
447 DoCopyTextureInternal( | |
448 decoder, source_target, source_id, GL_TEXTURE_2D, staging_testure_, 0, | |
449 0, x, y, width, height, width, height, source_width, source_height, | |
450 flip_y, premultiply_alpha, unpremultiply_alpha, kIdentityMatrix); | |
451 DoCopyTexSubImage2D(decoder, GL_TEXTURE_2D, staging_testure_, dest_target, | |
Ken Russell (switch to Gerrit)
2015/08/18 00:33:02
The staging_texture_ will stick around after this,
dshwang
2015/08/18 14:42:01
Acknowledged.
| |
452 dest_id, xoffset, yoffset, 0, 0, width, height, | |
453 framebuffer_); | |
454 return; | |
455 } | |
456 | |
457 DoCopyTextureInternal( | |
458 decoder, source_target, source_id, dest_target, dest_id, xoffset, yoffset, | |
459 x, y, width, height, dest_width, dest_height, source_width, source_height, | |
460 flip_y, premultiply_alpha, unpremultiply_alpha, kIdentityMatrix); | |
431 } | 461 } |
432 | 462 |
433 void CopyTextureCHROMIUMResourceManager::DoCopyTextureWithTransform( | 463 void CopyTextureCHROMIUMResourceManager::DoCopyTextureWithTransform( |
434 const gles2::GLES2Decoder* decoder, | 464 const gles2::GLES2Decoder* decoder, |
435 GLenum source_target, | 465 GLenum source_target, |
436 GLuint source_id, | 466 GLuint source_id, |
467 GLenum dest_target, | |
437 GLuint dest_id, | 468 GLuint dest_id, |
469 GLenum dest_internal_format, | |
470 GLenum dest_type, | |
438 GLsizei width, | 471 GLsizei width, |
439 GLsizei height, | 472 GLsizei height, |
440 bool flip_y, | 473 bool flip_y, |
441 bool premultiply_alpha, | 474 bool premultiply_alpha, |
442 bool unpremultiply_alpha, | 475 bool unpremultiply_alpha, |
476 bool dest_cube_complete, | |
443 const GLfloat transform_matrix[16]) { | 477 const GLfloat transform_matrix[16]) { |
444 GLsizei dest_width = width; | 478 GLsizei dest_width = width; |
445 GLsizei dest_height = height; | 479 GLsizei dest_height = height; |
446 DoCopyTextureInternal(decoder, source_target, source_id, dest_id, 0, 0, 0, 0, | 480 |
447 width, height, dest_width, dest_height, width, height, | 481 if (!dest_cube_complete) { |
448 flip_y, premultiply_alpha, unpremultiply_alpha, | 482 // The |dest_id| texture cannot be bound to FBO. Create a staging |
449 transform_matrix); | 483 // GL_TEXTURE_2D texture, and copy the source texture to the staging |
484 // texture, and copy the staging texture to the dest texture. | |
485 glBindTexture(GL_TEXTURE_2D, staging_testure_); | |
486 glTexImage2D(GL_TEXTURE_2D, 0, dest_internal_format, width, height, 0, | |
487 dest_internal_format, dest_type, nullptr); | |
488 DoCopyTextureInternal(decoder, source_target, source_id, GL_TEXTURE_2D, | |
489 staging_testure_, 0, 0, 0, 0, width, height, width, | |
490 height, width, height, flip_y, premultiply_alpha, | |
491 unpremultiply_alpha, transform_matrix); | |
492 DoCopyTexImage2D(decoder, GL_TEXTURE_2D, staging_testure_, dest_target, | |
Ken Russell (switch to Gerrit)
2015/08/18 00:33:02
Similar comment about the staging_texture_ staying
dshwang
2015/08/18 14:42:01
Acknowledged.
| |
493 dest_id, dest_internal_format, width, height, | |
494 framebuffer_); | |
495 return; | |
496 } | |
497 | |
498 DoCopyTextureInternal(decoder, source_target, source_id, dest_target, dest_id, | |
499 0, 0, 0, 0, width, height, dest_width, dest_height, | |
500 width, height, flip_y, premultiply_alpha, | |
501 unpremultiply_alpha, transform_matrix); | |
450 } | 502 } |
451 | 503 |
452 void CopyTextureCHROMIUMResourceManager::DoCopyTextureInternal( | 504 void CopyTextureCHROMIUMResourceManager::DoCopyTextureInternal( |
453 const gles2::GLES2Decoder* decoder, | 505 const gles2::GLES2Decoder* decoder, |
454 GLenum source_target, | 506 GLenum source_target, |
455 GLuint source_id, | 507 GLuint source_id, |
508 GLenum dest_target, | |
456 GLuint dest_id, | 509 GLuint dest_id, |
457 GLint xoffset, | 510 GLint xoffset, |
458 GLint yoffset, | 511 GLint yoffset, |
459 GLint x, | 512 GLint x, |
460 GLint y, | 513 GLint y, |
461 GLsizei width, | 514 GLsizei width, |
462 GLsizei height, | 515 GLsizei height, |
463 GLsizei dest_width, | 516 GLsizei dest_width, |
464 GLsizei dest_height, | 517 GLsizei dest_height, |
465 GLsizei source_width, | 518 GLsizei source_width, |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
535 // Pass translation to the shader program. | 588 // Pass translation to the shader program. |
536 glUniform2f(info->vertex_translate_handle, x_translate_on_vertex, | 589 glUniform2f(info->vertex_translate_handle, x_translate_on_vertex, |
537 y_translate_on_vertex); | 590 y_translate_on_vertex); |
538 } | 591 } |
539 if (source_target == GL_TEXTURE_RECTANGLE_ARB) | 592 if (source_target == GL_TEXTURE_RECTANGLE_ARB) |
540 glUniform2f(info->half_size_handle, source_width / 2.0f, | 593 glUniform2f(info->half_size_handle, source_width / 2.0f, |
541 source_height / 2.0f); | 594 source_height / 2.0f); |
542 else | 595 else |
543 glUniform2f(info->half_size_handle, 0.5f, 0.5f); | 596 glUniform2f(info->half_size_handle, 0.5f, 0.5f); |
544 | 597 |
545 if (BindFramebufferTexture2D(GL_TEXTURE_2D, dest_id, framebuffer_)) { | 598 if (BindFramebufferTexture2D(dest_target, dest_id, framebuffer_)) { |
546 #ifndef NDEBUG | 599 #ifndef NDEBUG |
547 // glValidateProgram of MACOSX validates FBO unlike other platforms, so | 600 // glValidateProgram of MACOSX validates FBO unlike other platforms, so |
548 // glValidateProgram must be called after FBO binding. crbug.com/463439 | 601 // glValidateProgram must be called after FBO binding. crbug.com/463439 |
549 glValidateProgram(info->program); | 602 glValidateProgram(info->program); |
550 GLint validation_status; | 603 GLint validation_status; |
551 glGetProgramiv(info->program, GL_VALIDATE_STATUS, &validation_status); | 604 glGetProgramiv(info->program, GL_VALIDATE_STATUS, &validation_status); |
552 if (GL_TRUE != validation_status) { | 605 if (GL_TRUE != validation_status) { |
553 DLOG(ERROR) << "CopyTextureCHROMIUM: Invalid shader."; | 606 DLOG(ERROR) << "CopyTextureCHROMIUM: Invalid shader."; |
554 return; | 607 return; |
555 } | 608 } |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
590 decoder->RestoreTextureState(dest_id); | 643 decoder->RestoreTextureState(dest_id); |
591 decoder->RestoreTextureUnitBindings(0); | 644 decoder->RestoreTextureUnitBindings(0); |
592 decoder->RestoreActiveTexture(); | 645 decoder->RestoreActiveTexture(); |
593 decoder->RestoreProgramBindings(); | 646 decoder->RestoreProgramBindings(); |
594 decoder->RestoreBufferBindings(); | 647 decoder->RestoreBufferBindings(); |
595 decoder->RestoreFramebufferBindings(); | 648 decoder->RestoreFramebufferBindings(); |
596 decoder->RestoreGlobalState(); | 649 decoder->RestoreGlobalState(); |
597 } | 650 } |
598 | 651 |
599 } // namespace gpu | 652 } // namespace gpu |
OLD | NEW |