Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/common/gpu/media/rendering_helper.h" | 5 #include "content/common/gpu/media/rendering_helper.h" |
| 6 | 6 |
| 7 #include <algorithm> | |
| 8 #include <numeric> | |
| 9 #include <vector> | |
| 10 | |
| 7 #include "base/bind.h" | 11 #include "base/bind.h" |
| 8 #include "base/mac/scoped_nsautorelease_pool.h" | 12 #include "base/mac/scoped_nsautorelease_pool.h" |
| 9 #include "base/message_loop/message_loop.h" | 13 #include "base/message_loop/message_loop.h" |
| 10 #include "base/strings/stringize_macros.h" | 14 #include "base/strings/stringize_macros.h" |
| 11 #include "base/synchronization/waitable_event.h" | 15 #include "base/synchronization/waitable_event.h" |
| 12 #include "ui/gl/gl_context.h" | 16 #include "ui/gl/gl_context.h" |
| 13 #include "ui/gl/gl_context_stub_with_extensions.h" | 17 #include "ui/gl/gl_context_stub_with_extensions.h" |
| 14 #include "ui/gl/gl_implementation.h" | 18 #include "ui/gl/gl_implementation.h" |
| 15 #include "ui/gl/gl_surface.h" | 19 #include "ui/gl/gl_surface.h" |
| 16 | 20 |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 75 #if defined(OS_WIN) | 79 #if defined(OS_WIN) |
| 76 window_ = NULL; | 80 window_ = NULL; |
| 77 #else | 81 #else |
| 78 x_window_ = (Window)0; | 82 x_window_ = (Window)0; |
| 79 #endif | 83 #endif |
| 80 | 84 |
| 81 Clear(); | 85 Clear(); |
| 82 } | 86 } |
| 83 | 87 |
| 84 RenderingHelper::~RenderingHelper() { | 88 RenderingHelper::~RenderingHelper() { |
| 85 CHECK_EQ(frame_dimensions_.size(), 0U) | 89 CHECK_EQ(clients_.size(), 0U) |
| 86 << "Must call UnInitialize before dtor."; | 90 << "Must call UnInitialize before dtor."; |
| 87 Clear(); | 91 Clear(); |
| 88 } | 92 } |
| 89 | 93 |
| 90 void RenderingHelper::Initialize(const RenderingHelperParams& params, | 94 void RenderingHelper::Initialize(const RenderingHelperParams& params, |
| 91 base::WaitableEvent* done) { | 95 base::WaitableEvent* done) { |
| 92 // Use frame_dimensions_.size() != 0 as a proxy for the class having already | 96 // Use cients_.size() != 0 as a proxy for the class having already been |
| 93 // been Initialize()'d, and UnInitialize() before continuing. | 97 // Initialize()'d, and UnInitialize() before continuing. |
| 94 if (frame_dimensions_.size()) { | 98 if (clients_.size()) { |
| 95 base::WaitableEvent done(false, false); | 99 base::WaitableEvent done(false, false); |
| 96 UnInitialize(&done); | 100 UnInitialize(&done); |
| 97 done.Wait(); | 101 done.Wait(); |
| 98 } | 102 } |
| 99 | 103 |
| 100 frame_duration_ = params.rendering_fps > 0 | 104 frame_duration_ = params.rendering_fps > 0 |
| 101 ? base::TimeDelta::FromSeconds(1) / params.rendering_fps | 105 ? base::TimeDelta::FromSeconds(1) / params.rendering_fps |
| 102 : base::TimeDelta(); | 106 : base::TimeDelta(); |
| 103 | 107 |
| 104 gfx::InitializeStaticGLBindings(kGLImplementation); | 108 gfx::InitializeStaticGLBindings(kGLImplementation); |
| 105 scoped_refptr<gfx::GLContextStubWithExtensions> stub_context( | 109 scoped_refptr<gfx::GLContextStubWithExtensions> stub_context( |
| 106 new gfx::GLContextStubWithExtensions()); | 110 new gfx::GLContextStubWithExtensions()); |
| 107 | 111 |
| 108 CHECK_GT(params.window_dimensions.size(), 0U); | |
| 109 CHECK_EQ(params.frame_dimensions.size(), params.window_dimensions.size()); | |
| 110 frame_dimensions_ = params.frame_dimensions; | |
| 111 render_as_thumbnails_ = params.render_as_thumbnails; | 112 render_as_thumbnails_ = params.render_as_thumbnails; |
| 112 message_loop_ = base::MessageLoop::current(); | 113 message_loop_ = base::MessageLoop::current(); |
| 113 CHECK_GT(params.num_windows, 0); | |
| 114 | |
| 115 gfx::Size window_size; | |
| 116 | 114 |
| 117 #if GL_VARIANT_GLX | 115 #if GL_VARIANT_GLX |
| 118 x_display_ = gfx::GetXDisplay(); | 116 x_display_ = gfx::GetXDisplay(); |
| 119 CHECK(x_display_); | 117 CHECK(x_display_); |
| 120 CHECK(glXQueryVersion(x_display_, NULL, NULL)); | 118 CHECK(glXQueryVersion(x_display_, NULL, NULL)); |
| 121 const int fbconfig_attr[] = { | 119 const int fbconfig_attr[] = { |
| 122 GLX_DRAWABLE_TYPE, GLX_WINDOW_BIT, | 120 GLX_DRAWABLE_TYPE, GLX_WINDOW_BIT, |
| 123 GLX_RENDER_TYPE, GLX_RGBA_BIT, | 121 GLX_RENDER_TYPE, GLX_RGBA_BIT, |
| 124 GLX_BIND_TO_TEXTURE_TARGETS_EXT, GLX_TEXTURE_2D_BIT_EXT, | 122 GLX_BIND_TO_TEXTURE_TARGETS_EXT, GLX_TEXTURE_2D_BIT_EXT, |
| 125 GLX_BIND_TO_TEXTURE_RGB_EXT, GL_TRUE, | 123 GLX_BIND_TO_TEXTURE_RGB_EXT, GL_TRUE, |
| 126 GLX_DOUBLEBUFFER, True, | 124 GLX_DOUBLEBUFFER, True, |
| 127 GL_NONE, | 125 GL_NONE, |
| 128 }; | 126 }; |
| 129 int num_fbconfigs; | 127 int num_fbconfigs; |
| 130 scoped_ptr<GLXFBConfig, XFreeDeleter> glx_fb_configs( | 128 scoped_ptr<GLXFBConfig, XFreeDeleter> glx_fb_configs( |
| 131 glXChooseFBConfig(x_display_, DefaultScreen(x_display_), fbconfig_attr, | 129 glXChooseFBConfig(x_display_, DefaultScreen(x_display_), fbconfig_attr, |
| 132 &num_fbconfigs)); | 130 &num_fbconfigs)); |
| 133 CHECK(glx_fb_configs.get()); | 131 CHECK(glx_fb_configs.get()); |
| 134 CHECK_GT(num_fbconfigs, 0); | 132 CHECK_GT(num_fbconfigs, 0); |
| 135 x_visual_ = glXGetVisualFromFBConfig(x_display_, glx_fb_configs.get()[0]); | 133 x_visual_ = glXGetVisualFromFBConfig(x_display_, glx_fb_configs.get()[0]); |
| 136 CHECK(x_visual_); | 134 CHECK(x_visual_); |
| 137 gl_context_ = glXCreateContext(x_display_, x_visual_, 0, true); | 135 gl_context_ = glXCreateContext(x_display_, x_visual_, 0, true); |
| 138 CHECK(gl_context_); | 136 CHECK(gl_context_); |
| 139 stub_context->AddExtensionsString( | 137 stub_context->AddExtensionsString( |
| 140 reinterpret_cast<const char*>(glGetString(GL_EXTENSIONS))); | 138 reinterpret_cast<const char*>(glGetString(GL_EXTENSIONS))); |
| 141 stub_context->SetGLVersionString( | 139 stub_context->SetGLVersionString( |
| 142 reinterpret_cast<const char*>(glGetString(GL_VERSION))); | 140 reinterpret_cast<const char*>(glGetString(GL_VERSION))); |
| 143 | 141 |
| 144 Screen* screen = DefaultScreenOfDisplay(x_display_); | 142 Screen* screen = DefaultScreenOfDisplay(x_display_); |
| 145 window_size = gfx::Size(XWidthOfScreen(screen), XHeightOfScreen(screen)); | 143 screen_size_ = gfx::Size(XWidthOfScreen(screen), XHeightOfScreen(screen)); |
| 146 #else // EGL | 144 #else // EGL |
| 147 EGLNativeDisplayType native_display; | 145 EGLNativeDisplayType native_display; |
| 148 | 146 |
| 149 #if defined(OS_WIN) | 147 #if defined(OS_WIN) |
| 150 native_display = EGL_DEFAULT_DISPLAY; | 148 native_display = EGL_DEFAULT_DISPLAY; |
| 151 window_size = | 149 screen_size_ = |
| 152 gfx::Size(GetSystemMetrics(SM_CXSREEN), GetSystemMetrics(SM_CY_SCREEN)) | 150 gfx::Size(GetSystemMetrics(SM_CXSREEN), GetSystemMetrics(SM_CY_SCREEN)) |
| 153 #else | 151 #else |
| 154 x_display_ = gfx::GetXDisplay(); | 152 x_display_ = gfx::GetXDisplay(); |
| 155 CHECK(x_display_); | 153 CHECK(x_display_); |
| 156 native_display = x_display_; | 154 native_display = x_display_; |
| 157 | 155 |
| 158 Screen* screen = DefaultScreenOfDisplay(x_display_); | 156 Screen* screen = DefaultScreenOfDisplay(x_display_); |
| 159 window_size = gfx::Size(XWidthOfScreen(screen), XHeightOfScreen(screen)); | 157 screen_size_ = gfx::Size(XWidthOfScreen(screen), XHeightOfScreen(screen)); |
| 160 #endif | 158 #endif |
| 161 gl_display_ = eglGetDisplay(native_display); | 159 gl_display_ = eglGetDisplay(native_display); |
| 162 CHECK(gl_display_); | 160 CHECK(gl_display_); |
| 163 CHECK(eglInitialize(gl_display_, NULL, NULL)) << glGetError(); | 161 CHECK(eglInitialize(gl_display_, NULL, NULL)) << glGetError(); |
| 164 | 162 |
| 165 static EGLint rgba8888[] = { | 163 static EGLint rgba8888[] = { |
| 166 EGL_RED_SIZE, 8, | 164 EGL_RED_SIZE, 8, |
| 167 EGL_GREEN_SIZE, 8, | 165 EGL_GREEN_SIZE, 8, |
| 168 EGL_BLUE_SIZE, 8, | 166 EGL_BLUE_SIZE, 8, |
| 169 EGL_ALPHA_SIZE, 8, | 167 EGL_ALPHA_SIZE, 8, |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 180 gl_display_, egl_config, EGL_NO_CONTEXT, context_attribs); | 178 gl_display_, egl_config, EGL_NO_CONTEXT, context_attribs); |
| 181 CHECK_NE(gl_context_, EGL_NO_CONTEXT) << eglGetError(); | 179 CHECK_NE(gl_context_, EGL_NO_CONTEXT) << eglGetError(); |
| 182 stub_context->AddExtensionsString( | 180 stub_context->AddExtensionsString( |
| 183 reinterpret_cast<const char*>(glGetString(GL_EXTENSIONS))); | 181 reinterpret_cast<const char*>(glGetString(GL_EXTENSIONS))); |
| 184 stub_context->AddExtensionsString( | 182 stub_context->AddExtensionsString( |
| 185 eglQueryString(gl_display_, EGL_EXTENSIONS)); | 183 eglQueryString(gl_display_, EGL_EXTENSIONS)); |
| 186 stub_context->SetGLVersionString( | 184 stub_context->SetGLVersionString( |
| 187 reinterpret_cast<const char*>(glGetString(GL_VERSION))); | 185 reinterpret_cast<const char*>(glGetString(GL_VERSION))); |
| 188 #endif | 186 #endif |
| 189 clients_ = params.clients; | 187 clients_ = params.clients; |
| 190 // Per-window/surface X11 & EGL initialization. | 188 CHECK_GT(clients_.size(), 0); |
| 191 for (int i = 0; i < params.num_windows; ++i) { | 189 LayoutRenderingAreas(); |
| 192 // Arrange X windows whimsically, with some padding. | |
| 193 int j = i % params.window_dimensions.size(); | |
| 194 int width = params.window_dimensions[j].width(); | |
| 195 int height = params.window_dimensions[j].height(); | |
| 196 CHECK_GT(width, 0); | |
| 197 CHECK_GT(height, 0); | |
| 198 int top_left_x = (width + 20) * (i % 4); | |
| 199 int top_left_y = (height + 12) * (i % 3); | |
| 200 render_areas_.push_back(gfx::Rect(top_left_x, top_left_y, width, height)); | |
| 201 } | |
| 202 | 190 |
| 203 #if defined(OS_WIN) | 191 #if defined(OS_WIN) |
| 204 window_ = CreateWindowEx(0, | 192 window_ = CreateWindowEx(0, |
| 205 L"Static", | 193 L"Static", |
| 206 L"VideoDecodeAcceleratorTest", | 194 L"VideoDecodeAcceleratorTest", |
| 207 WS_OVERLAPPEDWINDOW | WS_VISIBLE, | 195 WS_OVERLAPPEDWINDOW | WS_VISIBLE, |
| 208 0, | 196 0, |
| 209 0, | 197 0, |
| 210 window_size.width(), | 198 screen_size_.width(), |
| 211 widow_size.height(), | 199 screen_size_.height(), |
| 212 NULL, | 200 NULL, |
| 213 NULL, | 201 NULL, |
| 214 NULL, | 202 NULL, |
| 215 NULL); | 203 NULL); |
| 216 CHECK(window_ != NULL); | 204 CHECK(window_ != NULL); |
| 217 #else | 205 #else |
| 218 int depth = DefaultDepth(x_display_, DefaultScreen(x_display_)); | 206 int depth = DefaultDepth(x_display_, DefaultScreen(x_display_)); |
| 219 | 207 |
| 220 #if defined(GL_VARIANT_GLX) | 208 #if defined(GL_VARIANT_GLX) |
| 221 CHECK_EQ(depth, x_visual_->depth); | 209 CHECK_EQ(depth, x_visual_->depth); |
| 222 #endif | 210 #endif |
| 223 | 211 |
| 224 XSetWindowAttributes window_attributes; | 212 XSetWindowAttributes window_attributes; |
| 225 window_attributes.background_pixel = | 213 window_attributes.background_pixel = |
| 226 BlackPixel(x_display_, DefaultScreen(x_display_)); | 214 BlackPixel(x_display_, DefaultScreen(x_display_)); |
| 227 window_attributes.override_redirect = true; | 215 window_attributes.override_redirect = true; |
| 228 | 216 |
| 229 x_window_ = XCreateWindow(x_display_, | 217 x_window_ = XCreateWindow(x_display_, |
| 230 DefaultRootWindow(x_display_), | 218 DefaultRootWindow(x_display_), |
| 231 0, | 219 0, |
| 232 0, | 220 0, |
| 233 window_size.width(), | 221 screen_size_.width(), |
| 234 window_size.height(), | 222 screen_size_.height(), |
| 235 0 /* border width */, | 223 0 /* border width */, |
| 236 depth, | 224 depth, |
| 237 CopyFromParent /* class */, | 225 CopyFromParent /* class */, |
| 238 CopyFromParent /* visual */, | 226 CopyFromParent /* visual */, |
| 239 (CWBackPixel | CWOverrideRedirect), | 227 (CWBackPixel | CWOverrideRedirect), |
| 240 &window_attributes); | 228 &window_attributes); |
| 241 XStoreName(x_display_, x_window_, "VideoDecodeAcceleratorTest"); | 229 XStoreName(x_display_, x_window_, "VideoDecodeAcceleratorTest"); |
| 242 XSelectInput(x_display_, x_window_, ExposureMask); | 230 XSelectInput(x_display_, x_window_, ExposureMask); |
| 243 XMapWindow(x_display_, x_window_); | 231 XMapWindow(x_display_, x_window_); |
| 244 #endif | 232 #endif |
| 245 | 233 |
| 246 #if GL_VARIANT_EGL | 234 #if GL_VARIANT_EGL |
| 247 gl_surface_ = | 235 gl_surface_ = |
| 248 eglCreateWindowSurface(gl_display_, egl_config, x_window_, NULL); | 236 eglCreateWindowSurface(gl_display_, egl_config, x_window_, NULL); |
| 249 CHECK_NE(gl_surface_, EGL_NO_SURFACE); | 237 CHECK_NE(gl_surface_, EGL_NO_SURFACE); |
| 250 #endif | 238 #endif |
| 251 | 239 |
| 252 #if GL_VARIANT_GLX | 240 #if GL_VARIANT_GLX |
| 253 CHECK(glXMakeContextCurrent(x_display_, x_window_, x_window_, gl_context_)); | 241 CHECK(glXMakeContextCurrent(x_display_, x_window_, x_window_, gl_context_)); |
| 254 #else // EGL | 242 #else // EGL |
| 255 CHECK(eglMakeCurrent(gl_display_, gl_surface_, gl_surface_, gl_context_)) | 243 CHECK(eglMakeCurrent(gl_display_, gl_surface_, gl_surface_, gl_context_)) |
| 256 << eglGetError(); | 244 << eglGetError(); |
| 257 #endif | 245 #endif |
| 258 | 246 |
| 259 // Must be done after a context is made current. | 247 // Must be done after a context is made current. |
| 260 gfx::InitializeDynamicGLBindings(kGLImplementation, stub_context.get()); | 248 gfx::InitializeDynamicGLBindings(kGLImplementation, stub_context.get()); |
| 261 | 249 |
| 262 if (render_as_thumbnails_) { | 250 if (render_as_thumbnails_) { |
| 263 CHECK_EQ(frame_dimensions_.size(), 1U); | 251 CHECK_EQ(clients_.size(), 1U); |
| 264 | 252 |
| 265 GLint max_texture_size; | 253 GLint max_texture_size; |
| 266 glGetIntegerv(GL_MAX_TEXTURE_SIZE, &max_texture_size); | 254 glGetIntegerv(GL_MAX_TEXTURE_SIZE, &max_texture_size); |
| 267 CHECK_GE(max_texture_size, params.thumbnails_page_size.width()); | 255 CHECK_GE(max_texture_size, params.thumbnails_page_size.width()); |
| 268 CHECK_GE(max_texture_size, params.thumbnails_page_size.height()); | 256 CHECK_GE(max_texture_size, params.thumbnails_page_size.height()); |
| 269 | 257 |
| 270 thumbnails_fbo_size_ = params.thumbnails_page_size; | 258 thumbnails_fbo_size_ = params.thumbnails_page_size; |
| 271 thumbnail_size_ = params.thumbnail_size; | 259 thumbnail_size_ = params.thumbnail_size; |
| 272 | 260 |
| 273 glGenFramebuffersEXT(1, &thumbnails_fbo_id_); | 261 glGenFramebuffersEXT(1, &thumbnails_fbo_id_); |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 398 #else // EGL | 386 #else // EGL |
| 399 CHECK(eglDestroyContext(gl_display_, gl_context_)); | 387 CHECK(eglDestroyContext(gl_display_, gl_context_)); |
| 400 CHECK(eglDestroySurface(gl_display_, gl_surface_)); | 388 CHECK(eglDestroySurface(gl_display_, gl_surface_)); |
| 401 CHECK(eglTerminate(gl_display_)); | 389 CHECK(eglTerminate(gl_display_)); |
| 402 #endif | 390 #endif |
| 403 gfx::ClearGLBindings(); | 391 gfx::ClearGLBindings(); |
| 404 Clear(); | 392 Clear(); |
| 405 done->Signal(); | 393 done->Signal(); |
| 406 } | 394 } |
| 407 | 395 |
| 408 void RenderingHelper::CreateTexture(int window_id, | 396 void RenderingHelper::CreateTexture(uint32 texture_target, |
| 409 uint32 texture_target, | |
| 410 uint32* texture_id, | 397 uint32* texture_id, |
| 398 const gfx::Size& size, | |
| 411 base::WaitableEvent* done) { | 399 base::WaitableEvent* done) { |
| 412 if (base::MessageLoop::current() != message_loop_) { | 400 if (base::MessageLoop::current() != message_loop_) { |
| 413 message_loop_->PostTask( | 401 message_loop_->PostTask( |
| 414 FROM_HERE, | 402 FROM_HERE, |
| 415 base::Bind(&RenderingHelper::CreateTexture, base::Unretained(this), | 403 base::Bind(&RenderingHelper::CreateTexture, base::Unretained(this), |
| 416 window_id, texture_target, texture_id, done)); | 404 texture_target, texture_id, size, done)); |
| 417 return; | 405 return; |
| 418 } | 406 } |
| 419 glGenTextures(1, texture_id); | 407 glGenTextures(1, texture_id); |
| 420 glBindTexture(texture_target, *texture_id); | 408 glBindTexture(texture_target, *texture_id); |
| 421 int dimensions_id = window_id % frame_dimensions_.size(); | |
| 422 if (texture_target == GL_TEXTURE_2D) { | 409 if (texture_target == GL_TEXTURE_2D) { |
| 423 glTexImage2D(GL_TEXTURE_2D, | 410 glTexImage2D(GL_TEXTURE_2D, |
| 424 0, | 411 0, |
| 425 GL_RGBA, | 412 GL_RGBA, |
| 426 frame_dimensions_[dimensions_id].width(), | 413 size.width(), |
| 427 frame_dimensions_[dimensions_id].height(), | 414 size.height(), |
| 428 0, | 415 0, |
| 429 GL_RGBA, | 416 GL_RGBA, |
| 430 GL_UNSIGNED_BYTE, | 417 GL_UNSIGNED_BYTE, |
| 431 NULL); | 418 NULL); |
| 432 } | 419 } |
| 433 glTexParameteri(texture_target, GL_TEXTURE_MIN_FILTER, GL_LINEAR); | 420 glTexParameteri(texture_target, GL_TEXTURE_MIN_FILTER, GL_LINEAR); |
| 434 glTexParameteri(texture_target, GL_TEXTURE_MAG_FILTER, GL_LINEAR); | 421 glTexParameteri(texture_target, GL_TEXTURE_MAG_FILTER, GL_LINEAR); |
| 435 // OpenGLES2.0.25 section 3.8.2 requires CLAMP_TO_EDGE for NPOT textures. | 422 // OpenGLES2.0.25 section 3.8.2 requires CLAMP_TO_EDGE for NPOT textures. |
| 436 glTexParameteri(texture_target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); | 423 glTexParameteri(texture_target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); |
| 437 glTexParameteri(texture_target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); | 424 glTexParameteri(texture_target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); |
| 438 CHECK_EQ(static_cast<int>(glGetError()), GL_NO_ERROR); | 425 CHECK_EQ(static_cast<int>(glGetError()), GL_NO_ERROR); |
| 439 CHECK(texture_id_to_surface_index_.insert( | |
| 440 std::make_pair(*texture_id, window_id)).second); | |
| 441 done->Signal(); | 426 done->Signal(); |
| 442 } | 427 } |
| 443 | 428 |
| 444 // Helper function to set GL viewport. | 429 // Helper function to set GL viewport. |
| 445 static inline void GLSetViewPort(const gfx::Rect& area) { | 430 static inline void GLSetViewPort(const gfx::Rect& area) { |
| 446 glViewport(area.x(), area.y(), area.width(), area.height()); | 431 glViewport(area.x(), area.y(), area.width(), area.height()); |
| 447 glScissor(area.x(), area.y(), area.width(), area.height()); | 432 glScissor(area.x(), area.y(), area.width(), area.height()); |
| 448 } | 433 } |
| 449 | 434 |
| 450 void RenderingHelper::RenderThumbnail(uint32 texture_target, | 435 void RenderingHelper::RenderThumbnail(uint32 texture_target, |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 495 | 480 |
| 496 void* RenderingHelper::GetGLDisplay() { | 481 void* RenderingHelper::GetGLDisplay() { |
| 497 #if GL_VARIANT_GLX | 482 #if GL_VARIANT_GLX |
| 498 return x_display_; | 483 return x_display_; |
| 499 #else // EGL | 484 #else // EGL |
| 500 return gl_display_; | 485 return gl_display_; |
| 501 #endif | 486 #endif |
| 502 } | 487 } |
| 503 | 488 |
| 504 void RenderingHelper::Clear() { | 489 void RenderingHelper::Clear() { |
| 505 frame_dimensions_.clear(); | 490 clients_.clear(); |
| 506 texture_id_to_surface_index_.clear(); | |
| 507 message_loop_ = NULL; | 491 message_loop_ = NULL; |
| 508 gl_context_ = NULL; | 492 gl_context_ = NULL; |
| 509 #if GL_VARIANT_EGL | 493 #if GL_VARIANT_EGL |
| 510 gl_display_ = EGL_NO_DISPLAY; | 494 gl_display_ = EGL_NO_DISPLAY; |
| 511 gl_surface_ = EGL_NO_SURFACE; | 495 gl_surface_ = EGL_NO_SURFACE; |
| 512 #endif | 496 #endif |
| 513 render_as_thumbnails_ = false; | 497 render_as_thumbnails_ = false; |
| 514 frame_count_ = 0; | 498 frame_count_ = 0; |
| 515 thumbnails_fbo_id_ = 0; | 499 thumbnails_fbo_id_ = 0; |
| 516 thumbnails_texture_id_ = 0; | 500 thumbnails_texture_id_ = 0; |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 585 } | 569 } |
| 586 } | 570 } |
| 587 | 571 |
| 588 #if GL_VARIANT_GLX | 572 #if GL_VARIANT_GLX |
| 589 glXSwapBuffers(x_display_, x_window_); | 573 glXSwapBuffers(x_display_, x_window_); |
| 590 #else // EGL | 574 #else // EGL |
| 591 eglSwapBuffers(gl_display_, gl_surface_); | 575 eglSwapBuffers(gl_display_, gl_surface_); |
| 592 CHECK_EQ(static_cast<int>(eglGetError()), EGL_SUCCESS); | 576 CHECK_EQ(static_cast<int>(eglGetError()), EGL_SUCCESS); |
| 593 #endif | 577 #endif |
| 594 } | 578 } |
| 579 | |
| 580 // Helper function to scale the lengths to match the total_length and | |
| 581 // calculate the offsets. | |
|
Ami GONE FROM CHROMIUM
2014/05/27 16:05:25
This comment isn't adding value because the non-co
Owen Lin
2014/05/28 06:55:18
The comment is modified. Thanks.
| |
| 582 static void ScaleAndCalculateOffsets(std::vector<int>& lengths, | |
|
Ami GONE FROM CHROMIUM
2014/05/27 16:05:25
const ref or non-const ptr, never non-const ref.
h
Owen Lin
2014/05/28 06:55:18
Done.
| |
| 583 std::vector<int>& offsets, | |
| 584 int total_length) { | |
| 585 int sum = std::accumulate(lengths.begin(), lengths.end(), 0); | |
| 586 for (size_t i = 0; i < lengths.size(); ++i) { | |
| 587 lengths[i] = lengths[i] * total_length / sum; | |
| 588 if (i > 0) | |
| 589 offsets[i] = offsets[i - 1] + lengths[i - 1]; | |
|
Ami GONE FROM CHROMIUM
2014/05/27 16:05:25
else
offsets[0] = 0;
Owen Lin
2014/05/28 06:55:18
Done.
| |
| 590 } | |
| 591 } | |
| 592 | |
| 593 void RenderingHelper::LayoutRenderingAreas() { | |
| 594 size_t cols, rows; | |
| 595 | |
| 596 // Find the number of colums and rows. The smallest n * n or n * (n + 1). | |
| 597 for (rows = 1;; ++rows) { | |
| 598 cols = rows; | |
| 599 if (cols * rows >= clients_.size()) | |
| 600 break; | |
| 601 cols = rows + 1; | |
| 602 if (cols * rows >= clients_.size()) | |
| 603 break; | |
| 604 } | |
|
Ami GONE FROM CHROMIUM
2014/05/27 16:05:25
are l.594-604 equiv to
size_t rows = sqrt(clients_
Owen Lin
2014/05/28 06:55:18
Done. Thanks.
| |
| 605 | |
| 606 // Find the widths and heights of the grid. | |
| 607 std::vector<int> widths(cols); | |
| 608 std::vector<int> heights(rows); | |
| 609 std::vector<int> offset_x(cols); | |
| 610 std::vector<int> offset_y(rows); | |
| 611 | |
| 612 for (size_t i = 0; i < clients_.size(); ++i) { | |
| 613 const gfx::Size &window_size = clients_[i]->GetWindowSize(); | |
| 614 widths[i % cols] = std::max(widths[i % cols], window_size.width()); | |
| 615 heights[i / cols] = std::max(heights[i / cols], window_size.height()); | |
| 616 } | |
| 617 | |
| 618 ScaleAndCalculateOffsets(widths, offset_x, screen_size_.width()); | |
| 619 ScaleAndCalculateOffsets(heights, offset_y, screen_size_.height()); | |
| 620 | |
| 621 // Put each render_area_ in the center of each cell. | |
| 622 render_areas_.clear(); | |
| 623 for (size_t i = 0; i < clients_.size(); ++i) { | |
| 624 const gfx::Size &window_size = clients_[i]->GetWindowSize(); | |
|
Ami GONE FROM CHROMIUM
2014/05/27 16:05:25
nit: & sticks left not right
Owen Lin
2014/05/28 06:55:18
Done.
| |
| 625 float scale = std::min( | |
| 626 static_cast<float>(widths[i % cols]) / window_size.width(), | |
| 627 static_cast<float>(heights[i / cols]) / window_size.height()); | |
| 628 | |
| 629 // Don't scale up the texture. | |
| 630 scale = std::min(1.0f, scale); | |
| 631 | |
| 632 size_t w = scale * window_size.width(); | |
| 633 size_t h = scale * window_size.height(); | |
| 634 size_t x = offset_x[i % cols] + (widths[i % cols] - w) / 2; | |
| 635 size_t y = offset_y[i / cols] + (heights[i / cols] - h) / 2; | |
| 636 render_areas_.push_back(gfx::Rect(x, y, w, h)); | |
| 637 } | |
| 638 } | |
| 595 } // namespace content | 639 } // namespace content |
| OLD | NEW |