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 "content/browser/renderer_host/compositing_iosurface_mac.h" | 5 #include "content/browser/renderer_host/compositing_iosurface_mac.h" |
6 | 6 |
7 #include <OpenGL/OpenGL.h> | 7 #include <OpenGL/OpenGL.h> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
11 #include "base/debug/trace_event.h" | 11 #include "base/debug/trace_event.h" |
12 #include "content/browser/renderer_host/render_widget_host_view_mac.h" | 12 #include "content/browser/renderer_host/render_widget_host_view_mac.h" |
13 #include "content/public/browser/browser_thread.h" | 13 #include "content/public/browser/browser_thread.h" |
14 #include "gpu/command_buffer/service/gpu_switches.h" | 14 #include "gpu/command_buffer/service/gpu_switches.h" |
| 15 #include "ui/gfx/rect.h" |
15 #include "ui/gfx/scoped_ns_graphics_context_save_gstate_mac.h" | 16 #include "ui/gfx/scoped_ns_graphics_context_save_gstate_mac.h" |
16 #include "ui/gl/gl_context.h" | 17 #include "ui/gl/gl_context.h" |
17 #include "ui/gl/gl_switches.h" | 18 #include "ui/gl/gl_switches.h" |
18 #include "ui/surface/io_surface_support_mac.h" | 19 #include "ui/surface/io_surface_support_mac.h" |
19 | 20 |
20 #ifdef NDEBUG | 21 #ifdef NDEBUG |
21 #define CHECK_GL_ERROR() | 22 #define CHECK_GL_ERROR() |
22 #else | 23 #else |
23 #define CHECK_GL_ERROR() do { \ | 24 #define CHECK_GL_ERROR() do { \ |
24 GLenum gl_error = glGetError(); \ | 25 GLenum gl_error = glGetError(); \ |
(...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
296 // by forcing the graphics pipeline to be completely drained at this | 297 // by forcing the graphics pipeline to be completely drained at this |
297 // point. | 298 // point. |
298 glFinish(); | 299 glFinish(); |
299 } | 300 } |
300 | 301 |
301 CGLFlushDrawable(cglContext_); | 302 CGLFlushDrawable(cglContext_); |
302 | 303 |
303 CGLSetCurrentContext(0); | 304 CGLSetCurrentContext(0); |
304 } | 305 } |
305 | 306 |
306 bool CompositingIOSurfaceMac::CopyTo(const gfx::Size& dst_size, void* out) { | 307 bool CompositingIOSurfaceMac::CopyTo( |
| 308 const gfx::Rect& src_pixel_subrect, |
| 309 const gfx::Size& dst_pixel_size, |
| 310 void* out) { |
307 if (!MapIOSurfaceToTexture(io_surface_handle_)) | 311 if (!MapIOSurfaceToTexture(io_surface_handle_)) |
308 return false; | 312 return false; |
309 | 313 |
310 CGLSetCurrentContext(cglContext_); | 314 CGLSetCurrentContext(cglContext_); |
311 GLuint target = GL_TEXTURE_RECTANGLE_ARB; | 315 GLuint target = GL_TEXTURE_RECTANGLE_ARB; |
312 | 316 |
313 GLuint dst_texture = 0; | 317 GLuint dst_texture = 0; |
314 glGenTextures(1, &dst_texture); CHECK_GL_ERROR(); | 318 glGenTextures(1, &dst_texture); CHECK_GL_ERROR(); |
315 glBindTexture(target, dst_texture); CHECK_GL_ERROR(); | 319 glBindTexture(target, dst_texture); CHECK_GL_ERROR(); |
316 | 320 |
317 GLuint dst_framebuffer = 0; | 321 GLuint dst_framebuffer = 0; |
318 glGenFramebuffersEXT(1, &dst_framebuffer); CHECK_GL_ERROR(); | 322 glGenFramebuffersEXT(1, &dst_framebuffer); CHECK_GL_ERROR(); |
319 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, dst_framebuffer); CHECK_GL_ERROR(); | 323 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, dst_framebuffer); CHECK_GL_ERROR(); |
320 | 324 |
321 glTexImage2D(target, | 325 glTexImage2D(target, |
322 0, | 326 0, |
323 GL_RGBA, | 327 GL_RGBA, |
324 dst_size.width(), | 328 dst_pixel_size.width(), |
325 dst_size.height(), | 329 dst_pixel_size.height(), |
326 0, | 330 0, |
327 GL_BGRA, | 331 GL_BGRA, |
328 GL_UNSIGNED_INT_8_8_8_8_REV, | 332 GL_UNSIGNED_INT_8_8_8_8_REV, |
329 NULL); CHECK_GL_ERROR(); | 333 NULL); CHECK_GL_ERROR(); |
330 glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, | 334 glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, |
331 GL_COLOR_ATTACHMENT0_EXT, | 335 GL_COLOR_ATTACHMENT0_EXT, |
332 target, | 336 target, |
333 dst_texture, | 337 dst_texture, |
334 0); CHECK_GL_ERROR(); | 338 0); CHECK_GL_ERROR(); |
335 glBindTexture(target, 0); CHECK_GL_ERROR(); | 339 glBindTexture(target, 0); CHECK_GL_ERROR(); |
336 | 340 |
337 glViewport(0, 0, dst_size.width(), dst_size.height()); | 341 glViewport(0, 0, dst_pixel_size.width(), dst_pixel_size.height()); |
338 | 342 |
339 glMatrixMode(GL_PROJECTION); | 343 glMatrixMode(GL_PROJECTION); |
340 glLoadIdentity(); | 344 glLoadIdentity(); |
341 glOrtho(0, dst_size.width(), 0, dst_size.height(), -1, 1); | 345 glOrtho(0, dst_pixel_size.width(), 0, dst_pixel_size.height(), -1, 1); |
342 glMatrixMode(GL_MODELVIEW); | 346 glMatrixMode(GL_MODELVIEW); |
343 glLoadIdentity(); | 347 glLoadIdentity(); |
344 | 348 |
345 glDisable(GL_DEPTH_TEST); | 349 glDisable(GL_DEPTH_TEST); |
346 glDisable(GL_BLEND); | 350 glDisable(GL_BLEND); |
347 | 351 |
348 glUseProgram(shader_program_blit_rgb_); | 352 glUseProgram(shader_program_blit_rgb_); |
349 | 353 |
350 int texture_unit = 0; | 354 int texture_unit = 0; |
351 glUniform1i(blit_rgb_sampler_location_, texture_unit); | 355 glUniform1i(blit_rgb_sampler_location_, texture_unit); |
352 glActiveTexture(GL_TEXTURE0 + texture_unit); | 356 glActiveTexture(GL_TEXTURE0 + texture_unit); |
353 glBindTexture(GL_TEXTURE_RECTANGLE_ARB, texture_); | 357 glBindTexture(GL_TEXTURE_RECTANGLE_ARB, texture_); |
354 | 358 |
355 SurfaceQuad quad; | 359 SurfaceQuad quad; |
356 quad.set_size(dst_size, pixel_io_surface_size_); | 360 quad.set_rect(0.0f, 0.0f, dst_pixel_size.width(), dst_pixel_size.height()); |
| 361 quad.set_texcoord_rect(src_pixel_subrect.x(), src_pixel_subrect.y(), |
| 362 src_pixel_subrect.right(), src_pixel_subrect.bottom()); |
357 DrawQuad(quad); | 363 DrawQuad(quad); |
358 | 364 |
359 glBindTexture(GL_TEXTURE_RECTANGLE_ARB, 0); CHECK_GL_ERROR(); | 365 glBindTexture(GL_TEXTURE_RECTANGLE_ARB, 0); CHECK_GL_ERROR(); |
360 glUseProgram(0); | 366 glUseProgram(0); |
361 | 367 |
362 CGLFlushDrawable(cglContext_); | 368 CGLFlushDrawable(cglContext_); |
363 | 369 |
364 glReadPixels(0, 0, dst_size.width(), dst_size.height(), | 370 glReadPixels(0, 0, dst_pixel_size.width(), dst_pixel_size.height(), |
365 GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, out); | 371 GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, out); |
366 | 372 |
367 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0); CHECK_GL_ERROR(); | 373 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0); CHECK_GL_ERROR(); |
368 | 374 |
369 glDeleteFramebuffersEXT(1, &dst_framebuffer); | 375 glDeleteFramebuffersEXT(1, &dst_framebuffer); |
370 glDeleteTextures(1, &dst_texture); | 376 glDeleteTextures(1, &dst_texture); |
371 | 377 |
372 CGLSetCurrentContext(0); | 378 CGLSetCurrentContext(0); |
373 return true; | 379 return true; |
374 } | 380 } |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
461 void CompositingIOSurfaceMac::GlobalFrameDidChange() { | 467 void CompositingIOSurfaceMac::GlobalFrameDidChange() { |
462 [glContext_ update]; | 468 [glContext_ update]; |
463 } | 469 } |
464 | 470 |
465 void CompositingIOSurfaceMac::ClearDrawable() { | 471 void CompositingIOSurfaceMac::ClearDrawable() { |
466 [glContext_ clearDrawable]; | 472 [glContext_ clearDrawable]; |
467 UnrefIOSurface(); | 473 UnrefIOSurface(); |
468 } | 474 } |
469 | 475 |
470 } // namespace content | 476 } // namespace content |
OLD | NEW |