| 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/gl_video_renderer.h" | 5 #include "media/tools/player_x11/gl_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/buffers.h" |
| 13 #include "media/base/video_frame.h" |
| 13 #include "media/base/yuv_convert.h" | 14 #include "media/base/yuv_convert.h" |
| 14 | 15 |
| 15 GlVideoRenderer* GlVideoRenderer::instance_ = NULL; | 16 GlVideoRenderer* GlVideoRenderer::instance_ = NULL; |
| 16 | 17 |
| 17 GlVideoRenderer::GlVideoRenderer(Display* display, Window window) | 18 GlVideoRenderer::GlVideoRenderer(Display* display, Window window) |
| 18 : display_(display), | 19 : display_(display), |
| 19 window_(window), | 20 window_(window), |
| 20 new_frame_(false), | 21 new_frame_(false), |
| 21 gl_context_(NULL) { | 22 gl_context_(NULL) { |
| 22 } | 23 } |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 157 XResizeWindow(display_, window_, width_, height_); | 158 XResizeWindow(display_, window_, width_, height_); |
| 158 | 159 |
| 159 gl_context_ = InitGLContext(display_, window_); | 160 gl_context_ = InitGLContext(display_, window_); |
| 160 if (!gl_context_) | 161 if (!gl_context_) |
| 161 return false; | 162 return false; |
| 162 | 163 |
| 163 glMatrixMode(GL_MODELVIEW); | 164 glMatrixMode(GL_MODELVIEW); |
| 164 | 165 |
| 165 // Create 3 textures, one for each plane, and bind them to different | 166 // Create 3 textures, one for each plane, and bind them to different |
| 166 // texture units. | 167 // texture units. |
| 167 glGenTextures(media::VideoSurface::kNumYUVPlanes, textures_); | 168 glGenTextures(media::VideoFrame::kNumYUVPlanes, textures_); |
| 168 glActiveTexture(GL_TEXTURE0); | 169 glActiveTexture(GL_TEXTURE0); |
| 169 glBindTexture(GL_TEXTURE_2D, textures_[0]); | 170 glBindTexture(GL_TEXTURE_2D, textures_[0]); |
| 170 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); | 171 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); |
| 171 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); | 172 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
| 172 glEnable(GL_TEXTURE_2D); | 173 glEnable(GL_TEXTURE_2D); |
| 173 | 174 |
| 174 glActiveTexture(GL_TEXTURE1); | 175 glActiveTexture(GL_TEXTURE1); |
| 175 glBindTexture(GL_TEXTURE_2D, textures_[1]); | 176 glBindTexture(GL_TEXTURE_2D, textures_[1]); |
| 176 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); | 177 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); |
| 177 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); | 178 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 276 new_frame_ = false; | 277 new_frame_ = false; |
| 277 } | 278 } |
| 278 | 279 |
| 279 scoped_refptr<media::VideoFrame> video_frame; | 280 scoped_refptr<media::VideoFrame> video_frame; |
| 280 GetCurrentFrame(&video_frame); | 281 GetCurrentFrame(&video_frame); |
| 281 | 282 |
| 282 if (!video_frame) | 283 if (!video_frame) |
| 283 return; | 284 return; |
| 284 | 285 |
| 285 // Convert YUV frame to RGB. | 286 // Convert YUV frame to RGB. |
| 286 media::VideoSurface frame_in; | 287 DCHECK(video_frame->format() == media::VideoFrame::YV12 || |
| 287 if (video_frame->Lock(&frame_in)) { | 288 video_frame->format() == media::VideoFrame::YV16); |
| 288 DCHECK(frame_in.format == media::VideoSurface::YV12 || | 289 DCHECK(video_frame->stride(media::VideoFrame::kUPlane) == |
| 289 frame_in.format == media::VideoSurface::YV16); | 290 video_frame->stride(media::VideoFrame::kVPlane)); |
| 290 DCHECK(frame_in.strides[media::VideoSurface::kUPlane] == | 291 DCHECK(video_frame->planes() == media::VideoFrame::kNumYUVPlanes); |
| 291 frame_in.strides[media::VideoSurface::kVPlane]); | |
| 292 DCHECK(frame_in.planes == media::VideoSurface::kNumYUVPlanes); | |
| 293 | 292 |
| 294 if (glXGetCurrentContext() != gl_context_ || | 293 if (glXGetCurrentContext() != gl_context_ || |
| 295 glXGetCurrentDrawable() != window_) { | 294 glXGetCurrentDrawable() != window_) { |
| 296 glXMakeCurrent(display_, window_, gl_context_); | 295 glXMakeCurrent(display_, window_, gl_context_); |
| 297 } | 296 } |
| 298 for (unsigned int i = 0; i < media::VideoSurface::kNumYUVPlanes; ++i) { | 297 for (unsigned int i = 0; i < media::VideoFrame::kNumYUVPlanes; ++i) { |
| 299 unsigned int width = (i == media::VideoSurface::kYPlane) ? | 298 unsigned int width = (i == media::VideoFrame::kYPlane) ? |
| 300 frame_in.width : frame_in.width / 2; | 299 video_frame->width() : video_frame->width() / 2; |
| 301 unsigned int height = (i == media::VideoSurface::kYPlane || | 300 unsigned int height = (i == media::VideoFrame::kYPlane || |
| 302 frame_in.format == media::VideoSurface::YV16) ? | 301 video_frame->format() == media::VideoFrame::YV16) ? |
| 303 frame_in.height : frame_in.height / 2; | 302 video_frame->height() : video_frame->height() / 2; |
| 304 glActiveTexture(GL_TEXTURE0 + i); | 303 glActiveTexture(GL_TEXTURE0 + i); |
| 305 glPixelStorei(GL_UNPACK_ROW_LENGTH, frame_in.strides[i]); | 304 glPixelStorei(GL_UNPACK_ROW_LENGTH, video_frame->stride(i)); |
| 306 glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, width, height, 0, | 305 glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, width, height, 0, |
| 307 GL_LUMINANCE, GL_UNSIGNED_BYTE, frame_in.data[i]); | 306 GL_LUMINANCE, GL_UNSIGNED_BYTE, video_frame->data(i)); |
| 308 } | |
| 309 video_frame->Unlock(); | |
| 310 } else { | |
| 311 NOTREACHED(); | |
| 312 } | 307 } |
| 313 | 308 |
| 314 glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); | 309 glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); |
| 315 glXSwapBuffers(display_, window_); | 310 glXSwapBuffers(display_, window_); |
| 316 } | 311 } |
| OLD | NEW |