OLD | NEW |
---|---|
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 <string.h> | 5 #include <string.h> |
6 | 6 |
7 #include <iostream> | 7 #include <iostream> |
8 #include <sstream> | 8 #include <sstream> |
9 #include <list> | 9 #include <list> |
10 #include <map> | 10 #include <map> |
11 #include <set> | 11 #include <set> |
12 #include <vector> | 12 #include <vector> |
13 | 13 |
14 #include "ppapi/c/dev/ppb_console_dev.h" | 14 #include "ppapi/c/dev/ppb_console_dev.h" |
15 #include "ppapi/c/pp_errors.h" | 15 #include "ppapi/c/pp_errors.h" |
16 #include "ppapi/c/ppb_opengles2.h" | 16 #include "ppapi/c/ppb_opengles2.h" |
17 #include "ppapi/cpp/dev/video_decoder_client_dev.h" | 17 #include "ppapi/cpp/dev/video_decoder_client_dev.h" |
18 #include "ppapi/cpp/dev/video_decoder_dev.h" | 18 #include "ppapi/cpp/dev/video_decoder_dev.h" |
19 #include "ppapi/cpp/graphics_3d.h" | 19 #include "ppapi/cpp/graphics_3d.h" |
20 #include "ppapi/cpp/graphics_3d_client.h" | 20 #include "ppapi/cpp/graphics_3d_client.h" |
21 #include "ppapi/cpp/instance.h" | 21 #include "ppapi/cpp/instance.h" |
22 #include "ppapi/cpp/module.h" | 22 #include "ppapi/cpp/module.h" |
23 #include "ppapi/cpp/rect.h" | 23 #include "ppapi/cpp/rect.h" |
24 #include "ppapi/cpp/var.h" | 24 #include "ppapi/cpp/var.h" |
25 #include "ppapi/examples/video_decode/testdata.h" | 25 #include "ppapi/examples/video_decode/testdata.h" |
26 #include "ppapi/lib/gl/include/GLES2/gl2.h" | 26 #include "ppapi/lib/gl/include/GLES2/gl2.h" |
27 #include "ppapi/lib/gl/include/GLES2/gl2ext.h" | |
27 #include "ppapi/utility/completion_callback_factory.h" | 28 #include "ppapi/utility/completion_callback_factory.h" |
28 | 29 |
29 // Use assert as a poor-man's CHECK, even in non-debug mode. | 30 // Use assert as a poor-man's CHECK, even in non-debug mode. |
30 // Since <assert.h> redefines assert on every inclusion (it doesn't use | 31 // Since <assert.h> redefines assert on every inclusion (it doesn't use |
31 // include-guards), make sure this is the last file #include'd in this file. | 32 // include-guards), make sure this is the last file #include'd in this file. |
32 #undef NDEBUG | 33 #undef NDEBUG |
33 #include <assert.h> | 34 #include <assert.h> |
34 | 35 |
35 // Assert |context_| isn't holding any GL Errors. Done as a macro instead of a | 36 // Assert |context_| isn't holding any GL Errors. Done as a macro instead of a |
36 // function to preserve line number information in the failure message. | 37 // function to preserve line number information in the failure message. |
37 #define assertNoGLError() \ | 38 #define assertNoGLError() \ |
38 assert(!gles2_if_->GetError(context_->pp_resource())); | 39 assert(!gles2_if_->GetError(context_->pp_resource())); |
39 | 40 |
40 namespace { | 41 namespace { |
41 | 42 |
43 struct PictureBufferInfo { | |
Ami GONE FROM CHROMIUM
2012/05/19 20:46:12
You could revert most of the changes to this file,
sail
2012/05/29 04:21:28
As we discussed, this may need to be platform inde
| |
44 PP_PictureBuffer_Dev buffer; | |
45 GLenum texture_target; | |
46 }; | |
47 | |
48 struct Shader { | |
49 Shader() : program(0), | |
50 texcoord_scale_location(0), | |
51 texcoord_offset_location(0) {} | |
52 | |
53 GLuint program; | |
54 GLint texcoord_scale_location; | |
55 GLint texcoord_offset_location; | |
56 }; | |
57 | |
42 class VideoDecodeDemoInstance : public pp::Instance, | 58 class VideoDecodeDemoInstance : public pp::Instance, |
43 public pp::Graphics3DClient, | 59 public pp::Graphics3DClient, |
44 public pp::VideoDecoderClient_Dev { | 60 public pp::VideoDecoderClient_Dev { |
45 public: | 61 public: |
46 VideoDecodeDemoInstance(PP_Instance instance, pp::Module* module); | 62 VideoDecodeDemoInstance(PP_Instance instance, pp::Module* module); |
47 virtual ~VideoDecodeDemoInstance(); | 63 virtual ~VideoDecodeDemoInstance(); |
48 | 64 |
49 // pp::Instance implementation (see PPP_Instance). | 65 // pp::Instance implementation (see PPP_Instance). |
50 virtual void DidChangeView(const pp::Rect& position, | 66 virtual void DidChangeView(const pp::Rect& position, |
51 const pp::Rect& clip_ignored); | 67 const pp::Rect& clip_ignored); |
(...skipping 12 matching lines...) Expand all Loading... | |
64 PP_Resource decoder, | 80 PP_Resource decoder, |
65 uint32_t req_num_of_bufs, | 81 uint32_t req_num_of_bufs, |
66 const PP_Size& dimensions, | 82 const PP_Size& dimensions, |
67 PP_VideoDecoder_TextureTarget_Dev texture_target); | 83 PP_VideoDecoder_TextureTarget_Dev texture_target); |
68 virtual void DismissPictureBuffer(PP_Resource decoder, | 84 virtual void DismissPictureBuffer(PP_Resource decoder, |
69 int32_t picture_buffer_id); | 85 int32_t picture_buffer_id); |
70 virtual void PictureReady(PP_Resource decoder, const PP_Picture_Dev& picture); | 86 virtual void PictureReady(PP_Resource decoder, const PP_Picture_Dev& picture); |
71 virtual void NotifyError(PP_Resource decoder, PP_VideoDecodeError_Dev error); | 87 virtual void NotifyError(PP_Resource decoder, PP_VideoDecodeError_Dev error); |
72 | 88 |
73 private: | 89 private: |
74 enum { kNumConcurrentDecodes = 7, | 90 enum { kNumConcurrentDecodes = 1, |
75 kNumDecoders = 2 }; // Baked into viewport rendering. | 91 kNumDecoders = 1 }; // Baked into viewport rendering. |
Ami GONE FROM CHROMIUM
2012/05/19 20:46:12
Why these two changes?
Both of these are >1 to dem
sail
2012/05/29 04:21:28
Ooops, reverted.
| |
76 | 92 |
77 // A single decoder's client interface. | 93 // A single decoder's client interface. |
78 class DecoderClient { | 94 class DecoderClient { |
79 public: | 95 public: |
80 DecoderClient(VideoDecodeDemoInstance* gles2, | 96 DecoderClient(VideoDecodeDemoInstance* gles2, |
81 pp::VideoDecoder_Dev* decoder); | 97 pp::VideoDecoder_Dev* decoder); |
82 ~DecoderClient(); | 98 ~DecoderClient(); |
83 | 99 |
84 void DecodeNextNALUs(); | 100 void DecodeNextNALUs(); |
85 | 101 |
86 // Per-decoder implementation of part of pp::VideoDecoderClient_Dev. | 102 // Per-decoder implementation of part of pp::VideoDecoderClient_Dev. |
87 void ProvidePictureBuffers( | 103 void ProvidePictureBuffers( |
88 uint32_t req_num_of_bufs, | 104 uint32_t req_num_of_bufs, |
89 PP_Size dimensions, | 105 PP_Size dimensions, |
90 PP_VideoDecoder_TextureTarget_Dev texture_target); | 106 PP_VideoDecoder_TextureTarget_Dev texture_target); |
91 void DismissPictureBuffer(int32_t picture_buffer_id); | 107 void DismissPictureBuffer(int32_t picture_buffer_id); |
92 | 108 |
93 const PP_PictureBuffer_Dev& GetPictureBufferById(int id); | 109 const PictureBufferInfo& GetPictureBufferInfoById(int id); |
94 pp::VideoDecoder_Dev* decoder() { return decoder_; } | 110 pp::VideoDecoder_Dev* decoder() { return decoder_; } |
95 | 111 |
96 private: | 112 private: |
97 void DecodeNextNALU(); | 113 void DecodeNextNALU(); |
98 static void GetNextNALUBoundary(size_t start_pos, size_t* end_pos); | 114 static void GetNextNALUBoundary(size_t start_pos, size_t* end_pos); |
99 void DecoderBitstreamDone(int32_t result, int bitstream_buffer_id); | 115 void DecoderBitstreamDone(int32_t result, int bitstream_buffer_id); |
100 void DecoderFlushDone(int32_t result); | 116 void DecoderFlushDone(int32_t result); |
101 | 117 |
102 VideoDecodeDemoInstance* gles2_; | 118 VideoDecodeDemoInstance* gles2_; |
103 pp::VideoDecoder_Dev* decoder_; | 119 pp::VideoDecoder_Dev* decoder_; |
104 pp::CompletionCallbackFactory<DecoderClient> callback_factory_; | 120 pp::CompletionCallbackFactory<DecoderClient> callback_factory_; |
105 int next_picture_buffer_id_; | 121 int next_picture_buffer_id_; |
106 int next_bitstream_buffer_id_; | 122 int next_bitstream_buffer_id_; |
107 size_t encoded_data_next_pos_to_decode_; | 123 size_t encoded_data_next_pos_to_decode_; |
108 std::set<int> bitstream_ids_at_decoder_; | 124 std::set<int> bitstream_ids_at_decoder_; |
109 // Map of texture buffers indexed by buffer id. | 125 // Map of texture buffers indexed by buffer id. |
110 typedef std::map<int, PP_PictureBuffer_Dev> PictureBufferMap; | 126 typedef std::map<int, PictureBufferInfo> PictureBufferMap; |
111 PictureBufferMap picture_buffers_by_id_; | 127 PictureBufferMap picture_buffers_by_id_; |
112 // Map of bitstream buffers indexed by id. | 128 // Map of bitstream buffers indexed by id. |
113 typedef std::map<int, pp::Buffer_Dev*> BitstreamBufferMap; | 129 typedef std::map<int, pp::Buffer_Dev*> BitstreamBufferMap; |
114 BitstreamBufferMap bitstream_buffers_by_id_; | 130 BitstreamBufferMap bitstream_buffers_by_id_; |
115 }; | 131 }; |
116 | 132 |
117 // Initialize Video Decoders. | 133 // Initialize Video Decoders. |
118 void InitializeDecoders(); | 134 void InitializeDecoders(); |
119 | 135 |
120 // GL-related functions. | 136 // GL-related functions. |
121 void InitGL(); | 137 void InitGL(); |
122 GLuint CreateTexture(int32_t width, int32_t height); | 138 GLuint CreateTexture(int32_t width, int32_t height, GLenum texture_target); |
123 void CreateGLObjects(); | 139 void CreateGLObjects(); |
140 Shader CreateProgram(const char* vertex_shader, | |
141 const char* fragment_shader); | |
124 void CreateShader(GLuint program, GLenum type, const char* source, int size); | 142 void CreateShader(GLuint program, GLenum type, const char* source, int size); |
125 void DeleteTexture(GLuint id); | 143 void DeleteTexture(GLuint id); |
126 void PaintFinished(int32_t result, PP_Resource decoder, | 144 void PaintFinished(int32_t result, PP_Resource decoder, |
127 int picture_buffer_id); | 145 int picture_buffer_id); |
128 | 146 |
129 // Log an error to the developer console and stderr (though the latter may be | 147 // Log an error to the developer console and stderr (though the latter may be |
130 // closed due to sandboxing or blackholed for other reasons) by creating a | 148 // closed due to sandboxing or blackholed for other reasons) by creating a |
131 // temporary of this type and streaming to it. Example usage: | 149 // temporary of this type and streaming to it. Example usage: |
132 // LogError(this).s() << "Hello world: " << 42; | 150 // LogError(this).s() << "Hello world: " << 42; |
133 class LogError { | 151 class LogError { |
(...skipping 27 matching lines...) Expand all Loading... | |
161 | 179 |
162 // Unowned pointers. | 180 // Unowned pointers. |
163 const PPB_Console_Dev* console_if_; | 181 const PPB_Console_Dev* console_if_; |
164 const PPB_Core* core_if_; | 182 const PPB_Core* core_if_; |
165 const PPB_OpenGLES2* gles2_if_; | 183 const PPB_OpenGLES2* gles2_if_; |
166 | 184 |
167 // Owned data. | 185 // Owned data. |
168 pp::Graphics3D* context_; | 186 pp::Graphics3D* context_; |
169 typedef std::map<int, DecoderClient*> Decoders; | 187 typedef std::map<int, DecoderClient*> Decoders; |
170 Decoders video_decoders_; | 188 Decoders video_decoders_; |
189 | |
190 // Shader program to draw GL_TEXTURE_2D target. | |
191 Shader shader_2d_; | |
192 // Shader program to draw GL_TEXTURE_RECTANGLE_ARB target. | |
193 Shader shader_rectangle_arb_; | |
171 }; | 194 }; |
172 | 195 |
196 GLenum ToGLTextureTarget(PP_VideoDecoder_TextureTarget_Dev texture_target) { | |
197 switch (texture_target) { | |
198 case PP_VIDEODECODER_TEXTURE_TARGET_2D: | |
199 return GL_TEXTURE_2D; | |
200 case PP_VIDEODECODER_TEXTURE_TARGET_ARB: | |
201 return GL_TEXTURE_RECTANGLE_ARB; | |
202 default: | |
203 assert(false); | |
Ami GONE FROM CHROMIUM
2012/05/19 20:46:12
s/assert(false)/NOTREACHED()/
sail
2012/05/29 04:21:28
This code base uses assert instead of NOTREACHED()
| |
204 return GL_TEXTURE_2D; | |
205 } | |
206 } | |
207 | |
173 VideoDecodeDemoInstance::DecoderClient::DecoderClient( | 208 VideoDecodeDemoInstance::DecoderClient::DecoderClient( |
174 VideoDecodeDemoInstance* gles2, pp::VideoDecoder_Dev* decoder) | 209 VideoDecodeDemoInstance* gles2, pp::VideoDecoder_Dev* decoder) |
175 : gles2_(gles2), decoder_(decoder), callback_factory_(this), | 210 : gles2_(gles2), decoder_(decoder), callback_factory_(this), |
176 next_picture_buffer_id_(0), | 211 next_picture_buffer_id_(0), |
177 next_bitstream_buffer_id_(0), encoded_data_next_pos_to_decode_(0) { | 212 next_bitstream_buffer_id_(0), encoded_data_next_pos_to_decode_(0) { |
178 } | 213 } |
179 | 214 |
180 VideoDecodeDemoInstance::DecoderClient::~DecoderClient() { | 215 VideoDecodeDemoInstance::DecoderClient::~DecoderClient() { |
181 delete decoder_; | 216 delete decoder_; |
182 decoder_ = NULL; | 217 decoder_ = NULL; |
183 | 218 |
184 for (BitstreamBufferMap::iterator it = bitstream_buffers_by_id_.begin(); | 219 for (BitstreamBufferMap::iterator it = bitstream_buffers_by_id_.begin(); |
185 it != bitstream_buffers_by_id_.end(); ++it) { | 220 it != bitstream_buffers_by_id_.end(); ++it) { |
186 delete it->second; | 221 delete it->second; |
187 } | 222 } |
188 bitstream_buffers_by_id_.clear(); | 223 bitstream_buffers_by_id_.clear(); |
189 | 224 |
190 for (PictureBufferMap::iterator it = picture_buffers_by_id_.begin(); | 225 for (PictureBufferMap::iterator it = picture_buffers_by_id_.begin(); |
191 it != picture_buffers_by_id_.end(); ++it) { | 226 it != picture_buffers_by_id_.end(); ++it) { |
192 gles2_->DeleteTexture(it->second.texture_id); | 227 gles2_->DeleteTexture(it->second.buffer.texture_id); |
193 } | 228 } |
194 picture_buffers_by_id_.clear(); | 229 picture_buffers_by_id_.clear(); |
195 } | 230 } |
196 | 231 |
197 VideoDecodeDemoInstance::VideoDecodeDemoInstance(PP_Instance instance, | 232 VideoDecodeDemoInstance::VideoDecodeDemoInstance(PP_Instance instance, |
198 pp::Module* module) | 233 pp::Module* module) |
199 : pp::Instance(instance), pp::Graphics3DClient(this), | 234 : pp::Instance(instance), pp::Graphics3DClient(this), |
200 pp::VideoDecoderClient_Dev(this), | 235 pp::VideoDecoderClient_Dev(this), |
201 num_frames_rendered_(0), | 236 num_frames_rendered_(0), |
202 first_frame_delivered_ticks_(-1), | 237 first_frame_delivered_ticks_(-1), |
203 swap_ticks_(0), | 238 swap_ticks_(0), |
204 callback_factory_(this), | 239 callback_factory_(this), |
205 context_(NULL) { | 240 context_(NULL) { |
206 assert((console_if_ = static_cast<const PPB_Console_Dev*>( | 241 assert((console_if_ = static_cast<const PPB_Console_Dev*>( |
207 module->GetBrowserInterface(PPB_CONSOLE_DEV_INTERFACE)))); | 242 module->GetBrowserInterface(PPB_CONSOLE_DEV_INTERFACE)))); |
208 assert((core_if_ = static_cast<const PPB_Core*>( | 243 assert((core_if_ = static_cast<const PPB_Core*>( |
209 module->GetBrowserInterface(PPB_CORE_INTERFACE)))); | 244 module->GetBrowserInterface(PPB_CORE_INTERFACE)))); |
210 assert((gles2_if_ = static_cast<const PPB_OpenGLES2*>( | 245 assert((gles2_if_ = static_cast<const PPB_OpenGLES2*>( |
211 module->GetBrowserInterface(PPB_OPENGLES2_INTERFACE)))); | 246 module->GetBrowserInterface(PPB_OPENGLES2_INTERFACE)))); |
212 } | 247 } |
213 | 248 |
214 VideoDecodeDemoInstance::~VideoDecodeDemoInstance() { | 249 VideoDecodeDemoInstance::~VideoDecodeDemoInstance() { |
250 if (shader_2d_.program) | |
251 gles2_if_->DeleteProgram(context_->pp_resource(), shader_2d_.program); | |
252 if (shader_rectangle_arb_.program) { | |
253 gles2_if_->DeleteProgram( | |
254 context_->pp_resource(), shader_rectangle_arb_.program); | |
255 } | |
256 | |
215 for (Decoders::iterator it = video_decoders_.begin(); | 257 for (Decoders::iterator it = video_decoders_.begin(); |
216 it != video_decoders_.end(); ++it) { | 258 it != video_decoders_.end(); ++it) { |
217 delete it->second; | 259 delete it->second; |
218 } | 260 } |
219 video_decoders_.clear(); | 261 video_decoders_.clear(); |
220 delete context_; | 262 delete context_; |
221 } | 263 } |
222 | 264 |
223 void VideoDecodeDemoInstance::DidChangeView( | 265 void VideoDecodeDemoInstance::DidChangeView( |
224 const pp::Rect& position, const pp::Rect& clip_ignored) { | 266 const pp::Rect& position, const pp::Rect& clip_ignored) { |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
333 PP_VideoDecoder_TextureTarget_Dev texture_target) { | 375 PP_VideoDecoder_TextureTarget_Dev texture_target) { |
334 DecoderClient* client = video_decoders_[decoder]; | 376 DecoderClient* client = video_decoders_[decoder]; |
335 assert(client); | 377 assert(client); |
336 client->ProvidePictureBuffers(req_num_of_bufs, dimensions, texture_target); | 378 client->ProvidePictureBuffers(req_num_of_bufs, dimensions, texture_target); |
337 } | 379 } |
338 | 380 |
339 void VideoDecodeDemoInstance::DecoderClient::ProvidePictureBuffers( | 381 void VideoDecodeDemoInstance::DecoderClient::ProvidePictureBuffers( |
340 uint32_t req_num_of_bufs, | 382 uint32_t req_num_of_bufs, |
341 PP_Size dimensions, | 383 PP_Size dimensions, |
342 PP_VideoDecoder_TextureTarget_Dev texture_target) { | 384 PP_VideoDecoder_TextureTarget_Dev texture_target) { |
343 // TODO(sail): Add support for ARB texture types. | |
344 assert(texture_target == PP_VIDEODECODER_TEXTURE_TARGET_2D); | |
345 std::vector<PP_PictureBuffer_Dev> buffers; | 385 std::vector<PP_PictureBuffer_Dev> buffers; |
346 for (uint32_t i = 0; i < req_num_of_bufs; ++i) { | 386 for (uint32_t i = 0; i < req_num_of_bufs; ++i) { |
347 PP_PictureBuffer_Dev buffer; | 387 PictureBufferInfo info; |
348 buffer.size = dimensions; | 388 info.buffer.size = dimensions; |
349 buffer.texture_id = | 389 info.texture_target = ToGLTextureTarget(texture_target); |
350 gles2_->CreateTexture(dimensions.width, dimensions.height); | 390 info.buffer.texture_id = gles2_->CreateTexture( |
391 dimensions.width, dimensions.height, info.texture_target); | |
351 int id = ++next_picture_buffer_id_; | 392 int id = ++next_picture_buffer_id_; |
352 buffer.id = id; | 393 info.buffer.id = id; |
353 buffers.push_back(buffer); | 394 buffers.push_back(info.buffer); |
354 assert(picture_buffers_by_id_.insert(std::make_pair(id, buffer)).second); | 395 assert(picture_buffers_by_id_.insert(std::make_pair(id, info)).second); |
355 } | 396 } |
356 decoder_->AssignPictureBuffers(buffers); | 397 decoder_->AssignPictureBuffers(buffers); |
357 } | 398 } |
358 | 399 |
359 const PP_PictureBuffer_Dev& | 400 const PictureBufferInfo& |
360 VideoDecodeDemoInstance::DecoderClient::GetPictureBufferById( | 401 VideoDecodeDemoInstance::DecoderClient::GetPictureBufferInfoById( |
361 int id) { | 402 int id) { |
362 PictureBufferMap::iterator it = picture_buffers_by_id_.find(id); | 403 PictureBufferMap::iterator it = picture_buffers_by_id_.find(id); |
363 assert(it != picture_buffers_by_id_.end()); | 404 assert(it != picture_buffers_by_id_.end()); |
364 return it->second; | 405 return it->second; |
365 } | 406 } |
366 | 407 |
367 void VideoDecodeDemoInstance::DismissPictureBuffer(PP_Resource decoder, | 408 void VideoDecodeDemoInstance::DismissPictureBuffer(PP_Resource decoder, |
368 int32_t picture_buffer_id) { | 409 int32_t picture_buffer_id) { |
369 DecoderClient* client = video_decoders_[decoder]; | 410 DecoderClient* client = video_decoders_[decoder]; |
370 assert(client); | 411 assert(client); |
371 client->DismissPictureBuffer(picture_buffer_id); | 412 client->DismissPictureBuffer(picture_buffer_id); |
372 } | 413 } |
373 | 414 |
374 void VideoDecodeDemoInstance::DecoderClient::DismissPictureBuffer( | 415 void VideoDecodeDemoInstance::DecoderClient::DismissPictureBuffer( |
375 int32_t picture_buffer_id) { | 416 int32_t picture_buffer_id) { |
376 gles2_->DeleteTexture(GetPictureBufferById(picture_buffer_id).texture_id); | 417 gles2_->DeleteTexture(GetPictureBufferInfoById( |
418 picture_buffer_id).buffer.texture_id); | |
377 picture_buffers_by_id_.erase(picture_buffer_id); | 419 picture_buffers_by_id_.erase(picture_buffer_id); |
378 } | 420 } |
379 | 421 |
380 void VideoDecodeDemoInstance::PictureReady(PP_Resource decoder, | 422 void VideoDecodeDemoInstance::PictureReady(PP_Resource decoder, |
381 const PP_Picture_Dev& picture) { | 423 const PP_Picture_Dev& picture) { |
382 if (first_frame_delivered_ticks_ == -1) | 424 if (first_frame_delivered_ticks_ == -1) |
383 assert((first_frame_delivered_ticks_ = core_if_->GetTimeTicks()) != -1); | 425 assert((first_frame_delivered_ticks_ = core_if_->GetTimeTicks()) != -1); |
384 if (is_painting_) { | 426 if (is_painting_) { |
385 pictures_pending_paint_.push_back(std::make_pair(decoder, picture)); | 427 pictures_pending_paint_.push_back(std::make_pair(decoder, picture)); |
386 return; | 428 return; |
387 } | 429 } |
388 DecoderClient* client = video_decoders_[decoder]; | 430 DecoderClient* client = video_decoders_[decoder]; |
389 assert(client); | 431 assert(client); |
390 const PP_PictureBuffer_Dev& buffer = | 432 const PictureBufferInfo& info = |
391 client->GetPictureBufferById(picture.picture_buffer_id); | 433 client->GetPictureBufferInfoById(picture.picture_buffer_id); |
392 assert(!is_painting_); | 434 assert(!is_painting_); |
393 is_painting_ = true; | 435 is_painting_ = true; |
394 int x = 0; | 436 int x = 0; |
395 int y = 0; | 437 int y = 0; |
396 if (client != video_decoders_.begin()->second) { | 438 if (client != video_decoders_.begin()->second) { |
397 x = plugin_size_.width() / kNumDecoders; | 439 x = plugin_size_.width() / kNumDecoders; |
398 y = plugin_size_.height() / kNumDecoders; | 440 y = plugin_size_.height() / kNumDecoders; |
399 } | 441 } |
400 | 442 |
443 if (info.texture_target == GL_TEXTURE_2D) { | |
444 gles2_if_->UseProgram(context_->pp_resource(), shader_2d_.program); | |
445 gles2_if_->Uniform2f( | |
446 context_->pp_resource(), shader_2d_.texcoord_scale_location, 1.0, 1.0); | |
447 gles2_if_->Uniform2f( | |
448 context_->pp_resource(), shader_2d_.texcoord_offset_location, 0.0, 0.0); | |
449 } else { | |
450 assert(info.texture_target == GL_TEXTURE_RECTANGLE_ARB); | |
451 gles2_if_->UseProgram( | |
452 context_->pp_resource(), shader_rectangle_arb_.program); | |
453 // The video frame is upside down so scale it by -1 and offset it by the | |
454 // frame height. | |
455 gles2_if_->Uniform2f(context_->pp_resource(), | |
456 shader_rectangle_arb_.texcoord_scale_location, | |
457 info.buffer.size.width, | |
458 info.buffer.size.height * -1.0); | |
459 gles2_if_->Uniform2f(context_->pp_resource(), | |
460 shader_rectangle_arb_.texcoord_offset_location, | |
461 0.0, | |
462 info.buffer.size.height); | |
463 } | |
464 | |
401 gles2_if_->Viewport(context_->pp_resource(), x, y, | 465 gles2_if_->Viewport(context_->pp_resource(), x, y, |
402 plugin_size_.width() / kNumDecoders, | 466 plugin_size_.width() / kNumDecoders, |
403 plugin_size_.height() / kNumDecoders); | 467 plugin_size_.height() / kNumDecoders); |
404 gles2_if_->ActiveTexture(context_->pp_resource(), GL_TEXTURE0); | 468 gles2_if_->ActiveTexture(context_->pp_resource(), GL_TEXTURE0); |
405 gles2_if_->BindTexture( | 469 gles2_if_->BindTexture( |
406 context_->pp_resource(), GL_TEXTURE_2D, buffer.texture_id); | 470 context_->pp_resource(), info.texture_target, info.buffer.texture_id); |
407 gles2_if_->DrawArrays(context_->pp_resource(), GL_TRIANGLE_STRIP, 0, 4); | 471 gles2_if_->DrawArrays(context_->pp_resource(), GL_TRIANGLE_STRIP, 0, 4); |
472 | |
473 gles2_if_->UseProgram(context_->pp_resource(), 0); | |
474 | |
408 pp::CompletionCallback cb = | 475 pp::CompletionCallback cb = |
409 callback_factory_.NewCallback( | 476 callback_factory_.NewCallback( |
410 &VideoDecodeDemoInstance::PaintFinished, decoder, buffer.id); | 477 &VideoDecodeDemoInstance::PaintFinished, decoder, info.buffer.id); |
411 last_swap_request_ticks_ = core_if_->GetTimeTicks(); | 478 last_swap_request_ticks_ = core_if_->GetTimeTicks(); |
412 assert(context_->SwapBuffers(cb) == PP_OK_COMPLETIONPENDING); | 479 assert(context_->SwapBuffers(cb) == PP_OK_COMPLETIONPENDING); |
413 } | 480 } |
414 | 481 |
415 void VideoDecodeDemoInstance::NotifyError(PP_Resource decoder, | 482 void VideoDecodeDemoInstance::NotifyError(PP_Resource decoder, |
416 PP_VideoDecodeError_Dev error) { | 483 PP_VideoDecodeError_Dev error) { |
417 LogError(this).s() << "Received error: " << error; | 484 LogError(this).s() << "Received error: " << error; |
418 assert(!"Unexpected error; see stderr for details"); | 485 assert(!"Unexpected error; see stderr for details"); |
419 } | 486 } |
420 | 487 |
(...skipping 25 matching lines...) Expand all Loading... | |
446 PP_GRAPHICS3DATTRIB_SAMPLE_BUFFERS, 0, | 513 PP_GRAPHICS3DATTRIB_SAMPLE_BUFFERS, 0, |
447 PP_GRAPHICS3DATTRIB_WIDTH, plugin_size_.width(), | 514 PP_GRAPHICS3DATTRIB_WIDTH, plugin_size_.width(), |
448 PP_GRAPHICS3DATTRIB_HEIGHT, plugin_size_.height(), | 515 PP_GRAPHICS3DATTRIB_HEIGHT, plugin_size_.height(), |
449 PP_GRAPHICS3DATTRIB_NONE, | 516 PP_GRAPHICS3DATTRIB_NONE, |
450 }; | 517 }; |
451 context_ = new pp::Graphics3D(this, context_attributes); | 518 context_ = new pp::Graphics3D(this, context_attributes); |
452 assert(!context_->is_null()); | 519 assert(!context_->is_null()); |
453 assert(BindGraphics(*context_)); | 520 assert(BindGraphics(*context_)); |
454 | 521 |
455 // Clear color bit. | 522 // Clear color bit. |
456 gles2_if_->ClearColor(context_->pp_resource(), 1, 0, 0, 1); | 523 gles2_if_->ClearColor(context_->pp_resource(), 1, 1, 0, 1); |
Ami GONE FROM CHROMIUM
2012/05/19 20:46:12
why?
sail
2012/05/29 04:21:28
Argh, more testing code. Reverted.
| |
457 gles2_if_->Clear(context_->pp_resource(), GL_COLOR_BUFFER_BIT); | 524 gles2_if_->Clear(context_->pp_resource(), GL_COLOR_BUFFER_BIT); |
458 | 525 |
459 assertNoGLError(); | 526 assertNoGLError(); |
460 | 527 |
461 CreateGLObjects(); | 528 CreateGLObjects(); |
462 } | 529 } |
463 | 530 |
464 void VideoDecodeDemoInstance::PaintFinished(int32_t result, PP_Resource decoder, | 531 void VideoDecodeDemoInstance::PaintFinished(int32_t result, PP_Resource decoder, |
465 int picture_buffer_id) { | 532 int picture_buffer_id) { |
466 assert(result == PP_OK); | 533 assert(result == PP_OK); |
(...skipping 12 matching lines...) Expand all Loading... | |
479 if (client && client->decoder()) | 546 if (client && client->decoder()) |
480 client->decoder()->ReusePictureBuffer(picture_buffer_id); | 547 client->decoder()->ReusePictureBuffer(picture_buffer_id); |
481 if (!pictures_pending_paint_.empty()) { | 548 if (!pictures_pending_paint_.empty()) { |
482 std::pair<PP_Resource, PP_Picture_Dev> decoder_picture = | 549 std::pair<PP_Resource, PP_Picture_Dev> decoder_picture = |
483 pictures_pending_paint_.front(); | 550 pictures_pending_paint_.front(); |
484 pictures_pending_paint_.pop_front(); | 551 pictures_pending_paint_.pop_front(); |
485 PictureReady(decoder_picture.first, decoder_picture.second); | 552 PictureReady(decoder_picture.first, decoder_picture.second); |
486 } | 553 } |
487 } | 554 } |
488 | 555 |
489 GLuint VideoDecodeDemoInstance::CreateTexture(int32_t width, int32_t height) { | 556 GLuint VideoDecodeDemoInstance::CreateTexture(int32_t width, |
557 int32_t height, | |
558 GLenum texture_target) { | |
490 GLuint texture_id; | 559 GLuint texture_id; |
491 gles2_if_->GenTextures(context_->pp_resource(), 1, &texture_id); | 560 gles2_if_->GenTextures(context_->pp_resource(), 1, &texture_id); |
492 assertNoGLError(); | 561 assertNoGLError(); |
493 // Assign parameters. | 562 // Assign parameters. |
494 gles2_if_->ActiveTexture(context_->pp_resource(), GL_TEXTURE0); | 563 gles2_if_->ActiveTexture(context_->pp_resource(), GL_TEXTURE0); |
495 gles2_if_->BindTexture(context_->pp_resource(), GL_TEXTURE_2D, texture_id); | 564 gles2_if_->BindTexture(context_->pp_resource(), texture_target, texture_id); |
496 gles2_if_->TexParameteri( | 565 gles2_if_->TexParameteri( |
497 context_->pp_resource(), GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, | 566 context_->pp_resource(), texture_target, GL_TEXTURE_MIN_FILTER, |
498 GL_NEAREST); | 567 GL_NEAREST); |
499 gles2_if_->TexParameteri( | 568 gles2_if_->TexParameteri( |
500 context_->pp_resource(), GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, | 569 context_->pp_resource(), texture_target, GL_TEXTURE_MAG_FILTER, |
501 GL_NEAREST); | 570 GL_NEAREST); |
502 gles2_if_->TexParameterf( | 571 gles2_if_->TexParameterf( |
503 context_->pp_resource(), GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, | 572 context_->pp_resource(), texture_target, GL_TEXTURE_WRAP_S, |
504 GL_CLAMP_TO_EDGE); | 573 GL_CLAMP_TO_EDGE); |
505 gles2_if_->TexParameterf( | 574 gles2_if_->TexParameterf( |
506 context_->pp_resource(), GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, | 575 context_->pp_resource(), texture_target, GL_TEXTURE_WRAP_T, |
507 GL_CLAMP_TO_EDGE); | 576 GL_CLAMP_TO_EDGE); |
508 | 577 |
509 gles2_if_->TexImage2D( | 578 if (texture_target == GL_TEXTURE_2D) { |
510 context_->pp_resource(), GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, | 579 gles2_if_->TexImage2D( |
511 GL_RGBA, GL_UNSIGNED_BYTE, NULL); | 580 context_->pp_resource(), texture_target, 0, GL_RGBA, width, height, 0, |
581 GL_RGBA, GL_UNSIGNED_BYTE, NULL); | |
582 } | |
512 assertNoGLError(); | 583 assertNoGLError(); |
513 return texture_id; | 584 return texture_id; |
514 } | 585 } |
515 | 586 |
516 void VideoDecodeDemoInstance::DeleteTexture(GLuint id) { | 587 void VideoDecodeDemoInstance::DeleteTexture(GLuint id) { |
517 gles2_if_->DeleteTextures(context_->pp_resource(), 1, &id); | 588 gles2_if_->DeleteTextures(context_->pp_resource(), 1, &id); |
518 } | 589 } |
519 | 590 |
520 void VideoDecodeDemoInstance::CreateGLObjects() { | 591 void VideoDecodeDemoInstance::CreateGLObjects() { |
521 // Code and constants for shader. | 592 // Code and constants for shader. |
522 static const char kVertexShader[] = | 593 static const char kVertexShaderRectangle[] = |
523 "varying vec2 v_texCoord; \n" | 594 "varying vec2 v_texCoord; \n" |
524 "attribute vec4 a_position; \n" | 595 "attribute vec4 a_position; \n" |
525 "attribute vec2 a_texCoord; \n" | 596 "attribute vec2 a_texCoord; \n" |
597 "uniform vec2 v_scale; \n" | |
598 "uniform vec2 v_offset; \n" | |
526 "void main() \n" | 599 "void main() \n" |
527 "{ \n" | 600 "{ \n" |
528 " v_texCoord = a_texCoord; \n" | 601 " v_texCoord = v_scale * a_texCoord + v_offset; \n" |
529 " gl_Position = a_position; \n" | 602 " gl_Position = a_position; \n" |
530 "}"; | 603 "}"; |
531 | 604 |
532 static const char kFragmentShader[] = | 605 static const char kFragmentShader2D[] = |
533 "precision mediump float; \n" | 606 "precision mediump float; \n" |
534 "varying vec2 v_texCoord; \n" | 607 "varying vec2 v_texCoord; \n" |
535 "uniform sampler2D s_texture; \n" | 608 "uniform sampler2D s_texture; \n" |
536 "void main() \n" | 609 "void main() \n" |
537 "{" | 610 "{" |
538 " gl_FragColor = texture2D(s_texture, v_texCoord); \n" | 611 " gl_FragColor = texture2D(s_texture, v_texCoord); \n" |
539 "}"; | 612 "}"; |
540 | 613 |
541 // Create shader program. | 614 static const char kFragmentShaderRectangle[] = |
542 GLuint program = gles2_if_->CreateProgram(context_->pp_resource()); | 615 "#extension GL_ARB_texture_rectangle : require\n" |
543 CreateShader(program, GL_VERTEX_SHADER, kVertexShader, sizeof(kVertexShader)); | 616 "precision mediump float; \n" |
544 CreateShader( | 617 "varying vec2 v_texCoord; \n" |
545 program, GL_FRAGMENT_SHADER, kFragmentShader, sizeof(kFragmentShader)); | 618 "uniform sampler2DRect s_texture; \n" |
546 gles2_if_->LinkProgram(context_->pp_resource(), program); | 619 "void main() \n" |
547 gles2_if_->UseProgram(context_->pp_resource(), program); | 620 "{" |
548 gles2_if_->DeleteProgram(context_->pp_resource(), program); | 621 " gl_FragColor = texture2DRect(s_texture, v_texCoord).rgba; \n" |
549 gles2_if_->Uniform1i( | 622 "}"; |
550 context_->pp_resource(), | |
551 gles2_if_->GetUniformLocation( | |
552 context_->pp_resource(), program, "s_texture"), 0); | |
553 assertNoGLError(); | |
554 | 623 |
555 // Assign vertex positions and texture coordinates to buffers for use in | 624 // Assign vertex positions and texture coordinates to buffers for use in |
556 // shader program. | 625 // shader program. |
557 static const float kVertices[] = { | 626 static const float kVertices[] = { |
558 -1, 1, -1, -1, 1, 1, 1, -1, // Position coordinates. | 627 -1, 1, -1, -1, 1, 1, 1, -1, // Position coordinates. |
559 0, 1, 0, 0, 1, 1, 1, 0, // Texture coordinates. | 628 0, 1, 0, 0, 1, 1, 1, 0, // Texture coordinates. |
560 }; | 629 }; |
561 | 630 |
562 GLuint buffer; | 631 GLuint buffer; |
563 gles2_if_->GenBuffers(context_->pp_resource(), 1, &buffer); | 632 gles2_if_->GenBuffers(context_->pp_resource(), 1, &buffer); |
564 gles2_if_->BindBuffer(context_->pp_resource(), GL_ARRAY_BUFFER, buffer); | 633 gles2_if_->BindBuffer(context_->pp_resource(), GL_ARRAY_BUFFER, buffer); |
634 | |
565 gles2_if_->BufferData(context_->pp_resource(), GL_ARRAY_BUFFER, | 635 gles2_if_->BufferData(context_->pp_resource(), GL_ARRAY_BUFFER, |
566 sizeof(kVertices), kVertices, GL_STATIC_DRAW); | 636 sizeof(kVertices), kVertices, GL_STATIC_DRAW); |
567 assertNoGLError(); | 637 assertNoGLError(); |
638 | |
639 shader_2d_ = CreateProgram(kVertexShaderRectangle, kFragmentShader2D); | |
640 shader_rectangle_arb_ = | |
641 CreateProgram(kVertexShaderRectangle, kFragmentShaderRectangle); | |
642 } | |
643 | |
644 Shader VideoDecodeDemoInstance::CreateProgram(const char* vertex_shader, | |
645 const char* fragment_shader) { | |
646 Shader shader; | |
647 | |
648 // Create shader program. | |
649 shader.program = gles2_if_->CreateProgram(context_->pp_resource()); | |
650 CreateShader(shader.program, GL_VERTEX_SHADER, vertex_shader, | |
651 strlen(vertex_shader)); | |
652 CreateShader(shader.program, GL_FRAGMENT_SHADER, fragment_shader, | |
653 strlen(fragment_shader)); | |
654 gles2_if_->LinkProgram(context_->pp_resource(), shader.program); | |
655 gles2_if_->UseProgram(context_->pp_resource(), shader.program); | |
656 gles2_if_->Uniform1i( | |
657 context_->pp_resource(), | |
658 gles2_if_->GetUniformLocation( | |
659 context_->pp_resource(), shader.program, "s_texture"), 0); | |
660 assertNoGLError(); | |
661 | |
662 shader.texcoord_scale_location = gles2_if_->GetUniformLocation( | |
663 context_->pp_resource(), shader.program, "v_scale"); | |
664 shader.texcoord_offset_location = gles2_if_->GetUniformLocation( | |
665 context_->pp_resource(), shader.program, "v_offset"); | |
666 | |
568 GLint pos_location = gles2_if_->GetAttribLocation( | 667 GLint pos_location = gles2_if_->GetAttribLocation( |
569 context_->pp_resource(), program, "a_position"); | 668 context_->pp_resource(), shader.program, "a_position"); |
570 GLint tc_location = gles2_if_->GetAttribLocation( | 669 GLint tc_location = gles2_if_->GetAttribLocation( |
571 context_->pp_resource(), program, "a_texCoord"); | 670 context_->pp_resource(), shader.program, "a_texCoord"); |
572 assertNoGLError(); | 671 assertNoGLError(); |
672 | |
573 gles2_if_->EnableVertexAttribArray(context_->pp_resource(), pos_location); | 673 gles2_if_->EnableVertexAttribArray(context_->pp_resource(), pos_location); |
574 gles2_if_->VertexAttribPointer(context_->pp_resource(), pos_location, 2, | 674 gles2_if_->VertexAttribPointer(context_->pp_resource(), pos_location, 2, |
575 GL_FLOAT, GL_FALSE, 0, 0); | 675 GL_FLOAT, GL_FALSE, 0, 0); |
576 gles2_if_->EnableVertexAttribArray(context_->pp_resource(), tc_location); | 676 gles2_if_->EnableVertexAttribArray(context_->pp_resource(), tc_location); |
577 gles2_if_->VertexAttribPointer( | 677 gles2_if_->VertexAttribPointer( |
578 context_->pp_resource(), tc_location, 2, GL_FLOAT, GL_FALSE, 0, | 678 context_->pp_resource(), tc_location, 2, GL_FLOAT, GL_FALSE, 0, |
579 static_cast<float*>(0) + 8); // Skip position coordinates. | 679 static_cast<float*>(0) + 8); // Skip position coordinates. |
680 | |
681 gles2_if_->UseProgram(context_->pp_resource(), 0); | |
580 assertNoGLError(); | 682 assertNoGLError(); |
683 return shader; | |
581 } | 684 } |
582 | 685 |
583 void VideoDecodeDemoInstance::CreateShader( | 686 void VideoDecodeDemoInstance::CreateShader( |
584 GLuint program, GLenum type, const char* source, int size) { | 687 GLuint program, GLenum type, const char* source, int size) { |
585 GLuint shader = gles2_if_->CreateShader(context_->pp_resource(), type); | 688 GLuint shader = gles2_if_->CreateShader(context_->pp_resource(), type); |
586 gles2_if_->ShaderSource(context_->pp_resource(), shader, 1, &source, &size); | 689 gles2_if_->ShaderSource(context_->pp_resource(), shader, 1, &source, &size); |
587 gles2_if_->CompileShader(context_->pp_resource(), shader); | 690 gles2_if_->CompileShader(context_->pp_resource(), shader); |
588 gles2_if_->AttachShader(context_->pp_resource(), program, shader); | 691 gles2_if_->AttachShader(context_->pp_resource(), program, shader); |
589 gles2_if_->DeleteShader(context_->pp_resource(), shader); | 692 gles2_if_->DeleteShader(context_->pp_resource(), shader); |
590 } | 693 } |
591 } // anonymous namespace | 694 } // anonymous namespace |
592 | 695 |
593 namespace pp { | 696 namespace pp { |
594 // Factory function for your specialization of the Module object. | 697 // Factory function for your specialization of the Module object. |
595 Module* CreateModule() { | 698 Module* CreateModule() { |
596 return new VideoDecodeDemoModule(); | 699 return new VideoDecodeDemoModule(); |
597 } | 700 } |
598 } // namespace pp | 701 } // namespace pp |
OLD | NEW |