Commit 5394a410 authored by hkuang@chromium.org's avatar hkuang@chromium.org

Enable video painting on Canvas for Chrome on Android. This change should land...

Enable video painting on Canvas for Chrome on Android. This change should land after another patch landing in https://codereview.chromium.org/13685002.


BUG=147265
TEST=visited the following site:
http://html5doctor.com/demos/video-canvas-magic/demo1.html

Visit http://www.w3schools.com/tags/tryit.asp?filename=tryhtml5_canvas_drawimage_video.
Change different parameters of the canvas and video. Compare the result between desktop chrome and android chrome to see if video painting results are the same.

Canvas 500X400 ctx.drawImage(v,60,60,320,176)                PASS
Canvas 500X400 ctx.drawImage(v,0,0,320,176)                  PASS
Canvas 200X100 ctx.drawImage(v,0,0,320,176)                  PASS
Canvas 200X100 ctx.drawImage(v,50,50,320,176)                PASS
Canvas 500X400 ctx.drawImage(v,0,0,30,30,5,5,260,125)        PASS
Canvas 500X400 ctx.drawImage(v,0,0)                          PASS
Canvas 600x700 ctx.drawImage(v,90,90,80,80,100,100,260,125)  PASS

TODO:
More complex and mixed 2D Canvas operation to see if the painting result is right(Need to learn some more JS for that).

Review URL: https://chromiumcodereview.appspot.com/13620008

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@194785 0039d316-1c4b-4281-b951-d872f2087c98
parent 4f60d80f
...@@ -54,10 +54,11 @@ struct ShaderInfo { ...@@ -54,10 +54,11 @@ struct ShaderInfo {
const ShaderInfo shader_infos[] = { const ShaderInfo shader_infos[] = {
// VERTEX_SHADER_POS_TEX // VERTEX_SHADER_POS_TEX
SHADER( SHADER(
uniform mat4 u_matrix;
attribute vec4 a_position; attribute vec4 a_position;
varying vec2 v_uv; varying vec2 v_uv;
void main(void) { void main(void) {
gl_Position = a_position; gl_Position = u_matrix * a_position;
v_uv = a_position.xy * 0.5 + vec2(0.5, 0.5); v_uv = a_position.xy * 0.5 + vec2(0.5, 0.5);
}), }),
// FRAGMENT_SHADER_TEX // FRAGMENT_SHADER_TEX
...@@ -279,6 +280,9 @@ void CopyTextureCHROMIUMResourceManager::Initialize( ...@@ -279,6 +280,9 @@ void CopyTextureCHROMIUMResourceManager::Initialize(
sampler_locations_[program] = glGetUniformLocation(programs_[program], sampler_locations_[program] = glGetUniformLocation(programs_[program],
"u_texSampler"); "u_texSampler");
matrix_handle_[program] = glGetUniformLocation(programs_[program],
"u_matrix");
} }
for (int shader = 0; shader < kNumShaders; ++shader) for (int shader = 0; shader < kNumShaders; ++shader)
...@@ -313,6 +317,29 @@ void CopyTextureCHROMIUMResourceManager::DoCopyTexture( ...@@ -313,6 +317,29 @@ void CopyTextureCHROMIUMResourceManager::DoCopyTexture(
bool flip_y, bool flip_y,
bool premultiply_alpha, bool premultiply_alpha,
bool unpremultiply_alpha) { bool unpremultiply_alpha) {
// Use default transform matrix if no transform passed in.
const static GLfloat default_matrix[16] = {1.0f, 0.0f, 0.0f, 0.0f,
0.0f, 1.0f, 0.0f, 0.0f,
0.0f, 0.0f, 1.0f, 0.0f,
0.0f, 0.0f, 0.0f, 1.0f};
DoCopyTextureWithTransform(decoder, source_target, dest_target, source_id,
dest_id, level, width, height, flip_y, premultiply_alpha,
unpremultiply_alpha, default_matrix);
}
void CopyTextureCHROMIUMResourceManager::DoCopyTextureWithTransform(
const gles2::GLES2Decoder* decoder,
GLenum source_target,
GLenum dest_target,
GLuint source_id,
GLuint dest_id,
GLint level,
GLsizei width,
GLsizei height,
bool flip_y,
bool premultiply_alpha,
bool unpremultiply_alpha,
const GLfloat transform_matrix[16]) {
DCHECK(source_target == GL_TEXTURE_2D || DCHECK(source_target == GL_TEXTURE_2D ||
source_target == GL_TEXTURE_EXTERNAL_OES); source_target == GL_TEXTURE_EXTERNAL_OES);
if (!initialized_) { if (!initialized_) {
...@@ -335,6 +362,7 @@ void CopyTextureCHROMIUMResourceManager::DoCopyTexture( ...@@ -335,6 +362,7 @@ void CopyTextureCHROMIUMResourceManager::DoCopyTexture(
} }
#endif #endif
glUniformMatrix4fv(matrix_handle_[program], 1, GL_FALSE, transform_matrix);
glActiveTexture(GL_TEXTURE0); glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, dest_id); glBindTexture(GL_TEXTURE_2D, dest_id);
// NVidia drivers require texture settings to be a certain way // NVidia drivers require texture settings to be a certain way
......
...@@ -31,6 +31,16 @@ class GPU_EXPORT CopyTextureCHROMIUMResourceManager { ...@@ -31,6 +31,16 @@ class GPU_EXPORT CopyTextureCHROMIUMResourceManager {
bool flip_y, bool premultiply_alpha, bool flip_y, bool premultiply_alpha,
bool unpremultiply_alpha); bool unpremultiply_alpha);
// This will apply a transform on the source texture before copying to
// destination texture.
void DoCopyTextureWithTransform(const gles2::GLES2Decoder* decoder,
GLenum source_target, GLenum dest_target,
GLuint source_id, GLuint dest_id, GLint level,
GLsizei width, GLsizei height, bool flip_y,
bool premultiply_alpha,
bool unpremultiply_alpha,
const GLfloat transform_matrix[16]);
// The attributes used during invocation of the extension. // The attributes used during invocation of the extension.
static const GLuint kVertexPositionAttrib = 0; static const GLuint kVertexPositionAttrib = 0;
...@@ -41,6 +51,7 @@ class GPU_EXPORT CopyTextureCHROMIUMResourceManager { ...@@ -41,6 +51,7 @@ class GPU_EXPORT CopyTextureCHROMIUMResourceManager {
GLuint programs_[kNumPrograms]; GLuint programs_[kNumPrograms];
GLuint buffer_id_; GLuint buffer_id_;
GLuint framebuffer_; GLuint framebuffer_;
GLuint matrix_handle_[kNumPrograms];
GLuint sampler_locations_[kNumPrograms]; GLuint sampler_locations_[kNumPrograms];
DISALLOW_COPY_AND_ASSIGN(CopyTextureCHROMIUMResourceManager); DISALLOW_COPY_AND_ASSIGN(CopyTextureCHROMIUMResourceManager);
......
...@@ -9852,15 +9852,38 @@ void GLES2DecoderImpl::DoCopyTextureCHROMIUM( ...@@ -9852,15 +9852,38 @@ void GLES2DecoderImpl::DoCopyTextureCHROMIUM(
dest_texture, GL_TEXTURE_2D, level, true); dest_texture, GL_TEXTURE_2D, level, true);
} }
copy_texture_CHROMIUM_->DoCopyTexture(this, // GL_TEXTURE_EXTERNAL_OES texture requires apply a transform matrix
source_texture->target(), // before presenting.
dest_texture->target(), if (source_texture->target() == GL_TEXTURE_EXTERNAL_OES) {
source_texture->service_id(), // TODO(hkuang): get the StreamTexture transform matrix in GPU process
dest_texture->service_id(), level, // instead of using default matrix crbug.com/226218.
source_width, source_height, const static GLfloat default_matrix[16] = {1.0f, 0.0f, 0.0f, 0.0f,
unpack_flip_y_, 0.0f, 1.0f, 0.0f, 0.0f,
unpack_premultiply_alpha_, 0.0f, 0.0f, 1.0f, 0.0f,
unpack_unpremultiply_alpha_); 0.0f, 0.0f, 0.0f, 1.0f};
copy_texture_CHROMIUM_->DoCopyTextureWithTransform(
this,
source_texture->target(),
dest_texture->target(),
source_texture->service_id(),
dest_texture->service_id(), level,
source_width, source_height,
unpack_flip_y_,
unpack_premultiply_alpha_,
unpack_unpremultiply_alpha_,
default_matrix);
} else {
copy_texture_CHROMIUM_->DoCopyTexture(
this,
source_texture->target(),
dest_texture->target(),
source_texture->service_id(),
dest_texture->service_id(), level,
source_width, source_height,
unpack_flip_y_,
unpack_premultiply_alpha_,
unpack_unpremultiply_alpha_);
}
} }
static GLenum ExtractTypeFromStorageFormat(GLenum internalformat) { static GLenum ExtractTypeFromStorageFormat(GLenum internalformat) {
......
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
#include "base/logging.h" #include "base/logging.h"
#include "base/strings/string_number_conversions.h" #include "base/strings/string_number_conversions.h"
#include "cc/layers/video_layer.h" #include "cc/layers/video_layer.h"
#include "gpu/GLES2/gl2extchromium.h"
#include "media/base/android/media_player_bridge.h" #include "media/base/android/media_player_bridge.h"
#include "media/base/video_frame.h" #include "media/base/video_frame.h"
#include "net/base/mime_util.h" #include "net/base/mime_util.h"
...@@ -270,6 +271,34 @@ void WebMediaPlayerAndroid::paint(WebKit::WebCanvas* canvas, ...@@ -270,6 +271,34 @@ void WebMediaPlayerAndroid::paint(WebKit::WebCanvas* canvas,
NOTIMPLEMENTED(); NOTIMPLEMENTED();
} }
bool WebMediaPlayerAndroid::copyVideoTextureToPlatformTexture(
WebKit::WebGraphicsContext3D* web_graphics_context,
unsigned int texture,
unsigned int level,
unsigned int internal_format,
bool premultiply_alpha,
bool flip_y) {
if (!texture_id_)
return false;
// The video is stored in an unmultiplied format, so premultiply if
// necessary.
web_graphics_context->pixelStorei(GL_UNPACK_PREMULTIPLY_ALPHA_CHROMIUM,
premultiply_alpha);
// Application itself needs to take care of setting the right flip_y
// value down to get the expected result.
// flip_y==true means to reverse the video orientation while
// flip_y==false means to keep the intrinsic orientation.
web_graphics_context->pixelStorei(GL_UNPACK_FLIP_Y_CHROMIUM, flip_y);
web_graphics_context->copyTextureCHROMIUM(GL_TEXTURE_2D, texture_id_,
texture, level, internal_format);
web_graphics_context->pixelStorei(GL_UNPACK_FLIP_Y_CHROMIUM, false);
web_graphics_context->pixelStorei(GL_UNPACK_PREMULTIPLY_ALPHA_CHROMIUM,
false);
return true;
}
bool WebMediaPlayerAndroid::hasSingleSecurityOrigin() const { bool WebMediaPlayerAndroid::hasSingleSecurityOrigin() const {
return false; return false;
} }
......
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
#include "base/message_loop.h" #include "base/message_loop.h"
#include "base/time.h" #include "base/time.h"
#include "cc/layers/video_frame_provider.h" #include "cc/layers/video_frame_provider.h"
#include "third_party/WebKit/Source/Platform/chromium/public/WebGraphicsContext3D.h"
#include "third_party/WebKit/Source/Platform/chromium/public/WebSize.h" #include "third_party/WebKit/Source/Platform/chromium/public/WebSize.h"
#include "third_party/WebKit/Source/Platform/chromium/public/WebURL.h" #include "third_party/WebKit/Source/Platform/chromium/public/WebURL.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebMediaPlayer.h" #include "third_party/WebKit/Source/WebKit/chromium/public/WebMediaPlayer.h"
...@@ -65,6 +66,14 @@ class WebMediaPlayerAndroid ...@@ -65,6 +66,14 @@ class WebMediaPlayerAndroid
const WebKit::WebRect& rect, const WebKit::WebRect& rect,
uint8_t alpha); uint8_t alpha);
virtual bool copyVideoTextureToPlatformTexture(
WebKit::WebGraphicsContext3D* web_graphics_context,
unsigned int texture,
unsigned int level,
unsigned int internal_format,
bool premultiply_alpha,
bool flip_y);
// True if the loaded media has a playable video/audio track. // True if the loaded media has a playable video/audio track.
virtual bool hasVideo() const; virtual bool hasVideo() const;
virtual bool hasAudio() const; virtual bool hasAudio() const;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment