Fix synchronization bug in video to webgl texture upload

TexImage2D calls with a video element as a source were sometimes
failing because of a texture copy that was missing posterior
synchronization. This meant that it was possible for the source
texture to be recycled by skia (in a different command stream)
before the copy is executed.

BUG=807974
TBR=xlai@chromium.org

Cq-Include-Trybots: master.tryserver.blink:linux_trusty_blink_rel;master.tryserver.chromium.linux:linux_layout_tests_slimming_paint_v2
Change-Id: I5f5124e45e803240507a676e75b2183cf564e1ab
Reviewed-on: https://chromium-review.googlesource.com/945331
Reviewed-by: Justin Novosad <junov@chromium.org>
Cr-Commit-Position: refs/branch-heads/3325@{#644}
Cr-Branched-From: bc084a8b5afa3744a74927344e304c02ae54189f-refs/heads/master@{#530369}
diff --git a/third_party/WebKit/Source/platform/graphics/AcceleratedStaticBitmapImage.cpp b/third_party/WebKit/Source/platform/graphics/AcceleratedStaticBitmapImage.cpp
index e24cbb3..b1ddc0d 100644
--- a/third_party/WebKit/Source/platform/graphics/AcceleratedStaticBitmapImage.cpp
+++ b/third_party/WebKit/Source/platform/graphics/AcceleratedStaticBitmapImage.cpp
@@ -174,6 +174,14 @@
   // This drops the |destGL| context's reference on our |m_mailbox|, but it's
   // still held alive by our SkImage.
   dest_gl->DeleteTextures(1, &source_texture_id);
+
+  // We need to update the texture holder's sync token to ensure that when this
+  // image is deleted, the texture resource will not be recycled by skia before
+  // the the above texture copy has completed.
+  gpu::SyncToken sync_token;
+  dest_gl->GenUnverifiedSyncTokenCHROMIUM(sync_token.GetData());
+  texture_holder_->UpdateSyncToken(sync_token);
+
   return true;
 }