1 /* 2 * Copyright (C) 2010 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 #include "config.h" 17 #include "MediaLayer.h" 18 #include "MediaTexture.h" 19 #include "TilesManager.h" 20 21 #if USE(ACCELERATED_COMPOSITING) 22 23 #define LAYER_DEBUG 24 #undef LAYER_DEBUG 25 26 #ifdef DEBUG 27 28 #include <cutils/log.h> 29 #include <wtf/text/CString.h> 30 31 #undef XLOG 32 #define XLOG(...) android_printLog(ANDROID_LOG_DEBUG, "MediaLayer", __VA_ARGS__) 33 34 #else 35 36 #undef XLOG 37 #define XLOG(...) 38 39 #endif // DEBUG 40 41 namespace WebCore { 42 43 MediaLayer::MediaLayer(jobject webViewRef) : LayerAndroid((RenderLayer*) NULL) 44 { 45 m_mediaTexture = new MediaTexture(webViewRef); 46 m_mediaTexture->incStrong(this); 47 48 m_isCopy = false; 49 m_outlineSize = 0; 50 XLOG("Creating Media Layer %p", this); 51 } 52 53 MediaLayer::MediaLayer(const MediaLayer& layer) : LayerAndroid(layer) 54 { 55 m_mediaTexture = layer.m_mediaTexture; 56 m_mediaTexture->incStrong(this); 57 58 m_isCopy = true; 59 m_outlineSize = layer.m_outlineSize; 60 XLOG("Creating Media Layer Copy %p -> %p", &layer, this); 61 } 62 63 MediaLayer::~MediaLayer() 64 { 65 XLOG("Deleting Media Layer"); 66 m_mediaTexture->decStrong(this); 67 } 68 69 bool MediaLayer::drawGL() 70 { 71 FloatRect clippingRect = TilesManager::instance()->shader()->rectInScreenCoord(drawClip()); 72 TilesManager::instance()->shader()->clip(clippingRect); 73 74 // when the plugin gains focus webkit applies an outline to the 75 // widget, which causes the layer to expand to accommodate the 76 // outline. Therefore, we shrink the rect by the outline's dimensions 77 // to ensure the plugin does not draw outside of its bounds. 78 SkRect mediaBounds; 79 mediaBounds.set(0, 0, getSize().width(), getSize().height()); 80 mediaBounds.inset(m_outlineSize, m_outlineSize); 81 82 // check to see if we need to create a content or video texture 83 m_mediaTexture->initNativeWindowIfNeeded(); 84 85 // the layer's shader draws the content inverted so we must undo 86 // that change in the transformation matrix 87 TransformationMatrix m = m_drawTransform; 88 if (!m_mediaTexture->isContentInverted()) { 89 m.flipY(); 90 m.translate(0, -getSize().height()); 91 } 92 93 // draw any content or video if present 94 m_mediaTexture->draw(m, m_drawTransform, mediaBounds); 95 96 return drawChildrenGL(); 97 } 98 99 ANativeWindow* MediaLayer::acquireNativeWindowForContent() 100 { 101 return m_mediaTexture->getNativeWindowForContent(); 102 } 103 104 105 ANativeWindow* MediaLayer::acquireNativeWindowForVideo() 106 { 107 return m_mediaTexture->requestNativeWindowForVideo(); 108 } 109 110 void MediaLayer::setWindowDimensionsForVideo(const ANativeWindow* window, const SkRect& dimensions) 111 { 112 //TODO validate that the dimensions do not exceed the plugin's bounds 113 m_mediaTexture->setDimensions(window, dimensions); 114 } 115 116 void MediaLayer::releaseNativeWindowForVideo(ANativeWindow* window) 117 { 118 m_mediaTexture->releaseNativeWindow(window); 119 } 120 121 void MediaLayer::setFramerateCallback(const ANativeWindow* window, FramerateCallbackProc callback) 122 { 123 m_mediaTexture->setFramerateCallback(window, callback); 124 } 125 126 } // namespace WebCore 127 128 #endif // USE(ACCELERATED_COMPOSITING) 129