| 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/x11_video_renderer.h" | 5 #include "media/tools/player_x11/x11_video_renderer.h" |
| 6 | 6 |
| 7 #include <dlfcn.h> | 7 #include <dlfcn.h> |
| 8 #include <X11/Xutil.h> | 8 #include <X11/Xutil.h> |
| 9 #include <X11/extensions/Xrender.h> | 9 #include <X11/extensions/Xrender.h> |
| 10 #include <X11/extensions/Xcomposite.h> | 10 #include <X11/extensions/Xcomposite.h> |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 50 CHECK(pictformat) << "XRENDER ARGB32 not supported."; | 50 CHECK(pictformat) << "XRENDER ARGB32 not supported."; |
| 51 } | 51 } |
| 52 | 52 |
| 53 return pictformat; | 53 return pictformat; |
| 54 } | 54 } |
| 55 | 55 |
| 56 X11VideoRenderer::X11VideoRenderer(Display* display, Window window) | 56 X11VideoRenderer::X11VideoRenderer(Display* display, Window window) |
| 57 : display_(display), | 57 : display_(display), |
| 58 window_(window), | 58 window_(window), |
| 59 image_(NULL), | 59 image_(NULL), |
| 60 new_frame_(false), | |
| 61 picture_(0), | 60 picture_(0), |
| 62 use_render_(false) { | 61 use_render_(false), |
| 62 glx_thread_message_loop_(NULL) { |
| 63 } | 63 } |
| 64 | 64 |
| 65 X11VideoRenderer::~X11VideoRenderer() { | 65 X11VideoRenderer::~X11VideoRenderer() { |
| 66 } | 66 } |
| 67 | 67 |
| 68 // static | 68 // static |
| 69 bool X11VideoRenderer::IsMediaFormatSupported( | 69 bool X11VideoRenderer::IsMediaFormatSupported( |
| 70 const media::MediaFormat& media_format) { | 70 const media::MediaFormat& media_format) { |
| 71 int width = 0; | 71 int width = 0; |
| 72 int height = 0; | 72 int height = 0; |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 125 width_ * 4); | 125 width_ * 4); |
| 126 DCHECK(image_); | 126 DCHECK(image_); |
| 127 | 127 |
| 128 // Save this instance. | 128 // Save this instance. |
| 129 DCHECK(!instance_); | 129 DCHECK(!instance_); |
| 130 instance_ = this; | 130 instance_ = this; |
| 131 return true; | 131 return true; |
| 132 } | 132 } |
| 133 | 133 |
| 134 void X11VideoRenderer::OnFrameAvailable() { | 134 void X11VideoRenderer::OnFrameAvailable() { |
| 135 AutoLock auto_lock(lock_); | 135 if (glx_thread_message_loop()) { |
| 136 new_frame_ = true; | 136 glx_thread_message_loop()->PostTask(FROM_HERE, |
| 137 NewRunnableMethod(this, &X11VideoRenderer::Paint)); |
| 138 } |
| 137 } | 139 } |
| 138 | 140 |
| 139 void X11VideoRenderer::Paint() { | 141 void X11VideoRenderer::Paint() { |
| 140 // Use |new_frame_| to prevent overdraw since Paint() is called more | |
| 141 // often than needed. It is OK to lock only this flag and we don't | |
| 142 // want to lock the whole function because this method takes a long | |
| 143 // time to complete. | |
| 144 { | |
| 145 AutoLock auto_lock(lock_); | |
| 146 if (!new_frame_) | |
| 147 return; | |
| 148 new_frame_ = false; | |
| 149 } | |
| 150 | |
| 151 scoped_refptr<media::VideoFrame> video_frame; | 142 scoped_refptr<media::VideoFrame> video_frame; |
| 152 GetCurrentFrame(&video_frame); | 143 GetCurrentFrame(&video_frame); |
| 153 | 144 |
| 154 if (!image_ ||!video_frame) | 145 if (!image_ ||!video_frame) |
| 155 return; | 146 return; |
| 156 | 147 |
| 157 // Convert YUV frame to RGB. | 148 // Convert YUV frame to RGB. |
| 158 DCHECK(video_frame->format() == media::VideoFrame::YV12 || | 149 DCHECK(video_frame->format() == media::VideoFrame::YV12 || |
| 159 video_frame->format() == media::VideoFrame::YV16); | 150 video_frame->format() == media::VideoFrame::YV16); |
| 160 DCHECK(video_frame->stride(media::VideoFrame::kUPlane) == | 151 DCHECK(video_frame->stride(media::VideoFrame::kUPlane) == |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 227 // If XRender is not used, simply put the image to the server. | 218 // If XRender is not used, simply put the image to the server. |
| 228 // This will have a tearing effect but this is OK. | 219 // This will have a tearing effect but this is OK. |
| 229 // TODO(hclam): Upload the image to a pixmap and do XCopyArea() | 220 // TODO(hclam): Upload the image to a pixmap and do XCopyArea() |
| 230 // to the window. | 221 // to the window. |
| 231 GC gc = XCreateGC(display_, window_, 0, NULL); | 222 GC gc = XCreateGC(display_, window_, 0, NULL); |
| 232 XPutImage(display_, window_, gc, image_, | 223 XPutImage(display_, window_, gc, image_, |
| 233 0, 0, 0, 0, width_, height_); | 224 0, 0, 0, 0, width_, height_); |
| 234 XFlush(display_); | 225 XFlush(display_); |
| 235 XFreeGC(display_, gc); | 226 XFreeGC(display_, gc); |
| 236 } | 227 } |
| OLD | NEW |