Revert of Set defaultPageScaleLimits before setIgnoreViewportTagScaleLimits (patchset...
[chromium-blink-merge.git] / media / filters / skcanvas_video_renderer.cc
blob9ad70bead595a12ed112120040a88a7580f758b0
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
3 // found in the LICENSE file.
5 #include "media/filters/skcanvas_video_renderer.h"
7 #include "gpu/GLES2/gl2extchromium.h"
8 #include "gpu/command_buffer/client/gles2_interface.h"
9 #include "gpu/command_buffer/common/mailbox_holder.h"
10 #include "media/base/video_frame.h"
11 #include "media/base/yuv_convert.h"
12 #include "skia/ext/refptr.h"
13 #include "third_party/libyuv/include/libyuv.h"
14 #include "third_party/skia/include/core/SkCanvas.h"
15 #include "third_party/skia/include/core/SkImageGenerator.h"
16 #include "third_party/skia/include/gpu/GrContext.h"
17 #include "third_party/skia/include/gpu/SkGrPixelRef.h"
18 #include "ui/gfx/skbitmap_operations.h"
20 // Skia internal format depends on a platform. On Android it is ABGR, on others
21 // it is ARGB.
22 #if SK_B32_SHIFT == 0 && SK_G32_SHIFT == 8 && SK_R32_SHIFT == 16 && \
23 SK_A32_SHIFT == 24
24 #define LIBYUV_I420_TO_ARGB libyuv::I420ToARGB
25 #define LIBYUV_I422_TO_ARGB libyuv::I422ToARGB
26 #elif SK_R32_SHIFT == 0 && SK_G32_SHIFT == 8 && SK_B32_SHIFT == 16 && \
27 SK_A32_SHIFT == 24
28 #define LIBYUV_I420_TO_ARGB libyuv::I420ToABGR
29 #define LIBYUV_I422_TO_ARGB libyuv::I422ToABGR
30 #else
31 #error Unexpected Skia ARGB_8888 layout!
32 #endif
34 namespace media {
36 namespace {
38 // This class keeps two temporary resources; software bitmap, hardware bitmap.
39 // If both bitmap are created and then only software bitmap is updated every
40 // frame, hardware bitmap outlives until the media player dies. So we delete
41 // a temporary resource if it is not used for 3 sec.
42 const int kTemporaryResourceDeletionDelay = 3; // Seconds;
44 bool IsYUV(media::VideoFrame::Format format) {
45 switch (format) {
46 case VideoFrame::YV12:
47 case VideoFrame::YV16:
48 case VideoFrame::I420:
49 case VideoFrame::YV12A:
50 case VideoFrame::YV12J:
51 case VideoFrame::YV12HD:
52 case VideoFrame::YV24:
53 case VideoFrame::NV12:
54 return true;
55 case VideoFrame::UNKNOWN:
56 case VideoFrame::NATIVE_TEXTURE:
57 #if defined(VIDEO_HOLE)
58 case VideoFrame::HOLE:
59 #endif // defined(VIDEO_HOLE)
60 case VideoFrame::ARGB:
61 return false;
63 NOTREACHED() << "Invalid videoframe format provided: " << format;
64 return false;
67 bool IsJPEGColorSpace(media::VideoFrame::Format format) {
68 switch (format) {
69 case VideoFrame::YV12J:
70 return true;
71 case VideoFrame::YV12:
72 case VideoFrame::YV12HD:
73 case VideoFrame::YV16:
74 case VideoFrame::I420:
75 case VideoFrame::YV12A:
76 case VideoFrame::YV24:
77 case VideoFrame::NV12:
78 case VideoFrame::UNKNOWN:
79 case VideoFrame::NATIVE_TEXTURE:
80 #if defined(VIDEO_HOLE)
81 case VideoFrame::HOLE:
82 #endif // defined(VIDEO_HOLE)
83 case VideoFrame::ARGB:
84 return false;
86 NOTREACHED() << "Invalid videoframe format provided: " << format;
87 return false;
90 bool IsYUVOrNative(media::VideoFrame::Format format) {
91 return IsYUV(format) || format == media::VideoFrame::NATIVE_TEXTURE;
94 bool IsSkBitmapProperlySizedTexture(const SkBitmap* bitmap,
95 const gfx::Size& size) {
96 return bitmap->getTexture() && bitmap->width() == size.width() &&
97 bitmap->height() == size.height();
100 bool AllocateSkBitmapTexture(GrContext* gr,
101 SkBitmap* bitmap,
102 const gfx::Size& size) {
103 DCHECK(gr);
104 GrTextureDesc desc;
105 // Use kRGBA_8888_GrPixelConfig, not kSkia8888_GrPixelConfig, to avoid
106 // RGBA to BGRA conversion.
107 desc.fConfig = kRGBA_8888_GrPixelConfig;
108 desc.fFlags = kRenderTarget_GrTextureFlagBit | kNoStencil_GrTextureFlagBit;
109 desc.fSampleCnt = 0;
110 desc.fOrigin = kTopLeft_GrSurfaceOrigin;
111 desc.fWidth = size.width();
112 desc.fHeight = size.height();
113 skia::RefPtr<GrTexture> texture = skia::AdoptRef(
114 gr->refScratchTexture(desc, GrContext::kExact_ScratchTexMatch));
115 if (!texture.get())
116 return false;
118 SkImageInfo info = SkImageInfo::MakeN32Premul(desc.fWidth, desc.fHeight);
119 SkGrPixelRef* pixel_ref = SkNEW_ARGS(SkGrPixelRef, (info, texture.get()));
120 if (!pixel_ref)
121 return false;
122 bitmap->setInfo(info);
123 bitmap->setPixelRef(pixel_ref)->unref();
124 return true;
127 bool CopyVideoFrameTextureToSkBitmapTexture(VideoFrame* video_frame,
128 SkBitmap* bitmap,
129 const Context3D& context_3d) {
130 // Check if we could reuse existing texture based bitmap.
131 // Otherwise, release existing texture based bitmap and allocate
132 // a new one based on video size.
133 if (!IsSkBitmapProperlySizedTexture(bitmap,
134 video_frame->visible_rect().size())) {
135 if (!AllocateSkBitmapTexture(context_3d.gr_context, bitmap,
136 video_frame->visible_rect().size())) {
137 return false;
141 unsigned texture_id =
142 static_cast<unsigned>((bitmap->getTexture())->getTextureHandle());
143 // If CopyVideoFrameTextureToGLTexture() changes the state of the
144 // |texture_id|, it's needed to invalidate the state cached in skia,
145 // but currently the state isn't changed.
146 SkCanvasVideoRenderer::CopyVideoFrameTextureToGLTexture(
147 context_3d.gl, video_frame, texture_id, 0, GL_RGBA, GL_UNSIGNED_BYTE,
148 true, false);
149 return true;
152 class SyncPointClientImpl : public VideoFrame::SyncPointClient {
153 public:
154 explicit SyncPointClientImpl(gpu::gles2::GLES2Interface* gl) : gl_(gl) {}
155 ~SyncPointClientImpl() override {}
156 uint32 InsertSyncPoint() override { return gl_->InsertSyncPointCHROMIUM(); }
157 void WaitSyncPoint(uint32 sync_point) override {
158 gl_->WaitSyncPointCHROMIUM(sync_point);
161 private:
162 gpu::gles2::GLES2Interface* gl_;
164 DISALLOW_IMPLICIT_CONSTRUCTORS(SyncPointClientImpl);
167 } // anonymous namespace
169 // Generates an RGB image from a VideoFrame. Convert YUV to RGB plain on GPU.
170 class VideoImageGenerator : public SkImageGenerator {
171 public:
172 VideoImageGenerator(const scoped_refptr<VideoFrame>& frame) : frame_(frame) {
173 DCHECK(frame_.get());
175 ~VideoImageGenerator() override {}
177 void set_frame(const scoped_refptr<VideoFrame>& frame) { frame_ = frame; }
179 protected:
180 bool onGetInfo(SkImageInfo* info) override {
181 info->fWidth = frame_->visible_rect().width();
182 info->fHeight = frame_->visible_rect().height();
183 info->fColorType = kN32_SkColorType;
184 info->fAlphaType = kPremul_SkAlphaType;
185 return true;
188 bool onGetPixels(const SkImageInfo& info,
189 void* pixels,
190 size_t row_bytes,
191 SkPMColor ctable[],
192 int* ctable_count) override {
193 if (!frame_.get())
194 return false;
195 if (!pixels)
196 return false;
197 // If skia couldn't do the YUV conversion on GPU, we will on CPU.
198 SkCanvasVideoRenderer::ConvertVideoFrameToRGBPixels(
199 frame_, pixels, row_bytes);
200 return true;
203 bool onGetYUV8Planes(SkISize sizes[3],
204 void* planes[3],
205 size_t row_bytes[3],
206 SkYUVColorSpace* color_space) override {
207 if (!frame_.get() || !IsYUV(frame_->format()) ||
208 // TODO(rileya): Skia currently doesn't support Rec709 YUV conversion,
209 // Remove this case once it does. As-is we will fall back on the
210 // pure-software path in this case.
211 frame_->format() == VideoFrame::YV12HD) {
212 return false;
215 if (color_space) {
216 if (IsJPEGColorSpace(frame_->format()))
217 *color_space = kJPEG_SkYUVColorSpace;
218 else
219 *color_space = kRec601_SkYUVColorSpace;
222 for (int plane = VideoFrame::kYPlane; plane <= VideoFrame::kVPlane;
223 ++plane) {
224 if (sizes) {
225 gfx::Size size;
226 size =
227 VideoFrame::PlaneSize(frame_->format(),
228 plane,
229 gfx::Size(frame_->visible_rect().width(),
230 frame_->visible_rect().height()));
231 sizes[plane].set(size.width(), size.height());
233 if (row_bytes && planes) {
234 size_t offset;
235 int y_shift = (frame_->format() == media::VideoFrame::YV16) ? 0 : 1;
236 if (plane == media::VideoFrame::kYPlane) {
237 offset = (frame_->stride(media::VideoFrame::kYPlane) *
238 frame_->visible_rect().y()) +
239 frame_->visible_rect().x();
240 } else {
241 offset = (frame_->stride(media::VideoFrame::kUPlane) *
242 (frame_->visible_rect().y() >> y_shift)) +
243 (frame_->visible_rect().x() >> 1);
245 row_bytes[plane] = static_cast<size_t>(frame_->stride(plane));
246 planes[plane] = frame_->data(plane) + offset;
249 return true;
252 private:
253 scoped_refptr<VideoFrame> frame_;
255 DISALLOW_IMPLICIT_CONSTRUCTORS(VideoImageGenerator);
258 SkCanvasVideoRenderer::SkCanvasVideoRenderer()
259 : last_frame_timestamp_(media::kNoTimestamp()),
260 frame_deleting_timer_(
261 FROM_HERE,
262 base::TimeDelta::FromSeconds(kTemporaryResourceDeletionDelay),
263 this,
264 &SkCanvasVideoRenderer::ResetLastFrame),
265 accelerated_generator_(nullptr),
266 accelerated_last_frame_timestamp_(media::kNoTimestamp()),
267 accelerated_frame_deleting_timer_(
268 FROM_HERE,
269 base::TimeDelta::FromSeconds(kTemporaryResourceDeletionDelay),
270 this,
271 &SkCanvasVideoRenderer::ResetAcceleratedLastFrame) {
272 last_frame_.setIsVolatile(true);
275 SkCanvasVideoRenderer::~SkCanvasVideoRenderer() {}
277 void SkCanvasVideoRenderer::Paint(const scoped_refptr<VideoFrame>& video_frame,
278 SkCanvas* canvas,
279 const gfx::RectF& dest_rect,
280 uint8 alpha,
281 SkXfermode::Mode mode,
282 VideoRotation video_rotation,
283 const Context3D& context_3d) {
284 if (alpha == 0) {
285 return;
288 SkRect dest;
289 dest.set(dest_rect.x(), dest_rect.y(), dest_rect.right(), dest_rect.bottom());
291 SkPaint paint;
292 paint.setAlpha(alpha);
294 // Paint black rectangle if there isn't a frame available or the
295 // frame has an unexpected format.
296 if (!video_frame.get() || video_frame->natural_size().IsEmpty() ||
297 !IsYUVOrNative(video_frame->format())) {
298 canvas->drawRect(dest, paint);
299 canvas->flush();
300 return;
303 SkBitmap* target_frame = nullptr;
304 if (canvas->getGrContext()) {
305 if (accelerated_last_frame_.isNull() ||
306 video_frame->timestamp() != accelerated_last_frame_timestamp_) {
307 if (video_frame->format() == VideoFrame::NATIVE_TEXTURE) {
308 // Draw HW Video on HW Canvas.
309 DCHECK(context_3d.gl);
310 DCHECK(context_3d.gr_context);
311 if (accelerated_generator_) {
312 // Reset SkBitmap used in SWVideo-to-HWCanvas path.
313 accelerated_last_frame_.reset();
314 accelerated_generator_ = nullptr;
316 if (!CopyVideoFrameTextureToSkBitmapTexture(
317 video_frame.get(), &accelerated_last_frame_, context_3d)) {
318 NOTREACHED();
319 return;
321 } else {
322 // Draw SW Video on HW Canvas.
323 if (!accelerated_generator_ && !accelerated_last_frame_.isNull()) {
324 // Reset SkBitmap used in HWVideo-to-HWCanvas path.
325 accelerated_last_frame_.reset();
327 accelerated_generator_ = new VideoImageGenerator(video_frame);
329 // Note: This takes ownership of |accelerated_generator_|.
330 if (!SkInstallDiscardablePixelRef(accelerated_generator_,
331 &accelerated_last_frame_)) {
332 NOTREACHED();
333 return;
336 DCHECK(video_frame->visible_rect().width() ==
337 accelerated_last_frame_.width() &&
338 video_frame->visible_rect().height() ==
339 accelerated_last_frame_.height());
341 accelerated_last_frame_timestamp_ = video_frame->timestamp();
342 } else if (accelerated_generator_) {
343 accelerated_generator_->set_frame(video_frame);
345 target_frame = &accelerated_last_frame_;
346 accelerated_frame_deleting_timer_.Reset();
347 } else {
348 // Draw both SW and HW Video on SW Canvas.
349 if (last_frame_.isNull() ||
350 video_frame->timestamp() != last_frame_timestamp_) {
351 // Check if |bitmap| needs to be (re)allocated.
352 if (last_frame_.isNull() ||
353 last_frame_.width() != video_frame->visible_rect().width() ||
354 last_frame_.height() != video_frame->visible_rect().height()) {
355 last_frame_.allocN32Pixels(video_frame->visible_rect().width(),
356 video_frame->visible_rect().height());
357 last_frame_.setIsVolatile(true);
359 last_frame_.lockPixels();
360 ConvertVideoFrameToRGBPixels(
361 video_frame, last_frame_.getPixels(), last_frame_.rowBytes());
362 last_frame_.notifyPixelsChanged();
363 last_frame_.unlockPixels();
364 last_frame_timestamp_ = video_frame->timestamp();
366 target_frame = &last_frame_;
367 frame_deleting_timer_.Reset();
370 paint.setXfermodeMode(mode);
371 paint.setFilterLevel(SkPaint::kLow_FilterLevel);
373 bool need_transform =
374 video_rotation != VIDEO_ROTATION_0 ||
375 dest_rect.size() != video_frame->visible_rect().size() ||
376 !dest_rect.origin().IsOrigin();
377 if (need_transform) {
378 canvas->save();
379 canvas->translate(
380 SkFloatToScalar(dest_rect.x() + (dest_rect.width() * 0.5f)),
381 SkFloatToScalar(dest_rect.y() + (dest_rect.height() * 0.5f)));
382 SkScalar angle = SkFloatToScalar(0.0f);
383 switch (video_rotation) {
384 case VIDEO_ROTATION_0:
385 break;
386 case VIDEO_ROTATION_90:
387 angle = SkFloatToScalar(90.0f);
388 break;
389 case VIDEO_ROTATION_180:
390 angle = SkFloatToScalar(180.0f);
391 break;
392 case VIDEO_ROTATION_270:
393 angle = SkFloatToScalar(270.0f);
394 break;
396 canvas->rotate(angle);
398 gfx::SizeF rotated_dest_size = dest_rect.size();
399 if (video_rotation == VIDEO_ROTATION_90 ||
400 video_rotation == VIDEO_ROTATION_270) {
401 rotated_dest_size =
402 gfx::SizeF(rotated_dest_size.height(), rotated_dest_size.width());
404 canvas->scale(
405 SkFloatToScalar(rotated_dest_size.width() / target_frame->width()),
406 SkFloatToScalar(rotated_dest_size.height() / target_frame->height()));
407 canvas->translate(-SkFloatToScalar(target_frame->width() * 0.5f),
408 -SkFloatToScalar(target_frame->height() * 0.5f));
410 canvas->drawBitmap(*target_frame, 0, 0, &paint);
411 if (need_transform)
412 canvas->restore();
413 canvas->flush();
414 // SkCanvas::flush() causes the generator to generate SkImage, so delete
415 // |video_frame| not to be outlived.
416 if (canvas->getGrContext() && accelerated_generator_)
417 accelerated_generator_->set_frame(nullptr);
420 void SkCanvasVideoRenderer::Copy(const scoped_refptr<VideoFrame>& video_frame,
421 SkCanvas* canvas) {
422 Paint(video_frame, canvas, video_frame->visible_rect(), 0xff,
423 SkXfermode::kSrc_Mode, media::VIDEO_ROTATION_0, Context3D());
426 // static
427 void SkCanvasVideoRenderer::ConvertVideoFrameToRGBPixels(
428 const scoped_refptr<media::VideoFrame>& video_frame,
429 void* rgb_pixels,
430 size_t row_bytes) {
431 DCHECK(IsYUVOrNative(video_frame->format()))
432 << video_frame->format();
433 if (IsYUV(video_frame->format())) {
434 DCHECK_EQ(video_frame->stride(media::VideoFrame::kUPlane),
435 video_frame->stride(media::VideoFrame::kVPlane));
438 size_t y_offset = 0;
439 size_t uv_offset = 0;
440 if (IsYUV(video_frame->format())) {
441 int y_shift = (video_frame->format() == media::VideoFrame::YV16) ? 0 : 1;
442 // Use the "left" and "top" of the destination rect to locate the offset
443 // in Y, U and V planes.
444 y_offset = (video_frame->stride(media::VideoFrame::kYPlane) *
445 video_frame->visible_rect().y()) +
446 video_frame->visible_rect().x();
447 // For format YV12, there is one U, V value per 2x2 block.
448 // For format YV16, there is one U, V value per 2x1 block.
449 uv_offset = (video_frame->stride(media::VideoFrame::kUPlane) *
450 (video_frame->visible_rect().y() >> y_shift)) +
451 (video_frame->visible_rect().x() >> 1);
454 switch (video_frame->format()) {
455 case VideoFrame::YV12:
456 case VideoFrame::I420:
457 LIBYUV_I420_TO_ARGB(
458 video_frame->data(VideoFrame::kYPlane) + y_offset,
459 video_frame->stride(VideoFrame::kYPlane),
460 video_frame->data(VideoFrame::kUPlane) + uv_offset,
461 video_frame->stride(VideoFrame::kUPlane),
462 video_frame->data(VideoFrame::kVPlane) + uv_offset,
463 video_frame->stride(VideoFrame::kVPlane),
464 static_cast<uint8*>(rgb_pixels),
465 row_bytes,
466 video_frame->visible_rect().width(),
467 video_frame->visible_rect().height());
468 break;
470 case VideoFrame::YV12J:
471 ConvertYUVToRGB32(
472 video_frame->data(VideoFrame::kYPlane) + y_offset,
473 video_frame->data(VideoFrame::kUPlane) + uv_offset,
474 video_frame->data(VideoFrame::kVPlane) + uv_offset,
475 static_cast<uint8*>(rgb_pixels),
476 video_frame->visible_rect().width(),
477 video_frame->visible_rect().height(),
478 video_frame->stride(VideoFrame::kYPlane),
479 video_frame->stride(VideoFrame::kUPlane),
480 row_bytes,
481 YV12J);
482 break;
484 case VideoFrame::YV12HD:
485 ConvertYUVToRGB32(
486 video_frame->data(VideoFrame::kYPlane) + y_offset,
487 video_frame->data(VideoFrame::kUPlane) + uv_offset,
488 video_frame->data(VideoFrame::kVPlane) + uv_offset,
489 static_cast<uint8*>(rgb_pixels),
490 video_frame->visible_rect().width(),
491 video_frame->visible_rect().height(),
492 video_frame->stride(VideoFrame::kYPlane),
493 video_frame->stride(VideoFrame::kUPlane),
494 row_bytes,
495 YV12HD);
496 break;
498 case VideoFrame::YV16:
499 LIBYUV_I422_TO_ARGB(
500 video_frame->data(VideoFrame::kYPlane) + y_offset,
501 video_frame->stride(VideoFrame::kYPlane),
502 video_frame->data(VideoFrame::kUPlane) + uv_offset,
503 video_frame->stride(VideoFrame::kUPlane),
504 video_frame->data(VideoFrame::kVPlane) + uv_offset,
505 video_frame->stride(VideoFrame::kVPlane),
506 static_cast<uint8*>(rgb_pixels),
507 row_bytes,
508 video_frame->visible_rect().width(),
509 video_frame->visible_rect().height());
510 break;
512 case VideoFrame::YV12A:
513 // Since libyuv doesn't support YUVA, fallback to media, which is not ARM
514 // optimized.
515 // TODO(fbarchard, mtomasz): Use libyuv, then copy the alpha channel.
516 ConvertYUVAToARGB(
517 video_frame->data(VideoFrame::kYPlane) + y_offset,
518 video_frame->data(VideoFrame::kUPlane) + uv_offset,
519 video_frame->data(VideoFrame::kVPlane) + uv_offset,
520 video_frame->data(VideoFrame::kAPlane),
521 static_cast<uint8*>(rgb_pixels),
522 video_frame->visible_rect().width(),
523 video_frame->visible_rect().height(),
524 video_frame->stride(VideoFrame::kYPlane),
525 video_frame->stride(VideoFrame::kUPlane),
526 video_frame->stride(VideoFrame::kAPlane),
527 row_bytes,
528 YV12);
529 break;
531 case VideoFrame::YV24:
532 libyuv::I444ToARGB(
533 video_frame->data(VideoFrame::kYPlane) + y_offset,
534 video_frame->stride(VideoFrame::kYPlane),
535 video_frame->data(VideoFrame::kUPlane) + uv_offset,
536 video_frame->stride(VideoFrame::kUPlane),
537 video_frame->data(VideoFrame::kVPlane) + uv_offset,
538 video_frame->stride(VideoFrame::kVPlane),
539 static_cast<uint8*>(rgb_pixels),
540 row_bytes,
541 video_frame->visible_rect().width(),
542 video_frame->visible_rect().height());
543 #if SK_R32_SHIFT == 0 && SK_G32_SHIFT == 8 && SK_B32_SHIFT == 16 && \
544 SK_A32_SHIFT == 24
545 libyuv::ARGBToABGR(static_cast<uint8*>(rgb_pixels),
546 row_bytes,
547 static_cast<uint8*>(rgb_pixels),
548 row_bytes,
549 video_frame->visible_rect().width(),
550 video_frame->visible_rect().height());
551 #endif
552 break;
554 case VideoFrame::NATIVE_TEXTURE: {
555 SkBitmap tmp;
556 tmp.installPixels(
557 SkImageInfo::MakeN32Premul(video_frame->visible_rect().width(),
558 video_frame->visible_rect().height()),
559 rgb_pixels,
560 row_bytes);
561 video_frame->ReadPixelsFromNativeTexture(tmp);
562 break;
565 #if defined(VIDEO_HOLE)
566 case VideoFrame::HOLE:
567 #endif // defined(VIDEO_HOLE)
568 case VideoFrame::ARGB:
569 case VideoFrame::UNKNOWN:
570 case VideoFrame::NV12:
571 NOTREACHED();
575 // static
576 void SkCanvasVideoRenderer::CopyVideoFrameTextureToGLTexture(
577 gpu::gles2::GLES2Interface* gl,
578 VideoFrame* video_frame,
579 unsigned int texture,
580 unsigned int level,
581 unsigned int internal_format,
582 unsigned int type,
583 bool premultiply_alpha,
584 bool flip_y) {
585 DCHECK(video_frame && video_frame->format() == VideoFrame::NATIVE_TEXTURE);
586 const gpu::MailboxHolder* mailbox_holder = video_frame->mailbox_holder();
587 DCHECK(mailbox_holder->texture_target == GL_TEXTURE_2D ||
588 mailbox_holder->texture_target == GL_TEXTURE_RECTANGLE_ARB ||
589 mailbox_holder->texture_target == GL_TEXTURE_EXTERNAL_OES);
591 gl->WaitSyncPointCHROMIUM(mailbox_holder->sync_point);
592 uint32 source_texture = gl->CreateAndConsumeTextureCHROMIUM(
593 mailbox_holder->texture_target, mailbox_holder->mailbox.name);
595 // The video is stored in a unmultiplied format, so premultiply
596 // if necessary.
597 gl->PixelStorei(GL_UNPACK_PREMULTIPLY_ALPHA_CHROMIUM, premultiply_alpha);
598 // Application itself needs to take care of setting the right |flip_y|
599 // value down to get the expected result.
600 // "flip_y == true" means to reverse the video orientation while
601 // "flip_y == false" means to keep the intrinsic orientation.
602 gl->PixelStorei(GL_UNPACK_FLIP_Y_CHROMIUM, flip_y);
603 gl->CopyTextureCHROMIUM(GL_TEXTURE_2D, source_texture, texture, level,
604 internal_format, type);
605 gl->PixelStorei(GL_UNPACK_FLIP_Y_CHROMIUM, false);
606 gl->PixelStorei(GL_UNPACK_PREMULTIPLY_ALPHA_CHROMIUM, false);
608 gl->DeleteTextures(1, &source_texture);
609 gl->Flush();
611 SyncPointClientImpl client(gl);
612 video_frame->UpdateReleaseSyncPoint(&client);
615 void SkCanvasVideoRenderer::ResetLastFrame() {
616 last_frame_.reset();
617 last_frame_timestamp_ = media::kNoTimestamp();
620 void SkCanvasVideoRenderer::ResetAcceleratedLastFrame() {
621 accelerated_last_frame_.reset();
622 accelerated_generator_ = nullptr;
623 accelerated_last_frame_timestamp_ = media::kNoTimestamp();
626 } // namespace media