Beispiel #1
0
bool MediaLayer::drawGL(GLWebViewState* glWebViewState, SkMatrix& matrix)
{
    TilesManager::instance()->shader()->clip(drawClip());

    // when the plugin gains focus webkit applies an outline to the
    // widget, which causes the layer to expand to accommodate the
    // outline. Therefore, we shrink the rect by the outline's dimensions
    // to ensure the plugin does not draw outside of its bounds.
    SkRect mediaBounds;
    mediaBounds.set(0, 0, getSize().width(), getSize().height());
    mediaBounds.inset(m_outlineSize, m_outlineSize);

    // check to see if we need to create a content or video texture
    m_mediaTexture->initNativeWindowIfNeeded();

    // the layer's shader draws the content inverted so we must undo
    // that change in the transformation matrix
    TransformationMatrix m = m_drawTransform;
    if (!m_mediaTexture->isContentInverted()) {
        m.flipY();
        m.translate(0, -getSize().height());
    }

    // draw any content or video if present
    m_mediaTexture->draw(m, m_drawTransform, mediaBounds);

    return drawChildrenGL(glWebViewState, matrix);
}
bool VideoLayerAndroid::drawGL()
{
    // Lazily allocated the textures.
    if (!m_createdTexture) {
        m_backgroundTextureId = createBackgroundTexture();
        m_spinnerOuterTextureId = createSpinnerOuterTexture();
        m_spinnerInnerTextureId = createSpinnerInnerTexture();
        m_posterTextureId = createPosterTexture();
        m_createdTexture = true;
    }

    SkRect rect = SkRect::MakeSize(getSize());
    GLfloat surfaceMatrix[16];

    SkRect innerRect = SkRect(buttonRect);
    if (innerRect.contains(rect))
        innerRect = rect;

    innerRect.offset((rect.width() - IMAGESIZE) / 2 , (rect.height() - IMAGESIZE) / 2);

    // Draw the poster image, the progressing image or the Video depending
    // on the player's state.
    if (m_playerState == PREPARING) {
        // Show the progressing animation, with two rotating circles
		// SSG
		if (m_surfaceTexture.get() && (m_surfaceTexture->getTimestamp() > 0)) {
			m_surfaceTexture->getTransformMatrix(surfaceMatrix);
			GLuint textureId =
				TilesManager::instance()->videoLayerManager()->getTextureId(uniqueId());
			TilesManager::instance()->shader()->drawVideoLayerQuad(m_drawTransform,
					surfaceMatrix,
					rect, textureId);
			TilesManager::instance()->videoLayerManager()->updateMatrix(uniqueId(),
					surfaceMatrix);
		} else {
			TilesManager::instance()->shader()->drawLayerQuad(m_drawTransform, rect,
					m_backgroundTextureId,
					1, true);
		}

        TransformationMatrix addReverseRotation;
        TransformationMatrix addRotation = m_drawTransform;
        addRotation.translate(innerRect.fLeft, innerRect.fTop);
        addRotation.translate(IMAGESIZE / 2, IMAGESIZE / 2);
        addReverseRotation = addRotation;
        addRotation.rotate(m_rotateDegree);
        addRotation.translate(-IMAGESIZE / 2, -IMAGESIZE / 2);

        SkRect size = SkRect::MakeWH(innerRect.width(), innerRect.height());
        TilesManager::instance()->shader()->drawLayerQuad(addRotation, size,
                                                          m_spinnerOuterTextureId,
                                                          1, true);

        addReverseRotation.rotate(-m_rotateDegree);
        addReverseRotation.translate(-IMAGESIZE / 2, -IMAGESIZE / 2);

        TilesManager::instance()->shader()->drawLayerQuad(addReverseRotation, size,
                                                          m_spinnerInnerTextureId,
                                                          1, true);

        m_rotateDegree += ROTATESTEP;

    } else if (m_playerState == PLAYING && m_surfaceTexture.get()) {
        // Show the real video.
        m_surfaceTexture->updateTexImage();
        m_surfaceTexture->getTransformMatrix(surfaceMatrix);
        GLuint textureId =
            TilesManager::instance()->videoLayerManager()->getTextureId(uniqueId());
        TilesManager::instance()->shader()->drawVideoLayerQuad(m_drawTransform,
                                                               surfaceMatrix,
                                                               rect, textureId);
        TilesManager::instance()->videoLayerManager()->updateMatrix(uniqueId(),
                                                                    surfaceMatrix);
    } else {
        GLuint textureId =
            TilesManager::instance()->videoLayerManager()->getTextureId(uniqueId());
        GLfloat* matrix =
            TilesManager::instance()->videoLayerManager()->getMatrix(uniqueId());
        if (textureId && matrix) {
            // Show the screen shot for each video.
            TilesManager::instance()->shader()->drawVideoLayerQuad(m_drawTransform,
                                                               matrix,
                                                               rect, textureId);
        } else {
            // Show the static poster b/c there is no screen shot available.
            TilesManager::instance()->shader()->drawLayerQuad(m_drawTransform, rect,
                                                              m_backgroundTextureId,
                                                              1, true);
            TilesManager::instance()->shader()->drawLayerQuad(m_drawTransform, innerRect,
                                                              m_posterTextureId,
                                                              1, true);
        }
    }

    return drawChildrenGL();
}