Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(431)

Side by Side Diff: media/tools/player_x11/x11_video_renderer.cc

Issue 11269017: Plumb through cropped output size for VideoFrame (Closed) Base URL: https://git.chromium.org/git/chromium/src@git-svn
Patch Set: Found the windows failure, and fixed it. Thanks akalin@ Created 8 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « media/tools/player_x11/x11_video_renderer.h ('k') | media/tools/scaler_bench/scaler_bench.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
77 } 77 }
78 78
79 X11VideoRenderer::~X11VideoRenderer() { 79 X11VideoRenderer::~X11VideoRenderer() {
80 if (image_) 80 if (image_)
81 XDestroyImage(image_); 81 XDestroyImage(image_);
82 if (use_render_) 82 if (use_render_)
83 XRenderFreePicture(display_, picture_); 83 XRenderFreePicture(display_, picture_);
84 } 84 }
85 85
86 void X11VideoRenderer::Paint(media::VideoFrame* video_frame) { 86 void X11VideoRenderer::Paint(media::VideoFrame* video_frame) {
87 int width = video_frame->data_size().width(); 87 if (!image_)
88 int height = video_frame->data_size().height(); 88 Initialize(video_frame->coded_size(), video_frame->visible_rect());
89 89
90 if (!image_) 90 const int coded_width = video_frame->coded_size().width();
91 Initialize(width, height); 91 const int coded_height = video_frame->coded_size().height();
92 const int visible_width = video_frame->visible_rect().width();
93 const int visible_height = video_frame->visible_rect().height();
92 94
93 // Check if we need to reallocate our XImage. 95 // Check if we need to reallocate our XImage.
94 if (image_->width != width || image_->height != height) { 96 if (image_->width != coded_width || image_->height != coded_height) {
95 XDestroyImage(image_); 97 XDestroyImage(image_);
96 image_ = CreateImage(display_, width, height); 98 image_ = CreateImage(display_, coded_width, coded_height);
97 } 99 }
98 100
99 // Convert YUV frame to RGB. 101 // Convert YUV frame to RGB.
100 DCHECK(video_frame->format() == media::VideoFrame::YV12 || 102 DCHECK(video_frame->format() == media::VideoFrame::YV12 ||
101 video_frame->format() == media::VideoFrame::YV16); 103 video_frame->format() == media::VideoFrame::YV16);
102 DCHECK(video_frame->stride(media::VideoFrame::kUPlane) == 104 DCHECK(video_frame->stride(media::VideoFrame::kUPlane) ==
103 video_frame->stride(media::VideoFrame::kVPlane)); 105 video_frame->stride(media::VideoFrame::kVPlane));
104 106
105 DCHECK(image_->data); 107 DCHECK(image_->data);
106 media::YUVType yuv_type = 108 media::YUVType yuv_type =
107 (video_frame->format() == media::VideoFrame::YV12) ? 109 (video_frame->format() == media::VideoFrame::YV12) ?
108 media::YV12 : media::YV16; 110 media::YV12 : media::YV16;
109 media::ConvertYUVToRGB32(video_frame->data(media::VideoFrame::kYPlane), 111 media::ConvertYUVToRGB32(video_frame->data(media::VideoFrame::kYPlane),
110 video_frame->data(media::VideoFrame::kUPlane), 112 video_frame->data(media::VideoFrame::kUPlane),
111 video_frame->data(media::VideoFrame::kVPlane), 113 video_frame->data(media::VideoFrame::kVPlane),
112 (uint8*)image_->data, 114 (uint8*)image_->data, coded_width, coded_height,
113 video_frame->data_size().width(),
114 video_frame->data_size().height(),
115 video_frame->stride(media::VideoFrame::kYPlane), 115 video_frame->stride(media::VideoFrame::kYPlane),
116 video_frame->stride(media::VideoFrame::kUPlane), 116 video_frame->stride(media::VideoFrame::kUPlane),
117 image_->bytes_per_line, 117 image_->bytes_per_line,
118 yuv_type); 118 yuv_type);
119 119
120 if (use_render_) { 120 if (use_render_) {
121 // If XRender is used, we'll upload the image to a pixmap. And then 121 // If XRender is used, we'll upload the image to a pixmap. And then
122 // creats a picture from the pixmap and composite the picture over 122 // creats a picture from the pixmap and composite the picture over
123 // the picture represending the window. 123 // the picture represending the window.
124 124
125 // Creates a XImage. 125 // Creates a XImage.
126 XImage image; 126 XImage image;
127 memset(&image, 0, sizeof(image)); 127 memset(&image, 0, sizeof(image));
128 image.width = width; 128 image.width = coded_width;
129 image.height = height; 129 image.height = coded_height;
130 image.depth = 32; 130 image.depth = 32;
131 image.bits_per_pixel = 32; 131 image.bits_per_pixel = 32;
132 image.format = ZPixmap; 132 image.format = ZPixmap;
133 image.byte_order = LSBFirst; 133 image.byte_order = LSBFirst;
134 image.bitmap_unit = 8; 134 image.bitmap_unit = 8;
135 image.bitmap_bit_order = LSBFirst; 135 image.bitmap_bit_order = LSBFirst;
136 image.bytes_per_line = image_->bytes_per_line; 136 image.bytes_per_line = image_->bytes_per_line;
137 image.red_mask = 0xff; 137 image.red_mask = 0xff;
138 image.green_mask = 0xff00; 138 image.green_mask = 0xff00;
139 image.blue_mask = 0xff0000; 139 image.blue_mask = 0xff0000;
140 image.data = image_->data; 140 image.data = image_->data;
141 141
142 // Creates a pixmap and uploads from the XImage. 142 // Creates a pixmap and uploads from the XImage.
143 unsigned long pixmap = XCreatePixmap(display_, 143 unsigned long pixmap = XCreatePixmap(display_, window_,
144 window_, 144 visible_width, visible_height,
145 width,
146 height,
147 32); 145 32);
148 GC gc = XCreateGC(display_, pixmap, 0, NULL); 146 GC gc = XCreateGC(display_, pixmap, 0, NULL);
149 XPutImage(display_, pixmap, gc, &image, 147 XPutImage(display_, pixmap, gc, &image,
150 0, 0, 0, 0, 148 video_frame->visible_rect().x(),
151 width, height); 149 video_frame->visible_rect().y(),
150 0, 0,
151 visible_width, visible_height);
152 XFreeGC(display_, gc); 152 XFreeGC(display_, gc);
153 153
154 // Creates the picture representing the pixmap. 154 // Creates the picture representing the pixmap.
155 unsigned long picture = XRenderCreatePicture( 155 unsigned long picture = XRenderCreatePicture(
156 display_, pixmap, GetRenderARGB32Format(display_), 0, NULL); 156 display_, pixmap, GetRenderARGB32Format(display_), 0, NULL);
157 157
158 // Composite the picture over the picture representing the window. 158 // Composite the picture over the picture representing the window.
159 XRenderComposite(display_, PictOpSrc, picture, 0, 159 XRenderComposite(display_, PictOpSrc, picture, 0,
160 picture_, 0, 0, 0, 0, 0, 0, 160 picture_, 0, 0, 0, 0, 0, 0,
161 width, height); 161 visible_width, visible_height);
162 162
163 XRenderFreePicture(display_, picture); 163 XRenderFreePicture(display_, picture);
164 XFreePixmap(display_, pixmap); 164 XFreePixmap(display_, pixmap);
165 return; 165 return;
166 } 166 }
167 167
168 // If XRender is not used, simply put the image to the server. 168 // If XRender is not used, simply put the image to the server.
169 // This will have a tearing effect but this is OK. 169 // This will have a tearing effect but this is OK.
170 // TODO(hclam): Upload the image to a pixmap and do XCopyArea() 170 // TODO(hclam): Upload the image to a pixmap and do XCopyArea()
171 // to the window. 171 // to the window.
172 GC gc = XCreateGC(display_, window_, 0, NULL); 172 GC gc = XCreateGC(display_, window_, 0, NULL);
173 XPutImage(display_, window_, gc, image_, 173 XPutImage(display_, window_, gc, image_,
174 0, 0, 0, 0, width, height); 174 video_frame->visible_rect().x(),
175 video_frame->visible_rect().y(),
176 0, 0, visible_width, visible_height);
175 XFlush(display_); 177 XFlush(display_);
176 XFreeGC(display_, gc); 178 XFreeGC(display_, gc);
177 } 179 }
178 180
179 void X11VideoRenderer::Initialize(int width, int height) { 181 void X11VideoRenderer::Initialize(gfx::Size coded_size,
182 gfx::Rect visible_rect) {
180 CHECK(!image_); 183 CHECK(!image_);
181 LOG(INFO) << "Initializing X11 Renderer..."; 184 LOG(INFO) << "Initializing X11 Renderer...";
182 185
183 // Resize the window to fit that of the video. 186 // Resize the window to fit that of the video.
184 XResizeWindow(display_, window_, width, height); 187 XResizeWindow(display_, window_, visible_rect.width(), visible_rect.height());
185 image_ = CreateImage(display_, width, height); 188 image_ = CreateImage(display_, coded_size.width(), coded_size.height());
186 189
187 // Testing XRender support. We'll use the very basic of XRender 190 // Testing XRender support. We'll use the very basic of XRender
188 // so if it presents it is already good enough. We don't need 191 // so if it presents it is already good enough. We don't need
189 // to check its version. 192 // to check its version.
190 int dummy; 193 int dummy;
191 use_render_ = XRenderQueryExtension(display_, &dummy, &dummy); 194 use_render_ = XRenderQueryExtension(display_, &dummy, &dummy);
192 195
193 if (use_render_) { 196 if (use_render_) {
194 LOG(INFO) << "Using XRender extension."; 197 LOG(INFO) << "Using XRender extension.";
195 198
196 // If we are using XRender, we'll create a picture representing the 199 // If we are using XRender, we'll create a picture representing the
197 // window. 200 // window.
198 XWindowAttributes attr; 201 XWindowAttributes attr;
199 XGetWindowAttributes(display_, window_, &attr); 202 XGetWindowAttributes(display_, window_, &attr);
200 203
201 XRenderPictFormat* pictformat = XRenderFindVisualFormat( 204 XRenderPictFormat* pictformat = XRenderFindVisualFormat(
202 display_, 205 display_,
203 attr.visual); 206 attr.visual);
204 CHECK(pictformat) << "XRender does not support default visual"; 207 CHECK(pictformat) << "XRender does not support default visual";
205 208
206 picture_ = XRenderCreatePicture(display_, window_, pictformat, 0, NULL); 209 picture_ = XRenderCreatePicture(display_, window_, pictformat, 0, NULL);
207 CHECK(picture_) << "Backing picture not created"; 210 CHECK(picture_) << "Backing picture not created";
208 } 211 }
209 } 212 }
OLDNEW
« no previous file with comments | « media/tools/player_x11/x11_video_renderer.h ('k') | media/tools/scaler_bench/scaler_bench.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698