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> |
11 | 11 |
12 #include "media/base/buffers.h" | 12 #include "media/base/video_frame.h" |
13 #include "media/base/yuv_convert.h" | 13 #include "media/base/yuv_convert.h" |
14 | 14 |
15 X11VideoRenderer* X11VideoRenderer::instance_ = NULL; | 15 X11VideoRenderer* X11VideoRenderer::instance_ = NULL; |
16 | 16 |
17 // Returns the picture format for ARGB. | 17 // Returns the picture format for ARGB. |
18 // This method is originally from chrome/common/x11_util.cc. | 18 // This method is originally from chrome/common/x11_util.cc. |
19 static XRenderPictFormat* GetRenderARGB32Format(Display* dpy) { | 19 static XRenderPictFormat* GetRenderARGB32Format(Display* dpy) { |
20 static XRenderPictFormat* pictformat = NULL; | 20 static XRenderPictFormat* pictformat = NULL; |
21 if (pictformat) | 21 if (pictformat) |
22 return pictformat; | 22 return pictformat; |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
146 new_frame_ = false; | 146 new_frame_ = false; |
147 } | 147 } |
148 | 148 |
149 scoped_refptr<media::VideoFrame> video_frame; | 149 scoped_refptr<media::VideoFrame> video_frame; |
150 GetCurrentFrame(&video_frame); | 150 GetCurrentFrame(&video_frame); |
151 | 151 |
152 if (!image_ ||!video_frame) | 152 if (!image_ ||!video_frame) |
153 return; | 153 return; |
154 | 154 |
155 // Convert YUV frame to RGB. | 155 // Convert YUV frame to RGB. |
156 media::VideoSurface frame_in; | 156 DCHECK(video_frame->format() == media::VideoFrame::YV12 || |
157 if (video_frame->Lock(&frame_in)) { | 157 video_frame->format() == media::VideoFrame::YV16); |
158 DCHECK(frame_in.format == media::VideoSurface::YV12 || | 158 DCHECK(video_frame->stride(media::VideoFrame::kUPlane) == |
159 frame_in.format == media::VideoSurface::YV16); | 159 video_frame->stride(media::VideoFrame::kVPlane)); |
160 DCHECK(frame_in.strides[media::VideoSurface::kUPlane] == | 160 DCHECK(video_frame->planes() == media::VideoFrame::kNumYUVPlanes); |
161 frame_in.strides[media::VideoSurface::kVPlane]); | |
162 DCHECK(frame_in.planes == media::VideoSurface::kNumYUVPlanes); | |
163 | 161 |
164 DCHECK(image_->data); | 162 DCHECK(image_->data); |
165 media::YUVType yuv_type = (frame_in.format == media::VideoSurface::YV12) ? | 163 media::YUVType yuv_type = |
166 media::YV12 : media::YV16; | 164 (video_frame->format() == media::VideoFrame::YV12) ? |
167 media::ConvertYUVToRGB32(frame_in.data[media::VideoSurface::kYPlane], | 165 media::YV12 : media::YV16; |
168 frame_in.data[media::VideoSurface::kUPlane], | 166 media::ConvertYUVToRGB32(video_frame->data(media::VideoFrame::kYPlane), |
169 frame_in.data[media::VideoSurface::kVPlane], | 167 video_frame->data(media::VideoFrame::kUPlane), |
170 (uint8*)image_->data, | 168 video_frame->data(media::VideoFrame::kVPlane), |
171 frame_in.width, | 169 (uint8*)image_->data, |
172 frame_in.height, | 170 video_frame->width(), |
173 frame_in.strides[media::VideoSurface::kYPlane], | 171 video_frame->height(), |
174 frame_in.strides[media::VideoSurface::kUPlane], | 172 video_frame->stride(media::VideoFrame::kYPlane), |
175 image_->bytes_per_line, | 173 video_frame->stride(media::VideoFrame::kUPlane), |
176 yuv_type); | 174 image_->bytes_per_line, |
177 video_frame->Unlock(); | 175 yuv_type); |
178 } else { | |
179 NOTREACHED(); | |
180 } | |
181 | 176 |
182 if (use_render_) { | 177 if (use_render_) { |
183 // If XRender is used, we'll upload the image to a pixmap. And then | 178 // If XRender is used, we'll upload the image to a pixmap. And then |
184 // creats a picture from the pixmap and composite the picture over | 179 // creats a picture from the pixmap and composite the picture over |
185 // the picture represending the window. | 180 // the picture represending the window. |
186 | 181 |
187 // Creates a XImage. | 182 // Creates a XImage. |
188 XImage image; | 183 XImage image; |
189 memset(&image, 0, sizeof(image)); | 184 memset(&image, 0, sizeof(image)); |
190 image.width = width_; | 185 image.width = width_; |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
230 // If XRender is not used, simply put the image to the server. | 225 // If XRender is not used, simply put the image to the server. |
231 // This will have a tearing effect but this is OK. | 226 // This will have a tearing effect but this is OK. |
232 // TODO(hclam): Upload the image to a pixmap and do XCopyArea() | 227 // TODO(hclam): Upload the image to a pixmap and do XCopyArea() |
233 // to the window. | 228 // to the window. |
234 GC gc = XCreateGC(display_, window_, 0, NULL); | 229 GC gc = XCreateGC(display_, window_, 0, NULL); |
235 XPutImage(display_, window_, gc, image_, | 230 XPutImage(display_, window_, gc, image_, |
236 0, 0, 0, 0, width_, height_); | 231 0, 0, 0, 0, width_, height_); |
237 XFlush(display_); | 232 XFlush(display_); |
238 XFreeGC(display_, gc); | 233 XFreeGC(display_, gc); |
239 } | 234 } |
OLD | NEW |