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

Side by Side Diff: media/tools/player_x11/gl_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/gl_video_renderer.h ('k') | media/tools/player_x11/x11_video_renderer.h » ('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/gl_video_renderer.h" 5 #include "media/tools/player_x11/gl_video_renderer.h"
6 6
7 #include <X11/Xutil.h> 7 #include <X11/Xutil.h>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/message_loop.h" 10 #include "base/message_loop.h"
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
114 gl_context_(NULL) { 114 gl_context_(NULL) {
115 } 115 }
116 116
117 GlVideoRenderer::~GlVideoRenderer() { 117 GlVideoRenderer::~GlVideoRenderer() {
118 glXMakeCurrent(display_, 0, NULL); 118 glXMakeCurrent(display_, 0, NULL);
119 glXDestroyContext(display_, gl_context_); 119 glXDestroyContext(display_, gl_context_);
120 } 120 }
121 121
122 void GlVideoRenderer::Paint(media::VideoFrame* video_frame) { 122 void GlVideoRenderer::Paint(media::VideoFrame* video_frame) {
123 if (!gl_context_) 123 if (!gl_context_)
124 Initialize(video_frame->data_size().width(), 124 Initialize(video_frame->coded_size(), video_frame->visible_rect());
125 video_frame->data_size().height());
126 125
127 // Convert YUV frame to RGB. 126 // Convert YUV frame to RGB.
128 DCHECK(video_frame->format() == media::VideoFrame::YV12 || 127 DCHECK(video_frame->format() == media::VideoFrame::YV12 ||
129 video_frame->format() == media::VideoFrame::YV16); 128 video_frame->format() == media::VideoFrame::YV16);
130 DCHECK(video_frame->stride(media::VideoFrame::kUPlane) == 129 DCHECK(video_frame->stride(media::VideoFrame::kUPlane) ==
131 video_frame->stride(media::VideoFrame::kVPlane)); 130 video_frame->stride(media::VideoFrame::kVPlane));
132 131
133 if (glXGetCurrentContext() != gl_context_ || 132 if (glXGetCurrentContext() != gl_context_ ||
134 glXGetCurrentDrawable() != window_) { 133 glXGetCurrentDrawable() != window_) {
135 glXMakeCurrent(display_, window_, gl_context_); 134 glXMakeCurrent(display_, window_, gl_context_);
136 } 135 }
137 for (unsigned int i = 0; i < kNumYUVPlanes; ++i) { 136 for (unsigned int i = 0; i < kNumYUVPlanes; ++i) {
138 unsigned int width = video_frame->stride(i); 137 unsigned int width = video_frame->stride(i);
139 unsigned int height = video_frame->rows(i); 138 unsigned int height = video_frame->rows(i);
140 glActiveTexture(GL_TEXTURE0 + i); 139 glActiveTexture(GL_TEXTURE0 + i);
141 glPixelStorei(GL_UNPACK_ROW_LENGTH, video_frame->stride(i)); 140 glPixelStorei(GL_UNPACK_ROW_LENGTH, video_frame->stride(i));
142 glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, width, height, 0, 141 glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, width, height, 0,
143 GL_LUMINANCE, GL_UNSIGNED_BYTE, video_frame->data(i)); 142 GL_LUMINANCE, GL_UNSIGNED_BYTE, video_frame->data(i));
144 } 143 }
145 144
146 glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); 145 glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
147 glXSwapBuffers(display_, window_); 146 glXSwapBuffers(display_, window_);
148 } 147 }
149 148
150 void GlVideoRenderer::Initialize(int width, int height) { 149 void GlVideoRenderer::Initialize(gfx::Size coded_size, gfx::Rect visible_rect) {
151 CHECK(!gl_context_); 150 CHECK(!gl_context_);
152 LOG(INFO) << "Initializing GL Renderer..."; 151 LOG(INFO) << "Initializing GL Renderer...";
153 152
154 // Resize the window to fit that of the video. 153 // Resize the window to fit that of the video.
155 XResizeWindow(display_, window_, width, height); 154 XResizeWindow(display_, window_, visible_rect.width(), visible_rect.height());
156 155
157 gl_context_ = InitGLContext(display_, window_); 156 gl_context_ = InitGLContext(display_, window_);
158 CHECK(gl_context_) << "Failed to initialize GL context"; 157 CHECK(gl_context_) << "Failed to initialize GL context";
159 158
160 // Create 3 textures, one for each plane, and bind them to different 159 // Create 3 textures, one for each plane, and bind them to different
161 // texture units. 160 // texture units.
162 glGenTextures(3, textures_); 161 glGenTextures(3, textures_);
163 glActiveTexture(GL_TEXTURE0); 162 glActiveTexture(GL_TEXTURE0);
164 glBindTexture(GL_TEXTURE_2D, textures_[0]); 163 glBindTexture(GL_TEXTURE_2D, textures_[0]);
165 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); 164 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
234 glUniform1i(glGetUniformLocation(program, "v_tex"), 2); 233 glUniform1i(glGetUniformLocation(program, "v_tex"), 2);
235 int yuv2rgb_location = glGetUniformLocation(program, "yuv2rgb"); 234 int yuv2rgb_location = glGetUniformLocation(program, "yuv2rgb");
236 glUniformMatrix3fv(yuv2rgb_location, 1, GL_TRUE, kYUV2RGB); 235 glUniformMatrix3fv(yuv2rgb_location, 1, GL_TRUE, kYUV2RGB);
237 236
238 int pos_location = glGetAttribLocation(program, "in_pos"); 237 int pos_location = glGetAttribLocation(program, "in_pos");
239 glEnableVertexAttribArray(pos_location); 238 glEnableVertexAttribArray(pos_location);
240 glVertexAttribPointer(pos_location, 2, GL_FLOAT, GL_FALSE, 0, kVertices); 239 glVertexAttribPointer(pos_location, 2, GL_FLOAT, GL_FALSE, 0, kVertices);
241 240
242 int tc_location = glGetAttribLocation(program, "in_tc"); 241 int tc_location = glGetAttribLocation(program, "in_tc");
243 glEnableVertexAttribArray(tc_location); 242 glEnableVertexAttribArray(tc_location);
244 glVertexAttribPointer(tc_location, 2, GL_FLOAT, GL_FALSE, 0, 243 float verts[8];
245 kTextureCoords); 244 float x0 = static_cast<float>(visible_rect.x()) / coded_size.width();
245 float y0 = static_cast<float>(visible_rect.y()) / coded_size.height();
246 float x1 = static_cast<float>(visible_rect.right()) / coded_size.width();
247 float y1 = static_cast<float>(visible_rect.bottom()) / coded_size.height();
248 verts[0] = x0; verts[1] = y0;
249 verts[2] = x0; verts[3] = y1;
250 verts[4] = x1; verts[5] = y0;
251 verts[6] = x1; verts[7] = y1;
252 glVertexAttribPointer(tc_location, 2, GL_FLOAT, GL_FALSE, 0, verts);
246 253
247 // We are getting called on a thread. Release the context so that it can be 254 // We are getting called on a thread. Release the context so that it can be
248 // made current on the main thread. 255 // made current on the main thread.
249 glXMakeCurrent(display_, 0, NULL); 256 glXMakeCurrent(display_, 0, NULL);
250 } 257 }
OLDNEW
« no previous file with comments | « media/tools/player_x11/gl_video_renderer.h ('k') | media/tools/player_x11/x11_video_renderer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698