OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "media/tools/player_x11/gles_video_renderer.h" | 5 #include "media/tools/player_x11/gles_video_renderer.h" |
6 | 6 |
7 #include <dlfcn.h> | 7 #include <dlfcn.h> |
8 #include <EGL/eglext.h> | 8 #include <EGL/eglext.h> |
9 #include <X11/Xutil.h> | 9 #include <X11/Xutil.h> |
10 #include <X11/extensions/Xrender.h> | 10 #include <X11/extensions/Xrender.h> |
11 #include <X11/extensions/Xcomposite.h> | 11 #include <X11/extensions/Xcomposite.h> |
12 | 12 |
13 #include "media/base/buffers.h" | 13 #include "media/base/buffers.h" |
14 #include "media/base/pipeline.h" | 14 #include "media/base/pipeline.h" |
15 #include "media/base/filter_host.h" | 15 #include "media/base/filter_host.h" |
16 #include "media/base/video_frame.h" | 16 #include "media/base/video_frame.h" |
17 #include "media/base/yuv_convert.h" | 17 #include "media/base/yuv_convert.h" |
18 | 18 |
19 GlesVideoRenderer* GlesVideoRenderer::instance_ = NULL; | 19 GlesVideoRenderer* GlesVideoRenderer::instance_ = NULL; |
20 | 20 |
21 GlesVideoRenderer::GlesVideoRenderer(Display* display, Window window) | 21 GlesVideoRenderer::GlesVideoRenderer(Display* display, Window window) |
22 : egl_create_image_khr_(NULL), | 22 : egl_create_image_khr_(NULL), |
23 egl_destroy_image_khr_(NULL), | 23 egl_destroy_image_khr_(NULL), |
24 display_(display), | 24 display_(display), |
25 window_(window), | 25 window_(window), |
26 new_frame_(false), | |
27 egl_display_(NULL), | 26 egl_display_(NULL), |
28 egl_surface_(NULL), | 27 egl_surface_(NULL), |
29 egl_context_(NULL) { | 28 egl_context_(NULL), |
| 29 glx_thread_message_loop_(NULL) { |
30 } | 30 } |
31 | 31 |
32 GlesVideoRenderer::~GlesVideoRenderer() { | 32 GlesVideoRenderer::~GlesVideoRenderer() { |
33 } | 33 } |
34 | 34 |
35 // static | 35 // static |
36 bool GlesVideoRenderer::IsMediaFormatSupported( | 36 bool GlesVideoRenderer::IsMediaFormatSupported( |
37 const media::MediaFormat& media_format) { | 37 const media::MediaFormat& media_format) { |
38 int width = 0; | 38 int width = 0; |
39 int height = 0; | 39 int height = 0; |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
142 | 142 |
143 LOG(INFO) << "Initializing GLES Renderer..."; | 143 LOG(INFO) << "Initializing GLES Renderer..."; |
144 | 144 |
145 // Save this instance. | 145 // Save this instance. |
146 DCHECK(!instance_); | 146 DCHECK(!instance_); |
147 instance_ = this; | 147 instance_ = this; |
148 return true; | 148 return true; |
149 } | 149 } |
150 | 150 |
151 void GlesVideoRenderer::OnFrameAvailable() { | 151 void GlesVideoRenderer::OnFrameAvailable() { |
152 AutoLock auto_lock(lock_); | 152 if (glx_thread_message_loop()) { |
153 new_frame_ = true; | 153 glx_thread_message_loop()->PostTask(FROM_HERE, |
| 154 NewRunnableMethod(this, &GlesVideoRenderer::Paint)); |
| 155 } |
154 } | 156 } |
155 | 157 |
156 void GlesVideoRenderer::Paint() { | 158 void GlesVideoRenderer::Paint() { |
157 // Use |new_frame_| to prevent overdraw since Paint() is called more | |
158 // often than needed. It is OK to lock only this flag and we don't | |
159 // want to lock the whole function because this method takes a long | |
160 // time to complete. | |
161 { | |
162 AutoLock auto_lock(lock_); | |
163 if (!new_frame_) | |
164 return; | |
165 new_frame_ = false; | |
166 } | |
167 | |
168 // Initialize GLES here to avoid context switching. Some drivers doesn't | 159 // Initialize GLES here to avoid context switching. Some drivers doesn't |
169 // like switching context between threads. | 160 // like switching context between threads. |
170 static bool initialized = false; | 161 static bool initialized = false; |
171 if (!initialized && !InitializeGles()) { | 162 if (!initialized && !InitializeGles()) { |
172 initialized = true; | 163 initialized = true; |
173 host()->SetError(media::PIPELINE_ERROR_COULD_NOT_RENDER); | 164 host()->SetError(media::PIPELINE_ERROR_COULD_NOT_RENDER); |
174 return; | 165 return; |
175 } | 166 } |
176 initialized = true; | 167 initialized = true; |
177 | 168 |
(...skipping 327 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
505 | 496 |
506 int pos_location = glGetAttribLocation(program, "in_pos"); | 497 int pos_location = glGetAttribLocation(program, "in_pos"); |
507 glEnableVertexAttribArray(pos_location); | 498 glEnableVertexAttribArray(pos_location); |
508 glVertexAttribPointer(pos_location, 2, GL_FLOAT, GL_FALSE, 0, kVertices); | 499 glVertexAttribPointer(pos_location, 2, GL_FLOAT, GL_FALSE, 0, kVertices); |
509 | 500 |
510 int tc_location = glGetAttribLocation(program, "in_tc"); | 501 int tc_location = glGetAttribLocation(program, "in_tc"); |
511 glEnableVertexAttribArray(tc_location); | 502 glEnableVertexAttribArray(tc_location); |
512 glVertexAttribPointer(tc_location, 2, GL_FLOAT, GL_FALSE, 0, | 503 glVertexAttribPointer(tc_location, 2, GL_FLOAT, GL_FALSE, 0, |
513 kTextureCoords); | 504 kTextureCoords); |
514 } | 505 } |
OLD | NEW |