diff options
Diffstat (limited to 'Source/WebCore/platform/graphics/android/VideoLayerAndroid.cpp')
-rw-r--r-- | Source/WebCore/platform/graphics/android/VideoLayerAndroid.cpp | 143 |
1 files changed, 36 insertions, 107 deletions
diff --git a/Source/WebCore/platform/graphics/android/VideoLayerAndroid.cpp b/Source/WebCore/platform/graphics/android/VideoLayerAndroid.cpp index 46a8c1d..e48d36c 100644 --- a/Source/WebCore/platform/graphics/android/VideoLayerAndroid.cpp +++ b/Source/WebCore/platform/graphics/android/VideoLayerAndroid.cpp @@ -26,16 +26,18 @@ #include "config.h" #include "VideoLayerAndroid.h" -#include "RenderSkinMediaButton.h" #include "TilesManager.h" #include <GLES2/gl2.h> +#include <cutils/log.h> #include <gui/SurfaceTexture.h> +#include <wtf/text/CString.h> #if USE(ACCELERATED_COMPOSITING) +#undef XLOGC +#define XLOGC(...) android_printLog(ANDROID_LOG_DEBUG, "VideoLayerAndroid", __VA_ARGS__) + #ifdef DEBUG -#include <cutils/log.h> -#include <wtf/text/CString.h> #undef XLOG #define XLOG(...) android_printLog(ANDROID_LOG_DEBUG, "VideoLayerAndroid", __VA_ARGS__) @@ -49,18 +51,8 @@ namespace WebCore { -GLuint VideoLayerAndroid::m_spinnerOuterTextureId = 0; -GLuint VideoLayerAndroid::m_spinnerInnerTextureId = 0; -GLuint VideoLayerAndroid::m_posterTextureId = 0; -GLuint VideoLayerAndroid::m_backgroundTextureId = 0; -GLuint VideoLayerAndroid::m_playTextureId = 0; -GLuint VideoLayerAndroid::m_pauseTextureId = 0; -bool VideoLayerAndroid::m_createdTexture = false; - double VideoLayerAndroid::m_rotateDegree = 0; -const IntRect VideoLayerAndroid::buttonRect(0, 0, IMAGESIZE, IMAGESIZE); - VideoLayerAndroid::VideoLayerAndroid() : LayerAndroid((RenderLayer*)0) { @@ -89,93 +81,33 @@ void VideoLayerAndroid::setSurfaceTexture(sp<SurfaceTexture> texture, TilesManager::instance()->videoLayerManager()->registerTexture(uniqueId(), textureName); } -GLuint VideoLayerAndroid::createSpinnerInnerTexture() -{ - return createTextureFromImage(RenderSkinMediaButton::SPINNER_INNER); -} - -GLuint VideoLayerAndroid::createSpinnerOuterTexture() -{ - return createTextureFromImage(RenderSkinMediaButton::SPINNER_OUTER); -} - -GLuint VideoLayerAndroid::createPosterTexture() -{ - return createTextureFromImage(RenderSkinMediaButton::VIDEO); -} - -GLuint VideoLayerAndroid::createPlayTexture() -{ - return createTextureFromImage(RenderSkinMediaButton::PLAY); -} - -GLuint VideoLayerAndroid::createPauseTexture() -{ - return createTextureFromImage(RenderSkinMediaButton::PAUSE); -} - -GLuint VideoLayerAndroid::createTextureFromImage(int buttonType) -{ - SkRect rect = SkRect(buttonRect); - SkBitmap bitmap; - bitmap.setConfig(SkBitmap::kARGB_8888_Config, rect.width(), rect.height()); - bitmap.allocPixels(); - bitmap.eraseColor(0); - - SkCanvas canvas(bitmap); - canvas.drawARGB(0, 0, 0, 0, SkXfermode::kClear_Mode); - RenderSkinMediaButton::Draw(&canvas, buttonRect, buttonType, true, 0, - false); - - GLuint texture; - glGenTextures(1, &texture); - - GLUtils::createTextureWithBitmap(texture, bitmap); - bitmap.reset(); - return texture; -} - -GLuint VideoLayerAndroid::createBackgroundTexture() -{ - GLuint texture; - glGenTextures(1, &texture); - glPixelStorei(GL_UNPACK_ALIGNMENT, 1); - GLubyte pixels[4 *3] = { - 128, 128, 128, - 128, 128, 128, - 128, 128, 128, - 128, 128, 128 - }; - glBindTexture(GL_TEXTURE_2D, texture); - GLUtils::checkGlError("glBindTexture"); - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 2, 2, 0, GL_RGB, GL_UNSIGNED_BYTE, pixels); - GLUtils::checkGlError("glTexImage2D"); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); - return texture; -} - void VideoLayerAndroid::showPreparingAnimation(const SkRect& rect, const SkRect innerRect) { ShaderProgram* shader = TilesManager::instance()->shader(); - shader->drawLayerQuad(m_drawTransform, rect, m_backgroundTextureId, 1, true); + VideoLayerManager* manager = TilesManager::instance()->videoLayerManager(); + // Paint the video content's background. + shader->drawLayerQuad(m_drawTransform, rect, 0, 1, true, GL_TEXTURE_2D, + Color(128, 128, 128, 255)); TransformationMatrix addReverseRotation; TransformationMatrix addRotation = m_drawTransform; addRotation.translate(innerRect.fLeft, innerRect.fTop); - addRotation.translate(IMAGESIZE / 2, IMAGESIZE / 2); + double halfButtonSize = manager->getButtonSize() / 2; + addRotation.translate(halfButtonSize, halfButtonSize); addReverseRotation = addRotation; addRotation.rotate(m_rotateDegree); - addRotation.translate(-IMAGESIZE / 2, -IMAGESIZE / 2); + addRotation.translate(-halfButtonSize, -halfButtonSize); SkRect size = SkRect::MakeWH(innerRect.width(), innerRect.height()); - shader->drawLayerQuad(addRotation, size, m_spinnerOuterTextureId, 1, true); + shader->drawLayerQuad(addRotation, size, + manager->getSpinnerOuterTextureId(), 1, true); addReverseRotation.rotate(-m_rotateDegree); - addReverseRotation.translate(-IMAGESIZE / 2, -IMAGESIZE / 2); + addReverseRotation.translate(-halfButtonSize, -halfButtonSize); - shader->drawLayerQuad(addReverseRotation, size, m_spinnerInnerTextureId, 1, true); + shader->drawLayerQuad(addReverseRotation, size, + manager->getSpinnerInnerTextureId(), 1, true); m_rotateDegree += ROTATESTEP; } @@ -199,17 +131,11 @@ SkRect VideoLayerAndroid::calVideoRect(const SkRect& rect) bool VideoLayerAndroid::drawGL(bool layerTilesDisabled) { // Lazily allocated the textures. - if (!m_createdTexture) { - m_backgroundTextureId = createBackgroundTexture(); - m_spinnerOuterTextureId = createSpinnerOuterTexture(); - m_spinnerInnerTextureId = createSpinnerInnerTexture(); - m_posterTextureId = createPosterTexture(); - m_playTextureId = createPlayTexture(); - m_pauseTextureId = createPauseTexture(); - m_createdTexture = true; - } + TilesManager* tilesManager = TilesManager::instance(); + VideoLayerManager* manager = tilesManager->videoLayerManager(); + manager->initGLResourcesIfNeeded(); - ShaderProgram* shader = TilesManager::instance()->shader(); + ShaderProgram* shader = tilesManager->shader(); SkRect rect = SkRect::MakeSize(getSize()); GLfloat surfaceMatrix[16]; @@ -224,11 +150,13 @@ bool VideoLayerAndroid::drawGL(bool layerTilesDisabled) } // Inner rect is for the progressing / play / pause animation. - SkRect innerRect = SkRect(buttonRect); + SkRect innerRect = SkRect::MakeWH(manager->getButtonSize(), + manager->getButtonSize()); if (innerRect.contains(videoRect)) innerRect = videoRect; - innerRect.offset(videoRect.fLeft + (videoRect.width() - IMAGESIZE) / 2, - videoRect.fTop + (videoRect.height() - IMAGESIZE) / 2); + double buttonSize = manager->getButtonSize(); + innerRect.offset(videoRect.fLeft + (videoRect.width() - buttonSize) / 2, + videoRect.fTop + (videoRect.height() - buttonSize) / 2); // When we are drawing the animation of the play/pause button in the // middle of the video, we need to ask for redraw. @@ -236,7 +164,6 @@ bool VideoLayerAndroid::drawGL(bool layerTilesDisabled) // Draw the poster image, the progressing image or the Video depending // on the player's state. - VideoLayerManager* manager = TilesManager::instance()->videoLayerManager(); if (m_playerState == PREPARING) { // Show the progressing animation, with two rotating circles showPreparingAnimation(videoRect, innerRect); @@ -253,9 +180,10 @@ bool VideoLayerAndroid::drawGL(bool layerTilesDisabled) // Use the scale to control the fading the sizing during animation double scale = manager->drawIcon(uniqueId(), PlayIcon); if (scale) { - innerRect.inset(IMAGESIZE / 4 * scale, IMAGESIZE / 4 * scale); + innerRect.inset(manager->getButtonSize() / 4 * scale, + manager->getButtonSize() / 4 * scale); shader->drawLayerQuad(m_drawTransform, innerRect, - m_playTextureId, scale, true); + manager->getPlayTextureId(), scale, true); needRedraw = true; } @@ -268,18 +196,19 @@ bool VideoLayerAndroid::drawGL(bool layerTilesDisabled) videoRect, textureId); } else { // Show the static poster b/c there is no screen shot available. - shader->drawLayerQuad(m_drawTransform, videoRect, m_backgroundTextureId, - 1, true); - shader->drawLayerQuad(m_drawTransform, innerRect, m_posterTextureId, - 1, true); + shader->drawLayerQuad(m_drawTransform, rect, 0, 1, true, GL_TEXTURE_2D, + Color(128, 128, 128, 255)); + shader->drawLayerQuad(m_drawTransform, innerRect, + manager->getPosterTextureId(), 1, true); } // Use the scale to control the fading and the sizing during animation. double scale = manager->drawIcon(uniqueId(), PauseIcon); if (scale) { - innerRect.inset(IMAGESIZE / 4 * scale, IMAGESIZE / 4 * scale); + innerRect.inset(manager->getButtonSize() / 4 * scale, + manager->getButtonSize() / 4 * scale); shader->drawLayerQuad(m_drawTransform, innerRect, - m_pauseTextureId, scale, true); + manager->getPauseTextureId(), scale, true); needRedraw = true; } |