diff options
Diffstat (limited to 'Source/WebCore/platform')
39 files changed, 323 insertions, 936 deletions
diff --git a/Source/WebCore/platform/GeolocationService.h b/Source/WebCore/platform/GeolocationService.h index 27be6c3..1045bb3 100644 --- a/Source/WebCore/platform/GeolocationService.h +++ b/Source/WebCore/platform/GeolocationService.h @@ -48,12 +48,7 @@ public: static GeolocationService* create(GeolocationServiceClient*); virtual ~GeolocationService() { } -#if PLATFORM(ANDROID) - // TODO: Upstream to webkit.org. See https://bugs.webkit.org/show_bug.cgi?id=34082 - virtual bool startUpdating(PositionOptions*, bool suspend) { return false; } -#else virtual bool startUpdating(PositionOptions*) { return false; } -#endif virtual void stopUpdating() { } virtual void suspend() { } diff --git a/Source/WebCore/platform/android/GeolocationServiceAndroid.cpp b/Source/WebCore/platform/android/GeolocationServiceAndroid.cpp deleted file mode 100644 index 0f07722..0000000 --- a/Source/WebCore/platform/android/GeolocationServiceAndroid.cpp +++ /dev/null @@ -1,204 +0,0 @@ -/* - * Copyright 2009, The Android Open Source Project - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY - * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include "config.h" -#include "GeolocationServiceAndroid.h" - -#include "Geolocation.h" -#include "GeolocationServiceBridge.h" -#include "Geoposition.h" -#include "PositionError.h" -#include "PositionOptions.h" - -#if PLATFORM(ANDROID) -// Required for sim-eng build -#include <math.h> -#endif -#include <wtf/CurrentTime.h> - -using JSC::Bindings::getJNIEnv; -using namespace std; - -namespace WebCore { - -// GeolocationServiceAndroid is the Android implmentation of Geolocation -// service. Each object of this class owns an object of type -// GeolocationServiceBridge, which in turn owns a Java GeolocationService -// object. Therefore, there is a 1:1 mapping between Geolocation, -// GeolocationServiceAndroid, GeolocationServiceBridge and Java -// GeolocationService objects. In the case where multiple Geolocation objects -// exist simultaneously, the corresponsing Java GeolocationService objects all -// register with the platform location service. It is the platform service that -// handles making sure that updates are passed to all Geolocation objects. -GeolocationService* GeolocationServiceAndroid::create(GeolocationServiceClient* client) -{ - return new GeolocationServiceAndroid(client); -} - -GeolocationService::FactoryFunction* GeolocationService::s_factoryFunction = &GeolocationServiceAndroid::create; - -GeolocationServiceAndroid::GeolocationServiceAndroid(GeolocationServiceClient* client) - : GeolocationService(client) - , m_timer(this, &GeolocationServiceAndroid::timerFired) - , m_javaBridge(0) -{ -} - -// ANDROID -// TODO: Upstream to webkit.org. See https://bugs.webkit.org/show_bug.cgi?id=34082 -bool GeolocationServiceAndroid::startUpdating(PositionOptions* options, bool suspend) -{ - // ANDROID - // This is an ugly hack. A correct fix would require a change to WebCore, - // but this isn't worth the effort as we're in the process of switching to a - // client-based implementation. See https://bugs.webkit.org/show_bug.cgi?id=40373 - Frame* frame = reinterpret_cast<Geolocation*>(geolocationServiceClient())->frame(); - if (!frame) - return false; - - // This method is called every time a new watch or one-shot position request - // is started. If we already have a position or an error, call back - // immediately. - if (m_lastPosition || m_lastError) { - ASSERT(m_javaBridge); - m_timer.startOneShot(0); - } - - // Lazilly create the Java object. - bool haveJavaBridge = m_javaBridge; - if (!haveJavaBridge) - m_javaBridge.set(new GeolocationServiceBridge(this, frame)); - ASSERT(m_javaBridge); - - // On Android, high power == GPS. Set whether to use GPS before we start the - // implementation. - ASSERT(options); - if (options->enableHighAccuracy()) - m_javaBridge->setEnableGps(true); - - // We need only start the service when it's first created. - if (!haveJavaBridge) { - // If the browser is paused, don't start the service. It will be started - // when we get the call to resume. - // ANDROID - // TODO: Upstream to webkit.org. See https://bugs.webkit.org/show_bug.cgi?id=34082 - if (!suspend) - return m_javaBridge->start(); - } - - return true; -} - -void GeolocationServiceAndroid::stopUpdating() -{ - // Called when the Geolocation object has no watches or one shots in - // progress. This may be called repeatedly. - m_javaBridge.clear(); - // Reset last position and error to make sure that we always try to get a - // new position from the system service when a request is first made. - m_lastPosition = 0; - m_lastError = 0; - // remove the pending timer - if (m_timer.isActive()) - m_timer.stop(); -} - -void GeolocationServiceAndroid::suspend() -{ - if (m_javaBridge) - m_javaBridge->stop(); -} - -void GeolocationServiceAndroid::resume() -{ - if (m_javaBridge) - m_javaBridge->start(); -} - -// Note that there is no guarantee that subsequent calls to this method offer a -// more accurate or updated position. -void GeolocationServiceAndroid::newPositionAvailable(PassRefPtr<Geoposition> position) -{ - ASSERT(position); - if (!m_lastPosition - || isPositionMovement(m_lastPosition.get(), position.get()) - || isPositionMoreAccurate(m_lastPosition.get(), position.get()) - || isPositionMoreTimely(m_lastPosition.get(), position.get())) { - m_lastPosition = position; - // Remove the last error. - m_lastError = 0; - positionChanged(); - } -} - -void GeolocationServiceAndroid::newErrorAvailable(PassRefPtr<PositionError> error) -{ - ASSERT(error); - // We leave the last position - m_lastError = error; - errorOccurred(); -} - -void GeolocationServiceAndroid::timerFired(Timer<GeolocationServiceAndroid>* timer) -{ - ASSERT(&m_timer == timer); - ASSERT(m_lastPosition || m_lastError); - if (m_lastPosition) - positionChanged(); - else if (m_lastError) - errorOccurred(); -} - -bool GeolocationServiceAndroid::isPositionMovement(Geoposition* position1, Geoposition* position2) -{ - ASSERT(position1 && position2); - // For the small distances in which we are likely concerned, it's reasonable - // to approximate the distance between the two positions as the sum of the - // differences in latitude and longitude. - double delta = fabs(position1->coords()->latitude() - position2->coords()->latitude()) - + fabs(position1->coords()->longitude() - position2->coords()->longitude()); - // Approximate conversion from degrees of arc to metres. - delta *= 60 * 1852; - // The threshold is when the distance between the two positions exceeds the - // worse (larger) of the two accuracies. - int maxAccuracy = max(position1->coords()->accuracy(), position2->coords()->accuracy()); - return delta > maxAccuracy; -} - -bool GeolocationServiceAndroid::isPositionMoreAccurate(Geoposition* position1, Geoposition* position2) -{ - ASSERT(position1 && position2); - return position2->coords()->accuracy() < position1->coords()->accuracy(); -} - -bool GeolocationServiceAndroid::isPositionMoreTimely(Geoposition* position1, Geoposition* position2) -{ - ASSERT(position1 && position2); - DOMTimeStamp currentTime = convertSecondsToDOMTimeStamp(WTF::currentTime()); - DOMTimeStamp maximumAge = convertSecondsToDOMTimeStamp(10 * 60); // 10 minutes - return currentTime - position1->timestamp() > maximumAge; -} - -} // namespace WebCore diff --git a/Source/WebCore/platform/android/GeolocationServiceAndroid.h b/Source/WebCore/platform/android/GeolocationServiceAndroid.h deleted file mode 100644 index 72532f6..0000000 --- a/Source/WebCore/platform/android/GeolocationServiceAndroid.h +++ /dev/null @@ -1,79 +0,0 @@ -/* - * Copyright 2009, The Android Open Source Project - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY - * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#ifndef GeolocationServiceAndroid_h -#define GeolocationServiceAndroid_h - -#include "GeolocationService.h" -#include "Timer.h" -#include <wtf/OwnPtr.h> -#include <wtf/PassRefPtr.h> -#include <wtf/RefPtr.h> - -namespace WebCore { - -// The GeolocationServiceBridge is the bridge to the Java implementation of -// the Geolocation service. It is an implementation detail of -// GeolocationServiceAndroid. -class GeolocationServiceBridge; - -class GeolocationServiceAndroid : public GeolocationService { -public: - static GeolocationService* create(GeolocationServiceClient*); - - virtual ~GeolocationServiceAndroid() { }; - - // ANDROID - // TODO: Upstream to webkit.org. See https://bugs.webkit.org/show_bug.cgi?id=34082 - virtual bool startUpdating(PositionOptions*, bool suspend); - virtual void stopUpdating(); - - virtual Geoposition* lastPosition() const { return m_lastPosition.get(); } - virtual PositionError* lastError() const { return m_lastError.get(); } - - virtual void suspend(); - virtual void resume(); - - // Android-specific - void newPositionAvailable(PassRefPtr<Geoposition>); - void newErrorAvailable(PassRefPtr<PositionError>); - void timerFired(Timer<GeolocationServiceAndroid>* timer); - -private: - GeolocationServiceAndroid(GeolocationServiceClient*); - - static bool isPositionMovement(Geoposition* position1, Geoposition* position2); - static bool isPositionMoreAccurate(Geoposition* position1, Geoposition* position2); - static bool isPositionMoreTimely(Geoposition* position1, Geoposition* position2); - - Timer<GeolocationServiceAndroid> m_timer; - RefPtr<Geoposition> m_lastPosition; - RefPtr<PositionError> m_lastError; - OwnPtr<GeolocationServiceBridge> m_javaBridge; -}; - -} // namespace WebCore - -#endif // GeolocationServiceAndroid_h diff --git a/Source/WebCore/platform/android/GeolocationServiceBridge.cpp b/Source/WebCore/platform/android/GeolocationServiceBridge.cpp deleted file mode 100644 index 697b63b..0000000 --- a/Source/WebCore/platform/android/GeolocationServiceBridge.cpp +++ /dev/null @@ -1,246 +0,0 @@ -/* - * Copyright 2009, The Android Open Source Project - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY - * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include "config.h" -#include "GeolocationServiceBridge.h" - -#include "Frame.h" -#include "GeolocationServiceAndroid.h" -#include "Geoposition.h" -#include "PositionError.h" -#include "WebViewCore.h" -#include <JNIHelp.h> - -namespace WebCore { - -using JSC::Bindings::getJNIEnv; - -static const char* javaGeolocationServiceClassName = "android/webkit/GeolocationService"; -enum javaGeolocationServiceClassMethods { - GeolocationServiceMethodInit = 0, - GeolocationServiceMethodStart, - GeolocationServiceMethodStop, - GeolocationServiceMethodSetEnableGps, - GeolocationServiceMethodCount, -}; -static jmethodID javaGeolocationServiceClassMethodIDs[GeolocationServiceMethodCount]; - -static const JNINativeMethod javaGeolocationServiceClassNativeMethods[] = { - { "nativeNewLocationAvailable", "(JLandroid/location/Location;)V", - (void*) GeolocationServiceBridge::newLocationAvailable }, - { "nativeNewErrorAvailable", "(JLjava/lang/String;)V", - (void*) GeolocationServiceBridge::newErrorAvailable } -}; - -static const char *javaLocationClassName = "android/location/Location"; -enum javaLocationClassMethods { - LocationMethodGetLatitude = 0, - LocationMethodGetLongitude, - LocationMethodHasAltitude, - LocationMethodGetAltitude, - LocationMethodHasAccuracy, - LocationMethodGetAccuracy, - LocationMethodHasBearing, - LocationMethodGetBearing, - LocationMethodHasSpeed, - LocationMethodGetSpeed, - LocationMethodGetTime, - LocationMethodCount, -}; -static jmethodID javaLocationClassMethodIDs[LocationMethodCount]; - -GeolocationServiceBridge::GeolocationServiceBridge(ListenerInterface* listener, Frame* frame) - : m_listener(listener) - , m_javaGeolocationServiceObject(0) -{ - ASSERT(m_listener); - startJavaImplementation(frame); -} - -GeolocationServiceBridge::~GeolocationServiceBridge() -{ - stop(); - stopJavaImplementation(); -} - -bool GeolocationServiceBridge::start() -{ - if (!m_javaGeolocationServiceObject) - return false; - return getJNIEnv()->CallBooleanMethod(m_javaGeolocationServiceObject, - javaGeolocationServiceClassMethodIDs[GeolocationServiceMethodStart]); -} - -void GeolocationServiceBridge::stop() -{ - if (!m_javaGeolocationServiceObject) - return; - getJNIEnv()->CallVoidMethod(m_javaGeolocationServiceObject, - javaGeolocationServiceClassMethodIDs[GeolocationServiceMethodStop]); -} - -void GeolocationServiceBridge::setEnableGps(bool enable) -{ - if (!m_javaGeolocationServiceObject) - return; - getJNIEnv()->CallVoidMethod(m_javaGeolocationServiceObject, - javaGeolocationServiceClassMethodIDs[GeolocationServiceMethodSetEnableGps], - enable); -} - -void GeolocationServiceBridge::newLocationAvailable(JNIEnv* env, jclass, jlong nativeObject, jobject location) -{ - ASSERT(nativeObject); - ASSERT(location); - GeolocationServiceBridge* object = reinterpret_cast<GeolocationServiceBridge*>(nativeObject); - object->m_listener->newPositionAvailable(toGeoposition(env, location)); -} - -void GeolocationServiceBridge::newErrorAvailable(JNIEnv* env, jclass, jlong nativeObject, jstring message) -{ - GeolocationServiceBridge* object = reinterpret_cast<GeolocationServiceBridge*>(nativeObject); - RefPtr<PositionError> error = - PositionError::create(PositionError::POSITION_UNAVAILABLE, android::jstringToWtfString(env, message)); - object->m_listener->newErrorAvailable(error.release()); -} - -PassRefPtr<Geoposition> GeolocationServiceBridge::toGeoposition(JNIEnv *env, const jobject &location) -{ - // Altitude is optional and may not be supplied. - bool hasAltitude = - env->CallBooleanMethod(location, javaLocationClassMethodIDs[LocationMethodHasAltitude]); - double Altitude = - hasAltitude ? - env->CallDoubleMethod(location, javaLocationClassMethodIDs[LocationMethodGetAltitude]) : - 0.0; - // Accuracy is required, but is not supplied by the emulator. - double Accuracy = - env->CallBooleanMethod(location, javaLocationClassMethodIDs[LocationMethodHasAccuracy]) ? - env->CallFloatMethod(location, javaLocationClassMethodIDs[LocationMethodGetAccuracy]) : - 0.0; - // heading is optional and may not be supplied. - bool hasHeading = - env->CallBooleanMethod(location, javaLocationClassMethodIDs[LocationMethodHasBearing]); - double heading = - hasHeading ? - env->CallFloatMethod(location, javaLocationClassMethodIDs[LocationMethodGetBearing]) : - 0.0; - // speed is optional and may not be supplied. - bool hasSpeed = - env->CallBooleanMethod(location, javaLocationClassMethodIDs[LocationMethodHasSpeed]); - double speed = - hasSpeed ? - env->CallFloatMethod(location, javaLocationClassMethodIDs[LocationMethodGetSpeed]) : - 0.0; - - RefPtr<Coordinates> newCoordinates = WebCore::Coordinates::create( - env->CallDoubleMethod(location, javaLocationClassMethodIDs[LocationMethodGetLatitude]), - env->CallDoubleMethod(location, javaLocationClassMethodIDs[LocationMethodGetLongitude]), - hasAltitude, Altitude, - Accuracy, - false, 0.0, // AltitudeAccuracy not provided. - hasHeading, heading, - hasSpeed, speed); - - return WebCore::Geoposition::create( - newCoordinates.release(), - env->CallLongMethod(location, javaLocationClassMethodIDs[LocationMethodGetTime])); -} - -void GeolocationServiceBridge::startJavaImplementation(Frame* frame) -{ - JNIEnv* env = getJNIEnv(); - - // Get the Java GeolocationService class. - jclass javaGeolocationServiceClass = env->FindClass(javaGeolocationServiceClassName); - ASSERT(javaGeolocationServiceClass); - - // Set up the methods we wish to call on the Java GeolocationService class. - javaGeolocationServiceClassMethodIDs[GeolocationServiceMethodInit] = - env->GetMethodID(javaGeolocationServiceClass, "<init>", "(Landroid/content/Context;J)V"); - javaGeolocationServiceClassMethodIDs[GeolocationServiceMethodStart] = - env->GetMethodID(javaGeolocationServiceClass, "start", "()Z"); - javaGeolocationServiceClassMethodIDs[GeolocationServiceMethodStop] = - env->GetMethodID(javaGeolocationServiceClass, "stop", "()V"); - javaGeolocationServiceClassMethodIDs[GeolocationServiceMethodSetEnableGps] = - env->GetMethodID(javaGeolocationServiceClass, "setEnableGps", "(Z)V"); - - // Create the Java GeolocationService object. - jobject context = android::WebViewCore::getWebViewCore(frame->view())->getContext(); - if (!context) - return; - jlong nativeObject = reinterpret_cast<jlong>(this); - jobject object = env->NewObject(javaGeolocationServiceClass, - javaGeolocationServiceClassMethodIDs[GeolocationServiceMethodInit], - context, - nativeObject); - - m_javaGeolocationServiceObject = getJNIEnv()->NewGlobalRef(object); - ASSERT(m_javaGeolocationServiceObject); - - // Register to handle calls to native methods of the Java GeolocationService - // object. We register once only. - static int registered = jniRegisterNativeMethods(env, - javaGeolocationServiceClassName, - javaGeolocationServiceClassNativeMethods, - NELEM(javaGeolocationServiceClassNativeMethods)); - ASSERT(registered == JNI_OK); - - // Set up the methods we wish to call on the Java Location class. - jclass javaLocationClass = env->FindClass(javaLocationClassName); - ASSERT(javaLocationClass); - javaLocationClassMethodIDs[LocationMethodGetLatitude] = - env->GetMethodID(javaLocationClass, "getLatitude", "()D"); - javaLocationClassMethodIDs[LocationMethodGetLongitude] = - env->GetMethodID(javaLocationClass, "getLongitude", "()D"); - javaLocationClassMethodIDs[LocationMethodHasAltitude] = - env->GetMethodID(javaLocationClass, "hasAltitude", "()Z"); - javaLocationClassMethodIDs[LocationMethodGetAltitude] = - env->GetMethodID(javaLocationClass, "getAltitude", "()D"); - javaLocationClassMethodIDs[LocationMethodHasAccuracy] = - env->GetMethodID(javaLocationClass, "hasAccuracy", "()Z"); - javaLocationClassMethodIDs[LocationMethodGetAccuracy] = - env->GetMethodID(javaLocationClass, "getAccuracy", "()F"); - javaLocationClassMethodIDs[LocationMethodHasBearing] = - env->GetMethodID(javaLocationClass, "hasBearing", "()Z"); - javaLocationClassMethodIDs[LocationMethodGetBearing] = - env->GetMethodID(javaLocationClass, "getBearing", "()F"); - javaLocationClassMethodIDs[LocationMethodHasSpeed] = - env->GetMethodID(javaLocationClass, "hasSpeed", "()Z"); - javaLocationClassMethodIDs[LocationMethodGetSpeed] = - env->GetMethodID(javaLocationClass, "getSpeed", "()F"); - javaLocationClassMethodIDs[LocationMethodGetTime] = - env->GetMethodID(javaLocationClass, "getTime", "()J"); -} - -void GeolocationServiceBridge::stopJavaImplementation() -{ - // Called by GeolocationServiceAndroid on WebKit thread. - if (!m_javaGeolocationServiceObject) - return; - getJNIEnv()->DeleteGlobalRef(m_javaGeolocationServiceObject); -} - -} // namespace WebCore diff --git a/Source/WebCore/platform/android/GeolocationServiceBridge.h b/Source/WebCore/platform/android/GeolocationServiceBridge.h deleted file mode 100644 index 3997d65..0000000 --- a/Source/WebCore/platform/android/GeolocationServiceBridge.h +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Copyright 2009, The Android Open Source Project - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY - * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#ifndef GeolocationServiceBridge_h -#define GeolocationServiceBridge_h - -#include "JNIUtility.h" -#include <wtf/PassRefPtr.h> - -namespace WebCore { - -class Frame; -class GeolocationServiceAndroid; -class Geoposition; - -// GeolocationServiceBridge is the bridge to the Java implementation. It manages -// the lifetime of the Java object. It is an implementation detail of -// GeolocationServiceAndroid. -class GeolocationServiceBridge { -public: - typedef GeolocationServiceAndroid ListenerInterface; - GeolocationServiceBridge(ListenerInterface* listener, Frame* frame); - ~GeolocationServiceBridge(); - - bool start(); - void stop(); - void setEnableGps(bool enable); - - // Static wrapper functions to hide JNI nastiness. - static void newLocationAvailable(JNIEnv *env, jclass, jlong nativeObject, jobject location); - static void newErrorAvailable(JNIEnv *env, jclass, jlong nativeObject, jstring message); - static PassRefPtr<Geoposition> toGeoposition(JNIEnv *env, const jobject &location); - -private: - void startJavaImplementation(Frame* frame); - void stopJavaImplementation(); - - ListenerInterface* m_listener; - jobject m_javaGeolocationServiceObject; -}; - -} // namespace WebCore - -#endif // GeolocationServiceBridge_h diff --git a/Source/WebCore/platform/android/PlatformBridge.h b/Source/WebCore/platform/android/PlatformBridge.h index a4c1048..5af5d2d 100644 --- a/Source/WebCore/platform/android/PlatformBridge.h +++ b/Source/WebCore/platform/android/PlatformBridge.h @@ -124,10 +124,6 @@ public: }; static String* globalLocalizedName(rawResId resId); - // Whether the WebView is paused. - // ANDROID - // TODO: Upstream to webkit.org. See https://bugs.webkit.org/show_bug.cgi?id=34082 - static bool isWebViewPaused(const FrameView*); static String resolveFilePathForContentUri(const String&); static int screenDepth(); @@ -136,7 +132,7 @@ public: // Update the viewport meta data. static void updateViewport(FrameView*); - static void updateTextfield(FrameView*, Node*, bool changeToPassword, const WTF::String& text); + static void updateTextfield(FrameView*, Node*, const WTF::String& text); static void setScrollPosition(ScrollView*, int x, int y); diff --git a/Source/WebCore/platform/graphics/android/GLWebViewState.cpp b/Source/WebCore/platform/graphics/android/GLWebViewState.cpp index 55c4eec..20f5abf 100644 --- a/Source/WebCore/platform/graphics/android/GLWebViewState.cpp +++ b/Source/WebCore/platform/graphics/android/GLWebViewState.cpp @@ -355,7 +355,7 @@ int GLWebViewState::drawGL(IntRect& invScreenRect, SkRect& visibleContentRect, if (scale < MIN_SCALE_WARNING || scale > MAX_SCALE_WARNING) { ALOGW("WARNING, scale seems corrupted after update: %e", scale); - scale = 1.0f; // WORKAROUND for corrupted scale: use 1.0 + CRASH(); } double currentTime = setupDrawing(invScreenRect, visibleContentRect, screenRect, diff --git a/Source/WebCore/platform/graphics/android/GraphicsLayerAndroid.cpp b/Source/WebCore/platform/graphics/android/GraphicsLayerAndroid.cpp index 779dba5..5fe9a1f 100644 --- a/Source/WebCore/platform/graphics/android/GraphicsLayerAndroid.cpp +++ b/Source/WebCore/platform/graphics/android/GraphicsLayerAndroid.cpp @@ -853,6 +853,7 @@ bool GraphicsLayerAndroid::paintContext(LayerAndroid* layer, if (!layer) return false; + TRACE_METHOD(); SkPicture* picture = paintPicture(rect); if (!picture) return false; diff --git a/Source/WebCore/platform/graphics/android/context/GraphicsOperationCollection.cpp b/Source/WebCore/platform/graphics/android/context/GraphicsOperationCollection.cpp index 9e6208d..295c106 100644 --- a/Source/WebCore/platform/graphics/android/context/GraphicsOperationCollection.cpp +++ b/Source/WebCore/platform/graphics/android/context/GraphicsOperationCollection.cpp @@ -13,8 +13,7 @@ namespace WebCore { -GraphicsOperationCollection::GraphicsOperationCollection(const IntRect& drawArea) - : m_drawArea(drawArea) +GraphicsOperationCollection::GraphicsOperationCollection() { } @@ -26,12 +25,8 @@ GraphicsOperationCollection::~GraphicsOperationCollection() void GraphicsOperationCollection::apply(PlatformGraphicsContext* context) { - ALOGD("\nApply GraphicsOperationCollection %x, %d operations", this, m_operations.size()); - for (unsigned int i = 0; i < m_operations.size(); i++) { - ALOGD("[%d] (%x) %s %s", i, this, m_operations[i]->name().ascii().data(), - m_operations[i]->parameters().ascii().data()); + for (unsigned int i = 0; i < m_operations.size(); i++) m_operations[i]->apply(context); - } } void GraphicsOperationCollection::append(GraphicsOperation::Operation* operation) @@ -44,20 +39,6 @@ bool GraphicsOperationCollection::isEmpty() return !m_operations.size(); } -AutoGraphicsOperationCollection::AutoGraphicsOperationCollection(const IntRect& area) -{ - m_graphicsOperationCollection = new GraphicsOperationCollection(area); - m_platformGraphicsContext = new PlatformGraphicsContextRecording(m_graphicsOperationCollection); - m_graphicsContext = new GraphicsContext(m_platformGraphicsContext); -} - -AutoGraphicsOperationCollection::~AutoGraphicsOperationCollection() -{ - SkSafeUnref(m_graphicsOperationCollection); - delete m_graphicsContext; - delete m_platformGraphicsContext; -} - } // namespace WebCore #endif // USE(ACCELERATED_COMPOSITING) diff --git a/Source/WebCore/platform/graphics/android/context/GraphicsOperationCollection.h b/Source/WebCore/platform/graphics/android/context/GraphicsOperationCollection.h index 9d7b530..a8696fe 100644 --- a/Source/WebCore/platform/graphics/android/context/GraphicsOperationCollection.h +++ b/Source/WebCore/platform/graphics/android/context/GraphicsOperationCollection.h @@ -39,7 +39,7 @@ class PlatformGraphicsContext; class GraphicsOperationCollection : public SkRefCnt { public: - GraphicsOperationCollection(const IntRect& drawArea); + GraphicsOperationCollection(); ~GraphicsOperationCollection(); void apply(PlatformGraphicsContext* context); @@ -48,23 +48,9 @@ public: bool isEmpty(); private: - IntRect m_drawArea; Vector<GraphicsOperation::Operation*> m_operations; }; -class AutoGraphicsOperationCollection { -public: - AutoGraphicsOperationCollection(const IntRect& area); - ~AutoGraphicsOperationCollection(); - GraphicsContext* context() { return m_graphicsContext; } - GraphicsOperationCollection* picture() { return m_graphicsOperationCollection; } - -private: - GraphicsOperationCollection* m_graphicsOperationCollection; - PlatformGraphicsContext* m_platformGraphicsContext; - GraphicsContext* m_graphicsContext; -}; - } #endif // USE(ACCELERATED_COMPOSITING) diff --git a/Source/WebCore/platform/graphics/android/context/PlatformGraphicsContext.cpp b/Source/WebCore/platform/graphics/android/context/PlatformGraphicsContext.cpp index ce9ce5a..3b37693 100644 --- a/Source/WebCore/platform/graphics/android/context/PlatformGraphicsContext.cpp +++ b/Source/WebCore/platform/graphics/android/context/PlatformGraphicsContext.cpp @@ -82,6 +82,8 @@ static bool setBitmapDash(SkPaint* paint, int width) { s->setLocalMatrix(matrix); paint->setShader(s)->unref(); + paint->setFilterBitmap(true); + paint->setAntiAlias(true); return true; } diff --git a/Source/WebCore/platform/graphics/android/fonts/FontAndroid.cpp b/Source/WebCore/platform/graphics/android/fonts/FontAndroid.cpp index 7bed5bb..d59674b 100644 --- a/Source/WebCore/platform/graphics/android/fonts/FontAndroid.cpp +++ b/Source/WebCore/platform/graphics/android/fonts/FontAndroid.cpp @@ -45,6 +45,7 @@ #include "SkTypeface.h" #include "SkUtils.h" #include "TextRun.h" +#include "SkTypeface_android.h" #ifdef SUPPORT_COMPLEX_SCRIPTS #include "HarfbuzzSkia.h" @@ -461,26 +462,8 @@ public: } private: - enum CustomScript { - Bengali, - Devanagari, - Hebrew, - HebrewBold, - Kannada, - Malayalam, - Naskh, - Tamil, - TamilBold, - Telugu, - Thai, - NUM_SCRIPTS - }; - - static const char* paths[NUM_SCRIPTS]; - void setupFontForScriptRun(); - const FontPlatformData* setupComplexFont(CustomScript script, - const FontPlatformData& platformData); + const FontPlatformData* setupComplexFont(HB_Script script, const FontPlatformData& platformData); HB_FontRec* allocHarfbuzzFont(); void deleteGlyphArrays(); void createGlyphArrays(int); @@ -522,22 +505,6 @@ private: unsigned m_letterSpacing; // pixels to be added after each glyph. }; - -// Indexed using enum CustomScript -const char* TextRunWalker::paths[] = { - "/system/fonts/Lohit-Bengali.ttf", - "/system/fonts/DroidSansDevanagari-Regular.ttf", - "/system/fonts/DroidSansHebrew-Regular.ttf", - "/system/fonts/DroidSansHebrew-Bold.ttf", - "/system/fonts/Lohit-Kannada.ttf", - "/system/fonts/AnjaliNewLipi-light.ttf", - "/system/fonts/DroidNaskh-Regular.ttf", - "/system/fonts/DroidSansTamil-Regular.ttf", - "/system/fonts/DroidSansTamil-Bold.ttf", - "/system/fonts/Lohit-Telugu.ttf", - "/system/fonts/DroidSansThai.ttf" -}; - TextRunWalker::TextRunWalker(const TextRun& run, int startingX, int startingY, const Font* font) : m_font(font) , m_startingX(startingX) @@ -692,8 +659,7 @@ void TextRunWalker::setWordAndLetterSpacing(int wordSpacingAdjustment, } const FontPlatformData* TextRunWalker::setupComplexFont( - CustomScript script, - const FontPlatformData& platformData) + HB_Script script, const FontPlatformData& platformData) { static FallbackHash fallbackPlatformData; @@ -703,15 +669,19 @@ const FontPlatformData* TextRunWalker::setupComplexFont( // italic, then bold italic. additional fake style bits can be added. int scriptStyleIndex = script; if (platformData.isFakeBold()) - scriptStyleIndex += NUM_SCRIPTS; + scriptStyleIndex += HB_ScriptCount; if (platformData.isFakeItalic()) - scriptStyleIndex += NUM_SCRIPTS << 1; + scriptStyleIndex += HB_ScriptCount << 1; FallbackFontKey key(scriptStyleIndex, platformData.size()); FontPlatformData* newPlatformData = 0; if (!fallbackPlatformData.contains(key)) { - SkTypeface* typeface = SkTypeface::CreateFromFile(paths[script]); + SkTypeface::Style currentStyle = SkTypeface::kNormal; + if (platformData.typeface()) + currentStyle = platformData.typeface()->style(); + SkTypeface* typeface = SkCreateTypefaceForScript(script, currentStyle, + SkPaint::kElegant_Variant); newPlatformData = new FontPlatformData(platformData, typeface); SkSafeUnref(typeface); fallbackPlatformData.set(key, newPlatformData); @@ -729,61 +699,8 @@ void TextRunWalker::setupFontForScriptRun() const FontData* fontData = m_font->glyphDataForCharacter(m_run[0], false).fontData; const FontPlatformData& platformData = fontData->fontDataForCharacter(' ')->platformData(); - const FontPlatformData* complexPlatformData = &platformData; - - switch (m_item.item.script) { - case HB_Script_Bengali: - complexPlatformData = setupComplexFont(Bengali, platformData); - break; - case HB_Script_Devanagari: - complexPlatformData = setupComplexFont(Devanagari, platformData); - break; - case HB_Script_Hebrew: - switch (platformData.typeface()->style()) { - case SkTypeface::kBold: - case SkTypeface::kBoldItalic: - complexPlatformData = setupComplexFont(HebrewBold, platformData); - break; - case SkTypeface::kNormal: - case SkTypeface::kItalic: - default: - complexPlatformData = setupComplexFont(Hebrew, platformData); - break; - } - break; - case HB_Script_Kannada: - complexPlatformData = setupComplexFont(Kannada, platformData); - break; - case HB_Script_Malayalam: - complexPlatformData = setupComplexFont(Malayalam, platformData); - break; - case HB_Script_Arabic: - complexPlatformData = setupComplexFont(Naskh, platformData); - break; - case HB_Script_Tamil: - switch (platformData.typeface()->style()) { - case SkTypeface::kBold: - case SkTypeface::kBoldItalic: - complexPlatformData = setupComplexFont(TamilBold, platformData); - break; - case SkTypeface::kNormal: - case SkTypeface::kItalic: - default: - complexPlatformData = setupComplexFont(Tamil, platformData); - break; - } - break; - case HB_Script_Telugu: - complexPlatformData = setupComplexFont(Telugu, platformData); - break; - case HB_Script_Thai: - complexPlatformData = setupComplexFont(Thai, platformData); - break; - default: - // HB_Script_Common; includes Ethiopic - complexPlatformData = &platformData; - break; - } + const FontPlatformData* complexPlatformData = setupComplexFont(m_item.item.script, platformData); + m_item.face = complexPlatformData->harfbuzzFace(); m_item.font->userData = const_cast<FontPlatformData*>(complexPlatformData); diff --git a/Source/WebCore/platform/graphics/android/layers/DumpLayer.cpp b/Source/WebCore/platform/graphics/android/layers/DumpLayer.cpp index 5551965..d827c44 100644 --- a/Source/WebCore/platform/graphics/android/layers/DumpLayer.cpp +++ b/Source/WebCore/platform/graphics/android/layers/DumpLayer.cpp @@ -3,79 +3,87 @@ #if USE(ACCELERATED_COMPOSITING) +#define WRITE_VAL(format, ...) (snprintf(m_valueBuffer, BUF_SIZE, format, __VA_ARGS__), writeEntry(label, m_valueBuffer)) + namespace WebCore { -void lwrite(FILE* file, const char* str) +void LayerDumper::writeIntVal(const char* label, int value) { - fwrite(str, sizeof(char), strlen(str), file); + WRITE_VAL("%d", value); } -void writeIndent(FILE* file, int indentLevel) +void LayerDumper::writeHexVal(const char* label, int value) { - if (indentLevel) - fprintf(file, "%*s", indentLevel*2, " "); + WRITE_VAL("%x", value); } -void writeln(FILE* file, int indentLevel, const char* str) +void LayerDumper::writeFloatVal(const char* label, float value) { - writeIndent(file, indentLevel); - lwrite(file, str); - lwrite(file, "\n"); + WRITE_VAL("%.3f", value); } -void writeIntVal(FILE* file, int indentLevel, const char* str, int value) +void LayerDumper::writePoint(const char* label, SkPoint point) { - writeIndent(file, indentLevel); - fprintf(file, "%s = %d;\n", str, value); + WRITE_VAL("{ x = %.3f; y = %.3f; }", point.fX, point.fY); } -void writeHexVal(FILE* file, int indentLevel, const char* str, int value) +void LayerDumper::writeIntPoint(const char* label, IntPoint point) { - writeIndent(file, indentLevel); - fprintf(file, "%s = %x;\n", str, value); + WRITE_VAL("{ x = %d; y = %d; }", point.x(), point.y()); } -void writeFloatVal(FILE* file, int indentLevel, const char* str, float value) +void LayerDumper::writeSize(const char* label, SkSize size) { - writeIndent(file, indentLevel); - fprintf(file, "%s = %.3f;\n", str, value); + WRITE_VAL("{ w = %.3f; h = %.3f; }", size.width(), size.height()); } -void writePoint(FILE* file, int indentLevel, const char* str, SkPoint point) +void LayerDumper::writeRect(const char* label, SkRect rect) { - writeIndent(file, indentLevel); - fprintf(file, "%s = { x = %.3f; y = %.3f; };\n", str, point.fX, point.fY); + WRITE_VAL("{ x = %.3f; y = %.3f; w = %.3f; h = %.3f; }", + rect.fLeft, rect.fTop, rect.width(), rect.height()); } -void writeIntPoint(FILE* file, int indentLevel, const char* str, IntPoint point) +void LayerDumper::writeMatrix(const char* label, const TransformationMatrix& matrix) { - writeIndent(file, indentLevel); - fprintf(file, "%s = { x = %d; y = %d; };\n", str, point.x(), point.y()); + WRITE_VAL("{ (%.2f,%.2f,%.2f,%.2f),(%.2f,%.2f,%.2f,%.2f)," + "(%.2f,%.2f,%.2f,%.2f),(%.2f,%.2f,%.2f,%.2f) }", + matrix.m11(), matrix.m12(), matrix.m13(), matrix.m14(), + matrix.m21(), matrix.m22(), matrix.m23(), matrix.m24(), + matrix.m31(), matrix.m32(), matrix.m33(), matrix.m34(), + matrix.m41(), matrix.m42(), matrix.m43(), matrix.m44()); } -void writeSize(FILE* file, int indentLevel, const char* str, SkSize size) +void LayerDumper::writeLength(const char* label, SkLength value) { - writeIndent(file, indentLevel); - fprintf(file, "%s = { w = %.3f; h = %.3f; };\n", str, size.width(), size.height()); + if (value.defined()) + WRITE_VAL("{ type = %d; value = %.2f; }", value.type, value.value); + else + writeEntry(label, "<undefined>"); } -void writeRect(FILE* file, int indentLevel, const char* str, SkRect rect) +void FileLayerDumper::beginLayer(const char* className, const LayerAndroid* layerPtr) { - writeIndent(file, indentLevel); - fprintf(file, "%s = { x = %.3f; y = %.3f; w = %.3f; h = %.3f; };\n", - str, rect.fLeft, rect.fTop, rect.width(), rect.height()); + LayerDumper::beginLayer(className, layerPtr); + writeLine("{"); + writeHexVal("layer", (int)layerPtr); } -void writeMatrix(FILE* file, int indentLevel, const char* str, const TransformationMatrix& matrix) +void FileLayerDumper::endLayer() { - writeIndent(file, indentLevel); - fprintf(file, "%s = { (%.2f,%.2f,%.2f,%.2f),(%.2f,%.2f,%.2f,%.2f)," - "(%.2f,%.2f,%.2f,%.2f),(%.2f,%.2f,%.2f,%.2f) };\n", - str, - matrix.m11(), matrix.m12(), matrix.m13(), matrix.m14(), - matrix.m21(), matrix.m22(), matrix.m23(), matrix.m24(), - matrix.m31(), matrix.m32(), matrix.m33(), matrix.m34(), - matrix.m41(), matrix.m42(), matrix.m43(), matrix.m44()); + writeLine("}"); + LayerDumper::endLayer(); +} + +void FileLayerDumper::writeEntry(const char* label, const char* value) +{ + fprintf(m_file, "%*s%s = %s\n", (m_indentLevel + 1) * 2, " ", label, value); +} + +void FileLayerDumper::writeLine(const char* str) +{ + if (m_indentLevel) + fprintf(m_file, "%*s", m_indentLevel * 2, " "); + fprintf(m_file, "%s\n", str); } } // namespace WebCore diff --git a/Source/WebCore/platform/graphics/android/layers/DumpLayer.h b/Source/WebCore/platform/graphics/android/layers/DumpLayer.h index 5b30952..9fd3365 100644 --- a/Source/WebCore/platform/graphics/android/layers/DumpLayer.h +++ b/Source/WebCore/platform/graphics/android/layers/DumpLayer.h @@ -17,7 +17,9 @@ #ifndef DumpLayer_h #define DumpLayer_h +#include "FixedPositioning.h" #include "IntPoint.h" +#include "LayerAndroid.h" #include "SkPoint.h" #include "SkRect.h" #include "SkSize.h" @@ -50,17 +52,59 @@ namespace WebCore { -void lwrite(FILE* file, const char* str); -void writeIndent(FILE* file, int indentLevel); -void writeln(FILE* file, int indentLevel, const char* str); -void writeIntVal(FILE* file, int indentLevel, const char* str, int value); -void writeHexVal(FILE* file, int indentLevel, const char* str, int value); -void writeFloatVal(FILE* file, int indentLevel, const char* str, float value); -void writePoint(FILE* file, int indentLevel, const char* str, SkPoint point); -void writeIntPoint(FILE* file, int indentLevel, const char* str, IntPoint point); -void writeSize(FILE* file, int indentLevel, const char* str, SkSize size); -void writeRect(FILE* file, int indentLevel, const char* str, SkRect rect); -void writeMatrix(FILE* file, int indentLevel, const char* str, const TransformationMatrix& matrix); +class LayerDumper { +public: + LayerDumper(int initialIndentLevel = 0) + : m_indentLevel(initialIndentLevel) + {} + virtual ~LayerDumper() {} + + virtual void beginLayer(const char* className, const LayerAndroid* layerPtr) {} + + virtual void endLayer() {} + + virtual void beginChildren(int childCount) { + m_indentLevel++; + } + virtual void endChildren() { + m_indentLevel--; + } + + void writeIntVal(const char* label, int value); + void writeHexVal(const char* label, int value); + void writeFloatVal(const char* label, float value); + void writePoint(const char* label, SkPoint value); + void writeIntPoint(const char* label, IntPoint value); + void writeSize(const char* label, SkSize value); + void writeRect(const char* label, SkRect value); + void writeMatrix(const char* label, const TransformationMatrix& value); + void writeLength(const char* label, SkLength value); + +protected: + virtual void writeEntry(const char* label, const char* value) = 0; + + int m_indentLevel; + +private: + static const int BUF_SIZE = 4096; + char m_valueBuffer[BUF_SIZE]; +}; + +class FileLayerDumper : public LayerDumper { +public: + FileLayerDumper(FILE* file) + : m_file(file) + {} + + virtual void beginLayer(const char* className, const LayerAndroid* layerPtr); + virtual void endLayer(); +protected: + virtual void writeEntry(const char* label, const char* value); + +private: + void writeLine(const char* str); + FILE* m_file; +}; } diff --git a/Source/WebCore/platform/graphics/android/layers/FixedPositioning.cpp b/Source/WebCore/platform/graphics/android/layers/FixedPositioning.cpp index 82afe8f..aa204f8 100644 --- a/Source/WebCore/platform/graphics/android/layers/FixedPositioning.cpp +++ b/Source/WebCore/platform/graphics/android/layers/FixedPositioning.cpp @@ -86,25 +86,17 @@ void FixedPositioning::contentDraw(SkCanvas* canvas, Layer::PaintStyle style) } } -void writeLength(FILE* file, int indentLevel, const char* str, SkLength length) +void FixedPositioning::dumpLayer(LayerDumper* dumper) const { - if (!length.defined()) - return; - writeIndent(file, indentLevel); - fprintf(file, "%s = { type = %d; value = %.2f; };\n", str, length.type, length.value); -} - -void FixedPositioning::dumpLayer(FILE* file, int indentLevel) const -{ - writeLength(file, indentLevel + 1, "fixedLeft", m_fixedLeft); - writeLength(file, indentLevel + 1, "fixedTop", m_fixedTop); - writeLength(file, indentLevel + 1, "fixedRight", m_fixedRight); - writeLength(file, indentLevel + 1, "fixedBottom", m_fixedBottom); - writeLength(file, indentLevel + 1, "fixedMarginLeft", m_fixedMarginLeft); - writeLength(file, indentLevel + 1, "fixedMarginTop", m_fixedMarginTop); - writeLength(file, indentLevel + 1, "fixedMarginRight", m_fixedMarginRight); - writeLength(file, indentLevel + 1, "fixedMarginBottom", m_fixedMarginBottom); - writeRect(file, indentLevel + 1, "fixedRect", m_fixedRect); + dumper->writeLength("fixedLeft", m_fixedLeft); + dumper->writeLength("fixedTop", m_fixedTop); + dumper->writeLength("fixedRight", m_fixedRight); + dumper->writeLength("fixedBottom", m_fixedBottom); + dumper->writeLength("fixedMarginLeft", m_fixedMarginLeft); + dumper->writeLength("fixedMarginTop", m_fixedMarginTop); + dumper->writeLength("fixedMarginRight", m_fixedMarginRight); + dumper->writeLength("fixedMarginBottom", m_fixedMarginBottom); + dumper->writeRect("fixedRect", m_fixedRect); } BackgroundImagePositioning::BackgroundImagePositioning(LayerAndroid* layer, const BackgroundImagePositioning& position) diff --git a/Source/WebCore/platform/graphics/android/layers/FixedPositioning.h b/Source/WebCore/platform/graphics/android/layers/FixedPositioning.h index e273a25..ac838c8 100644 --- a/Source/WebCore/platform/graphics/android/layers/FixedPositioning.h +++ b/Source/WebCore/platform/graphics/android/layers/FixedPositioning.h @@ -130,7 +130,7 @@ public: void contentDraw(SkCanvas* canvas, Layer::PaintStyle style); - void dumpLayer(FILE*, int indentLevel) const; + void dumpLayer(LayerDumper*) const; // ViewStateSerializer friends friend void android::serializeLayer(LayerAndroid* layer, SkWStream* stream); diff --git a/Source/WebCore/platform/graphics/android/layers/IFrameLayerAndroid.cpp b/Source/WebCore/platform/graphics/android/layers/IFrameLayerAndroid.cpp index 3532542..4481f55 100644 --- a/Source/WebCore/platform/graphics/android/layers/IFrameLayerAndroid.cpp +++ b/Source/WebCore/platform/graphics/android/layers/IFrameLayerAndroid.cpp @@ -29,10 +29,10 @@ IFrameLayerAndroid* IFrameLayerAndroid::updatePosition(SkRect viewport, return this; } -void IFrameLayerAndroid::dumpLayer(FILE* file, int indentLevel) const +void IFrameLayerAndroid::dumpLayer(LayerDumper* dumper) const { - writeIntVal(file, indentLevel + 1, "m_isIframe", true); - writeIntPoint(file, indentLevel + 1, "m_iframeOffset", m_iframeOffset); + LayerAndroid::dumpLayer(dumper); + dumper->writeIntPoint("m_iframeOffset", m_iframeOffset); } } // namespace WebCore diff --git a/Source/WebCore/platform/graphics/android/layers/IFrameLayerAndroid.h b/Source/WebCore/platform/graphics/android/layers/IFrameLayerAndroid.h index f2fbf49..08e7212 100644 --- a/Source/WebCore/platform/graphics/android/layers/IFrameLayerAndroid.h +++ b/Source/WebCore/platform/graphics/android/layers/IFrameLayerAndroid.h @@ -53,7 +53,7 @@ public: virtual IFrameLayerAndroid* updatePosition(SkRect viewport, IFrameLayerAndroid* parentIframeLayer); - virtual void dumpLayer(FILE*, int indentLevel) const; + virtual void dumpLayer(LayerDumper*) const; const IntPoint& iframeOffset() const { return m_iframeOffset; } diff --git a/Source/WebCore/platform/graphics/android/layers/LayerAndroid.cpp b/Source/WebCore/platform/graphics/android/layers/LayerAndroid.cpp index 228a30e..438d96c 100644 --- a/Source/WebCore/platform/graphics/android/layers/LayerAndroid.cpp +++ b/Source/WebCore/platform/graphics/android/layers/LayerAndroid.cpp @@ -601,7 +601,7 @@ void LayerAndroid::showLayer(int indent) m_clippingRect.width(), m_clippingRect.height()); ALOGD("%s s:%x %s %s (%d) [%d:%x - 0x%x] - %s %s - area (%d, %d, %d, %d) - visible (%d, %d, %d, %d) " "clip (%d, %d, %d, %d) %s %s m_content(%x), pic w: %d h: %d originalLayer: %x %d", - spaces, m_surface, m_haveClip ? "CLIP LAYER" : "", subclassName().ascii().data(), + spaces, m_surface, m_haveClip ? "CLIP LAYER" : "", subclassName(), subclassType(), uniqueId(), this, m_owningLayer, needsTexture() ? "needsTexture" : "", m_imageCRC ? "hasImage" : "", @@ -954,60 +954,42 @@ void LayerAndroid::setFixedPosition(FixedPositioning* position) { m_fixedPosition = position; } -void LayerAndroid::dumpLayer(FILE* file, int indentLevel) const +void LayerAndroid::dumpLayer(LayerDumper* dumper) const { - writeHexVal(file, indentLevel + 1, "layer", (int)this); - writeIntVal(file, indentLevel + 1, "layerId", m_uniqueId); - writeIntVal(file, indentLevel + 1, "haveClip", m_haveClip); - writeIntVal(file, indentLevel + 1, "isFixed", isPositionFixed()); + dumper->writeIntVal("layerId", m_uniqueId); + dumper->writeIntVal("haveClip", m_haveClip); + dumper->writeIntVal("isFixed", isPositionFixed()); - writeFloatVal(file, indentLevel + 1, "opacity", getOpacity()); - writeSize(file, indentLevel + 1, "size", getSize()); - writePoint(file, indentLevel + 1, "position", getPosition()); - writePoint(file, indentLevel + 1, "anchor", getAnchorPoint()); + dumper->writeFloatVal("opacity", getOpacity()); + dumper->writeSize("size", getSize()); + dumper->writePoint("position", getPosition()); + dumper->writePoint("anchor", getAnchorPoint()); - writeMatrix(file, indentLevel + 1, "drawMatrix", m_drawTransform); - writeMatrix(file, indentLevel + 1, "transformMatrix", m_transform); - writeRect(file, indentLevel + 1, "clippingRect", SkRect(m_clippingRect)); + dumper->writeMatrix("drawMatrix", m_drawTransform); + dumper->writeMatrix("transformMatrix", m_transform); + dumper->writeRect("clippingRect", SkRect(m_clippingRect)); if (m_content) { - writeIntVal(file, indentLevel + 1, "m_content.width", m_content->width()); - writeIntVal(file, indentLevel + 1, "m_content.height", m_content->height()); + dumper->writeIntVal("m_content.width", m_content->width()); + dumper->writeIntVal("m_content.height", m_content->height()); } if (m_fixedPosition) - return m_fixedPosition->dumpLayer(file, indentLevel); + m_fixedPosition->dumpLayer(dumper); } -void LayerAndroid::dumpLayers(FILE* file, int indentLevel) const +void LayerAndroid::dumpLayers(LayerDumper* dumper) const { - writeln(file, indentLevel, "{"); - - dumpLayer(file, indentLevel); + dumper->beginLayer(subclassName(), this); + dumpLayer(dumper); + dumper->beginChildren(countChildren()); if (countChildren()) { - writeln(file, indentLevel + 1, "children = ["); - for (int i = 0; i < countChildren(); i++) { - if (i > 0) - writeln(file, indentLevel + 1, ", "); - getChild(i)->dumpLayers(file, indentLevel + 1); - } - writeln(file, indentLevel + 1, "];"); + for (int i = 0; i < countChildren(); i++) + getChild(i)->dumpLayers(dumper); } - writeln(file, indentLevel, "}"); -} - -void LayerAndroid::dumpToLog() const -{ - FILE* file = fopen("/data/data/com.android.browser/layertmp", "w"); - dumpLayers(file, 0); - fclose(file); - file = fopen("/data/data/com.android.browser/layertmp", "r"); - char buffer[512]; - bzero(buffer, sizeof(buffer)); - while (fgets(buffer, sizeof(buffer), file)) - SkDebugf("%s", buffer); - fclose(file); + dumper->endChildren(); + dumper->endLayer(); } LayerAndroid* LayerAndroid::findById(int match) diff --git a/Source/WebCore/platform/graphics/android/layers/LayerAndroid.h b/Source/WebCore/platform/graphics/android/layers/LayerAndroid.h index 41f6420..b28daef 100644 --- a/Source/WebCore/platform/graphics/android/layers/LayerAndroid.h +++ b/Source/WebCore/platform/graphics/android/layers/LayerAndroid.h @@ -73,6 +73,7 @@ class IFrameLayerAndroid; class LayerMergeState; class RenderLayer; class PaintedSurface; +class LayerDumper; class TexturesResult { public: @@ -100,7 +101,7 @@ public: CanvasLayer, BaseLayer } SubclassType; typedef enum { InvalidateNone = 0, InvalidateLayers } InvalidateFlags; - String subclassName() + const char* subclassName() const { switch (subclassType()) { case LayerAndroid::StandardLayer: @@ -195,9 +196,7 @@ public: bool hasAnimations() const; void addDirtyArea(); - virtual void dumpLayer(FILE*, int indentLevel) const; - void dumpLayers(FILE*, int indentLevel) const; - void dumpToLog() const; + void dumpLayers(LayerDumper*) const; virtual IFrameLayerAndroid* updatePosition(SkRect viewport, IFrameLayerAndroid* parentIframeLayer); @@ -292,6 +291,7 @@ public: } protected: + virtual void dumpLayer(LayerDumper*) const; /** Call this with the current viewport (scrolling, zoom) to update the position of the fixed layers. diff --git a/Source/WebCore/platform/graphics/android/layers/PictureLayerContent.cpp b/Source/WebCore/platform/graphics/android/layers/PictureLayerContent.cpp index 4398146..f012c42 100644 --- a/Source/WebCore/platform/graphics/android/layers/PictureLayerContent.cpp +++ b/Source/WebCore/platform/graphics/android/layers/PictureLayerContent.cpp @@ -1,6 +1,10 @@ +#define LOG_TAG "PictureLayerContent" +#define LOG_NDEBUG 1 + #include "config.h" #include "PictureLayerContent.h" +#include "AndroidLog.h" #include "InspectorCanvas.h" #include "SkPicture.h" @@ -90,6 +94,7 @@ void PictureLayerContent::draw(SkCanvas* canvas) if (!m_picture) return; + TRACE_METHOD(); android::Mutex::Autolock lock(m_drawLock); SkRect r = SkRect::MakeWH(width(), height()); canvas->clipRect(r); diff --git a/Source/WebCore/platform/graphics/android/layers/PicturePileLayerContent.cpp b/Source/WebCore/platform/graphics/android/layers/PicturePileLayerContent.cpp index b648e72..5d516af 100644 --- a/Source/WebCore/platform/graphics/android/layers/PicturePileLayerContent.cpp +++ b/Source/WebCore/platform/graphics/android/layers/PicturePileLayerContent.cpp @@ -1,6 +1,10 @@ +#define LOG_TAG "PicturePileLayerContent" +#define LOG_NDEBUG 1 + #include "config.h" #include "PicturePileLayerContent.h" +#include "AndroidLog.h" #include "SkCanvas.h" #include "SkPicture.h" @@ -13,6 +17,7 @@ PicturePileLayerContent::PicturePileLayerContent(const PicturePile& picturePile) void PicturePileLayerContent::draw(SkCanvas* canvas) { + TRACE_METHOD(); android::Mutex::Autolock lock(m_drawLock); m_picturePile.draw(canvas); } diff --git a/Source/WebCore/platform/graphics/android/rendering/GLUtils.cpp b/Source/WebCore/platform/graphics/android/rendering/GLUtils.cpp index bfa0789..a68c01a 100644 --- a/Source/WebCore/platform/graphics/android/rendering/GLUtils.cpp +++ b/Source/WebCore/platform/graphics/android/rendering/GLUtils.cpp @@ -384,6 +384,7 @@ bool GLUtils::isPureColorBitmap(const SkBitmap& bitmap, Color& pureColor) // If the bitmap is the pure color, skip the transfer step, and update the Tile Info. // This check is taking < 1ms if we do full bitmap check per tile. // TODO: use the SkPicture to determine whether or not a tile is single color. + TRACE_METHOD(); pureColor = Color(Color::transparent); bitmap.lockPixels(); bool sameColor = true; @@ -483,6 +484,7 @@ void GLUtils::updateQueueWithBitmap(const TileRenderInfo* renderInfo, const SkBi bool GLUtils::updateSharedSurfaceTextureWithBitmap(ANativeWindow* anw, const SkBitmap& bitmap) { + TRACE_METHOD(); SkAutoLockPixels alp(bitmap); if (!bitmap.getPixels()) return false; diff --git a/Source/WebCore/platform/graphics/android/rendering/PaintTileOperation.cpp b/Source/WebCore/platform/graphics/android/rendering/PaintTileOperation.cpp index 3fcbdb2..c1b91a3 100644 --- a/Source/WebCore/platform/graphics/android/rendering/PaintTileOperation.cpp +++ b/Source/WebCore/platform/graphics/android/rendering/PaintTileOperation.cpp @@ -79,12 +79,12 @@ bool PaintTileOperation::operator==(const QueuedOperation* operation) return op->m_tile == m_tile; } -void PaintTileOperation::run() +void PaintTileOperation::run(BaseRenderer* renderer) { TRACE_METHOD(); if (m_tile) { - m_tile->paintBitmap(m_painter); + m_tile->paintBitmap(m_painter, renderer); m_tile->setRepaintPending(false); m_tile = 0; } diff --git a/Source/WebCore/platform/graphics/android/rendering/PaintTileOperation.h b/Source/WebCore/platform/graphics/android/rendering/PaintTileOperation.h index c82cdcd..ecd3ce9 100644 --- a/Source/WebCore/platform/graphics/android/rendering/PaintTileOperation.h +++ b/Source/WebCore/platform/graphics/android/rendering/PaintTileOperation.h @@ -42,7 +42,7 @@ public: GLWebViewState* state, bool isLowResPrefetch); virtual ~PaintTileOperation(); virtual bool operator==(const QueuedOperation* operation); - virtual void run(); + virtual void run(BaseRenderer* renderer); virtual void* uniquePtr() { return m_tile; } // returns a rendering priority for m_tile, lower values are processed faster virtual int priority(); diff --git a/Source/WebCore/platform/graphics/android/rendering/QueuedOperation.h b/Source/WebCore/platform/graphics/android/rendering/QueuedOperation.h index 7625528..fe6f8a3 100644 --- a/Source/WebCore/platform/graphics/android/rendering/QueuedOperation.h +++ b/Source/WebCore/platform/graphics/android/rendering/QueuedOperation.h @@ -28,10 +28,12 @@ namespace WebCore { +class BaseRenderer; + class QueuedOperation { public: virtual ~QueuedOperation() {} - virtual void run() = 0; + virtual void run(BaseRenderer* renderer) = 0; virtual bool operator==(const QueuedOperation* operation) = 0; virtual void* uniquePtr() = 0; virtual int priority() = 0; diff --git a/Source/WebCore/platform/graphics/android/rendering/RasterRenderer.cpp b/Source/WebCore/platform/graphics/android/rendering/RasterRenderer.cpp index 47e5c17..a67a890 100644 --- a/Source/WebCore/platform/graphics/android/rendering/RasterRenderer.cpp +++ b/Source/WebCore/platform/graphics/android/rendering/RasterRenderer.cpp @@ -42,20 +42,17 @@ namespace WebCore { -SkBitmap* RasterRenderer::g_bitmap = 0; - -RasterRenderer::RasterRenderer() : BaseRenderer(BaseRenderer::Raster) +RasterRenderer::RasterRenderer() + : BaseRenderer(BaseRenderer::Raster) + , m_bitmapIsPureColor(false) { + m_bitmap.setConfig(SkBitmap::kARGB_8888_Config, + TilesManager::instance()->tileWidth(), + TilesManager::instance()->tileHeight()); + m_bitmap.allocPixels(); #ifdef DEBUG_COUNT ClassTracker::instance()->increment("RasterRenderer"); #endif - if (!g_bitmap) { - g_bitmap = new SkBitmap(); - g_bitmap->setConfig(SkBitmap::kARGB_8888_Config, - TilesManager::instance()->tileWidth(), - TilesManager::instance()->tileHeight()); - g_bitmap->allocPixels(); - } } RasterRenderer::~RasterRenderer() @@ -67,9 +64,14 @@ RasterRenderer::~RasterRenderer() void RasterRenderer::setupCanvas(const TileRenderInfo& renderInfo, SkCanvas* canvas) { + TRACE_METHOD(); + if (renderInfo.baseTile->isLayerTile()) { - g_bitmap->setIsOpaque(false); - g_bitmap->eraseARGB(0, 0, 0, 0); + m_bitmap.setIsOpaque(false); + + // clear bitmap if necessary + if (!m_bitmapIsPureColor || m_bitmapPureColor != Color::transparent) + m_bitmap.eraseARGB(0, 0, 0, 0); } else { Color defaultBackground = Color::white; Color* background = renderInfo.tilePainter->background(); @@ -78,12 +80,15 @@ void RasterRenderer::setupCanvas(const TileRenderInfo& renderInfo, SkCanvas* can background = &defaultBackground; } ALOGV("setupCanvas use background on Base Layer %x", background->rgb()); - g_bitmap->setIsOpaque(!background->hasAlpha()); - g_bitmap->eraseARGB(background->alpha(), background->red(), - background->green(), background->blue()); + m_bitmap.setIsOpaque(!background->hasAlpha()); + + // fill background color if necessary + if (!m_bitmapIsPureColor || m_bitmapPureColor != *background) + m_bitmap.eraseARGB(background->alpha(), background->red(), + background->green(), background->blue()); } - SkDevice* device = new SkDevice(*g_bitmap); + SkDevice* device = new SkDevice(m_bitmap); canvas->setDevice(device); @@ -92,14 +97,15 @@ void RasterRenderer::setupCanvas(const TileRenderInfo& renderInfo, SkCanvas* can void RasterRenderer::renderingComplete(const TileRenderInfo& renderInfo, SkCanvas* canvas) { - const SkBitmap& bitmap = canvas->getDevice()->accessBitmap(false); - GLUtils::paintTextureWithBitmap(&renderInfo, bitmap); + GLUtils::paintTextureWithBitmap(&renderInfo, m_bitmap); } void RasterRenderer::checkForPureColor(TileRenderInfo& renderInfo, SkCanvas* canvas) { - const SkBitmap& bitmap = canvas->getDevice()->accessBitmap(false); - renderInfo.isPureColor = GLUtils::isPureColorBitmap(bitmap, renderInfo.pureColor); + m_bitmapIsPureColor = GLUtils::isPureColorBitmap(m_bitmap, m_bitmapPureColor); + + renderInfo.isPureColor = m_bitmapIsPureColor; + renderInfo.pureColor = m_bitmapPureColor; } } // namespace WebCore diff --git a/Source/WebCore/platform/graphics/android/rendering/RasterRenderer.h b/Source/WebCore/platform/graphics/android/rendering/RasterRenderer.h index 39e00f2..34b57ca 100644 --- a/Source/WebCore/platform/graphics/android/rendering/RasterRenderer.h +++ b/Source/WebCore/platform/graphics/android/rendering/RasterRenderer.h @@ -46,14 +46,14 @@ public: ~RasterRenderer(); protected: - virtual void setupCanvas(const TileRenderInfo& renderInfo, SkCanvas* canvas); virtual void renderingComplete(const TileRenderInfo& renderInfo, SkCanvas* canvas); virtual void checkForPureColor(TileRenderInfo& renderInfo, SkCanvas* canvas); private: - static SkBitmap* g_bitmap; - + SkBitmap m_bitmap; + bool m_bitmapIsPureColor; + Color m_bitmapPureColor; }; } // namespace WebCore diff --git a/Source/WebCore/platform/graphics/android/rendering/Surface.cpp b/Source/WebCore/platform/graphics/android/rendering/Surface.cpp index 1898910..96a4a16 100644 --- a/Source/WebCore/platform/graphics/android/rendering/Surface.cpp +++ b/Source/WebCore/platform/graphics/android/rendering/Surface.cpp @@ -218,7 +218,7 @@ void Surface::prepareGL(bool layerTilesDisabled, bool updateWithBlit) ALOGV("prepareGL on Surf %p with SurfBack %p, %d layers, first layer %s (%d) " "prepareArea(%d, %d - %d x %d) fullArea(%d, %d - %d x %d)", this, m_surfaceBacking, m_layers.size(), - getFirstLayer()->subclassName().ascii().data(), + getFirstLayer()->subclassName(), getFirstLayer()->uniqueId(), prepareArea.x(), prepareArea.y(), prepareArea.width(), prepareArea.height(), fullArea.x(), fullArea.y(), fullArea.width(), fullArea.height()); @@ -253,7 +253,7 @@ bool Surface::drawGL(bool layerTilesDisabled) bool askRedraw = false; if (m_surfaceBacking && !tilesDisabled) { ALOGV("drawGL on Surf %p with SurfBack %p, first layer %s (%d)", this, m_surfaceBacking, - getFirstLayer()->subclassName().ascii().data(), getFirstLayer()->uniqueId()); + getFirstLayer()->subclassName(), getFirstLayer()->uniqueId()); bool force3dContentVisible = true; IntRect drawArea = visibleContentArea(force3dContentVisible); diff --git a/Source/WebCore/platform/graphics/android/rendering/SurfaceCollectionManager.cpp b/Source/WebCore/platform/graphics/android/rendering/SurfaceCollectionManager.cpp index 174720f..1270498 100644 --- a/Source/WebCore/platform/graphics/android/rendering/SurfaceCollectionManager.cpp +++ b/Source/WebCore/platform/graphics/android/rendering/SurfaceCollectionManager.cpp @@ -38,6 +38,10 @@ namespace WebCore { using namespace android::uirenderer; +// Tag used to display current number of SurfaceCollections. +// Note: this will only work if one webview is actively drawing at a time. +static const char* COLLECTION_COUNT_TAG = "CollectionCount"; + SurfaceCollectionManager::SurfaceCollectionManager() : m_drawingCollection(0) , m_paintingCollection(0) @@ -87,6 +91,12 @@ void SurfaceCollectionManager::swap() m_paintingCollection = m_queuedCollection; m_queuedCollection = 0; + if (ATRACE_ENABLED()) { + ATRACE_INT(COLLECTION_COUNT_TAG, + (m_drawingCollection ? 1 : 0) + + (m_paintingCollection ? 1 : 0)); + } + ALOGV("SWAPPING COMPLETE, D %p, P %p, Q %p", m_drawingCollection, m_paintingCollection, m_queuedCollection); } @@ -106,6 +116,8 @@ void SurfaceCollectionManager::clearCollections() m_paintingCollection = 0; SkSafeUnref(m_queuedCollection); m_queuedCollection = 0; + + ATRACE_INT(COLLECTION_COUNT_TAG, 0); } void SurfaceCollectionManager::updatePaintingCollection(SurfaceCollection* newCollection) @@ -126,8 +138,10 @@ bool SurfaceCollectionManager::updateWithSurfaceCollection(SurfaceCollection* ne if (!newCollection || brandNew) { clearCollections(); - if (brandNew) + if (brandNew) { updatePaintingCollection(newCollection); + ATRACE_INT(COLLECTION_COUNT_TAG, 1); + } return false; } @@ -157,6 +171,13 @@ bool SurfaceCollectionManager::updateWithSurfaceCollection(SurfaceCollection* ne // don't have painting collection, paint this one! updatePaintingCollection(newCollection); } + + if (ATRACE_ENABLED()) { + ATRACE_INT(COLLECTION_COUNT_TAG, + (m_drawingCollection ? 1 : 0) + + (m_paintingCollection ? 1 : 0) + + (m_queuedCollection ? 1 : 0)); + } return m_drawingCollection && TilesManager::instance()->useDoubleBuffering(); } @@ -225,12 +246,12 @@ int SurfaceCollectionManager::drawGL(double currentTime, IntRect& viewRect, int returnFlags = 0; bool didCollectionSwap = false; + bool tryFastBlit = !m_fastSwapMode; if (m_paintingCollection) { ALOGV("preparing painting collection %p", m_paintingCollection); m_paintingCollection->evaluateAnimations(currentTime); - bool tryFastBlit = !m_fastSwapMode; m_paintingCollection->prepareGL(visibleContentRect, tryFastBlit); m_paintingCollection->computeTexturesAmount(texturesResultPtr); @@ -261,6 +282,9 @@ int SurfaceCollectionManager::drawGL(double currentTime, IntRect& viewRect, && m_drawingCollection->isReady())) { // either a swap just occurred, or there is no more work to be done: do a full draw m_drawingCollection->swapTiles(); + + if (didCollectionSwap && m_paintingCollection) + m_paintingCollection->prepareGL(visibleContentRect, tryFastBlit); returnFlags |= DrawGlInfo::kStatusDraw; } else { // current collection not ready - invoke functor in process mode @@ -286,6 +310,9 @@ int SurfaceCollectionManager::drawGL(double currentTime, IntRect& viewRect, if (didCollectionSwap || m_fastSwapMode || (drawingReady && !m_paintingCollection)) m_drawingCollection->swapTiles(); + if (didCollectionSwap && m_paintingCollection) + m_paintingCollection->prepareGL(visibleContentRect, tryFastBlit); + if (drawingReady) { // exit fast swap mode, as content is up to date m_fastSwapMode = false; diff --git a/Source/WebCore/platform/graphics/android/rendering/TexturesGenerator.cpp b/Source/WebCore/platform/graphics/android/rendering/TexturesGenerator.cpp index cc94c9c..74e663a 100644 --- a/Source/WebCore/platform/graphics/android/rendering/TexturesGenerator.cpp +++ b/Source/WebCore/platform/graphics/android/rendering/TexturesGenerator.cpp @@ -32,6 +32,7 @@ #if USE(ACCELERATED_COMPOSITING) #include "AndroidLog.h" +#include "BaseRenderer.h" #include "GLUtils.h" #include "PaintTileOperation.h" #include "TilesManager.h" @@ -39,6 +40,19 @@ namespace WebCore { +TexturesGenerator::TexturesGenerator(TilesManager* instance) + : Thread(false) + , m_tilesManager(instance) + , m_deferredMode(false) + , m_renderer(0) +{ +} + +TexturesGenerator::~TexturesGenerator() +{ + delete m_renderer; +} + bool TexturesGenerator::tryUpdateOperationWithPainter(Tile* tile, TilePainter* painter) { android::Mutex::Autolock lock(mRequestedOperationsLock); @@ -83,12 +97,11 @@ void TexturesGenerator::removeOperationsForFilter(OperationFilter* filter) i++; } } - delete filter; } status_t TexturesGenerator::readyToRun() { - ALOGV("Thread ready to run"); + m_renderer = BaseRenderer::createRenderer(); return NO_ERROR; } @@ -165,7 +178,9 @@ bool TexturesGenerator::threadLoop() if (currentOperation) { ALOGV("threadLoop, painting the request with priority %d", currentOperation->priority()); - currentOperation->run(); + // swap out the renderer if necessary + BaseRenderer::swapRendererIfNeeded(m_renderer); + currentOperation->run(m_renderer); } mRequestedOperationsLock.lock(); diff --git a/Source/WebCore/platform/graphics/android/rendering/TexturesGenerator.h b/Source/WebCore/platform/graphics/android/rendering/TexturesGenerator.h index 290ad08..2998330 100644 --- a/Source/WebCore/platform/graphics/android/rendering/TexturesGenerator.h +++ b/Source/WebCore/platform/graphics/android/rendering/TexturesGenerator.h @@ -29,7 +29,7 @@ #if USE(ACCELERATED_COMPOSITING) #include "QueuedOperation.h" -#include "TilePainter.h" +#include "TransferQueue.h" #include <wtf/HashMap.h> #include <wtf/Vector.h> @@ -43,10 +43,9 @@ class TilesManager; class TexturesGenerator : public Thread { public: - TexturesGenerator(TilesManager* instance) : Thread(false) - , m_tilesManager(instance) - , m_deferredMode(false) { } - virtual ~TexturesGenerator() { } + TexturesGenerator(TilesManager* instance); + virtual ~TexturesGenerator(); + virtual status_t readyToRun(); bool tryUpdateOperationWithPainter(Tile* tile, TilePainter* painter); @@ -68,6 +67,7 @@ private: android::Condition mRequestedOperationsCond; TilesManager* m_tilesManager; + BaseRenderer* m_renderer; bool m_deferredMode; // defer painting for one second if best in queue has priority diff --git a/Source/WebCore/platform/graphics/android/rendering/Tile.cpp b/Source/WebCore/platform/graphics/android/rendering/Tile.cpp index 96b189a..76be981 100644 --- a/Source/WebCore/platform/graphics/android/rendering/Tile.cpp +++ b/Source/WebCore/platform/graphics/android/rendering/Tile.cpp @@ -33,7 +33,7 @@ #include "AndroidLog.h" #include "GLUtils.h" -#include "RasterRenderer.h" +#include "BaseRenderer.h" #include "TextureInfo.h" #include "TileTexture.h" #include "TilesManager.h" @@ -64,7 +64,6 @@ Tile::Tile(bool isLayerTile) #ifdef DEBUG_COUNT ClassTracker::instance()->increment("Tile"); #endif - m_renderer = BaseRenderer::createRenderer(); } Tile::~Tile() @@ -74,8 +73,6 @@ Tile::~Tile() if (m_frontTexture) m_frontTexture->release(this); - delete m_renderer; - #ifdef DEBUG_COUNT ClassTracker::instance()->decrement("Tile"); #endif @@ -297,7 +294,7 @@ bool Tile::isTileVisible(const IntRect& viewTileBounds) } // This is called from the texture generation thread -void Tile::paintBitmap(TilePainter* painter) +void Tile::paintBitmap(TilePainter* painter, BaseRenderer* renderer) { // We acquire the values below atomically. This ensures that we are reading // values correctly across cores. Further, once we have these values they @@ -328,8 +325,6 @@ void Tile::paintBitmap(TilePainter* painter) return; } - // swap out the renderer if necessary - BaseRenderer::swapRendererIfNeeded(m_renderer); // setup the common renderInfo fields; TileRenderInfo renderInfo; renderInfo.x = x; @@ -343,7 +338,7 @@ void Tile::paintBitmap(TilePainter* painter) const float tileWidth = renderInfo.tileSize.width(); const float tileHeight = renderInfo.tileSize.height(); - m_renderer->renderTiledContent(renderInfo); + renderer->renderTiledContent(renderInfo); m_atomicSync.lock(); diff --git a/Source/WebCore/platform/graphics/android/rendering/Tile.h b/Source/WebCore/platform/graphics/android/rendering/Tile.h index b045f1f..f467bb0 100644 --- a/Source/WebCore/platform/graphics/android/rendering/Tile.h +++ b/Source/WebCore/platform/graphics/android/rendering/Tile.h @@ -28,7 +28,6 @@ #if USE(ACCELERATED_COMPOSITING) -#include "BaseRenderer.h" #include "FloatPoint.h" #include "SkRect.h" #include "SkRegion.h" @@ -39,9 +38,10 @@ namespace WebCore { +class BaseRenderer; +class GLWebViewState; class TextureInfo; class TileTexture; -class GLWebViewState; /** * An individual tile that is used to construct part of a webpage's BaseLayer of @@ -107,7 +107,7 @@ public: const FloatRect& fillPortion); // the only thread-safe function called by the background thread - void paintBitmap(TilePainter* painter); + void paintBitmap(TilePainter* painter, BaseRenderer* renderer); bool intersectWithRect(int x, int y, int tileWidth, int tileHeight, float scale, const SkRect& dirtyRect, @@ -171,8 +171,6 @@ private: // across all threads and cores. android::Mutex m_atomicSync; - BaseRenderer* m_renderer; - bool m_isLayerTile; // the most recent GL draw before this tile was prepared. used for diff --git a/Source/WebCore/platform/graphics/android/rendering/TilesManager.cpp b/Source/WebCore/platform/graphics/android/rendering/TilesManager.cpp index 0b4ba7b..e584b81 100644 --- a/Source/WebCore/platform/graphics/android/rendering/TilesManager.cpp +++ b/Source/WebCore/platform/graphics/android/rendering/TilesManager.cpp @@ -65,6 +65,10 @@ #define LAYER_TEXTURES_DESTROY_TIMEOUT 60 // If we do not need layers for 60 seconds, free the textures +// Eventually this should be dynamically be determined, and smart scheduling +// between the generators should be implemented +#define NUM_TEXTURES_GENERATORS 1 + namespace WebCore { int TilesManager::getMaxTextureAllocation() @@ -105,10 +109,21 @@ TilesManager::TilesManager() m_availableTextures.reserveCapacity(MAX_TEXTURE_ALLOCATION); m_tilesTextures.reserveCapacity(MAX_TEXTURE_ALLOCATION); m_availableTilesTextures.reserveCapacity(MAX_TEXTURE_ALLOCATION); - m_pixmapsGenerationThread = new TexturesGenerator(this); - m_pixmapsGenerationThread->run("TexturesGenerator"); + + m_textureGenerators = new sp<TexturesGenerator>[NUM_TEXTURES_GENERATORS]; + for (int i = 0; i < NUM_TEXTURES_GENERATORS; i++) { + m_textureGenerators[i] = new TexturesGenerator(this); + ALOGD("Starting TG #%d, %p", i, m_textureGenerators[i].get()); + m_textureGenerators[i]->run("TexturesGenerator"); + } } +TilesManager::~TilesManager() +{ + delete[] m_textureGenerators; +} + + void TilesManager::allocateTextures() { int nbTexturesToAllocate = m_currentTextureCount - m_textures.size(); @@ -488,6 +503,29 @@ void TilesManager::updateTilesIfContextVerified() return; } +void TilesManager::removeOperationsForFilter(OperationFilter* filter) +{ + for (int i = 0; i < NUM_TEXTURES_GENERATORS; i++) + m_textureGenerators[i]->removeOperationsForFilter(filter); + delete filter; +} + +bool TilesManager::tryUpdateOperationWithPainter(Tile* tile, TilePainter* painter) +{ + for (int i = 0; i < NUM_TEXTURES_GENERATORS; i++) { + if (m_textureGenerators[i]->tryUpdateOperationWithPainter(tile, painter)) + return true; + } + return false; +} + +void TilesManager::scheduleOperation(QueuedOperation* operation) +{ + // TODO: painter awareness, store prefer awareness, store preferred thread into painter + m_scheduleThread = (m_scheduleThread + 1) % NUM_TEXTURES_GENERATORS; + m_textureGenerators[m_scheduleThread]->scheduleOperation(operation); +} + int TilesManager::tileWidth() { return TILE_WIDTH; diff --git a/Source/WebCore/platform/graphics/android/rendering/TilesManager.h b/Source/WebCore/platform/graphics/android/rendering/TilesManager.h index f0d2eac..0781ef6 100644 --- a/Source/WebCore/platform/graphics/android/rendering/TilesManager.h +++ b/Source/WebCore/platform/graphics/android/rendering/TilesManager.h @@ -53,23 +53,9 @@ public: return gInstance != 0; } - void removeOperationsForFilter(OperationFilter* filter) - { - m_pixmapsGenerationThread->removeOperationsForFilter(filter); - } - - bool tryUpdateOperationWithPainter(Tile* tile, TilePainter* painter) - { - return m_pixmapsGenerationThread->tryUpdateOperationWithPainter(tile, painter); - } - - void scheduleOperation(QueuedOperation* operation) - { - m_pixmapsGenerationThread->scheduleOperation(operation); - } - ShaderProgram* shader() { return &m_shader; } TransferQueue* transferQueue(); + VideoLayerManager* videoLayerManager() { return &m_videoLayerManager; } void updateTilesIfContextVerified(); @@ -165,8 +151,15 @@ public: return m_drawGLCount; } + // operations on/for texture generator threads + void removeOperationsForFilter(OperationFilter* filter); + bool tryUpdateOperationWithPainter(Tile* tile, TilePainter* painter); + void scheduleOperation(QueuedOperation* operation); + private: TilesManager(); + ~TilesManager(); + int m_scheduleThread; void discardTexturesVector(unsigned long long sparedDrawCount, WTF::Vector<TileTexture*>& textures, @@ -198,7 +191,7 @@ private: unsigned int m_contentUpdates; // nr of successful tiled paints unsigned int m_webkitContentUpdates; // nr of paints from webkit - sp<TexturesGenerator> m_pixmapsGenerationThread; + sp<TexturesGenerator>* m_textureGenerators; android::Mutex m_texturesLock; diff --git a/Source/WebCore/platform/graphics/android/rendering/TransferQueue.cpp b/Source/WebCore/platform/graphics/android/rendering/TransferQueue.cpp index f37afa4..e329191 100644 --- a/Source/WebCore/platform/graphics/android/rendering/TransferQueue.cpp +++ b/Source/WebCore/platform/graphics/android/rendering/TransferQueue.cpp @@ -32,6 +32,7 @@ #if USE(ACCELERATED_COMPOSITING) #include "AndroidLog.h" +#include "BaseRenderer.h" #include "DrawQuadData.h" #include "GLUtils.h" #include "Tile.h" @@ -391,6 +392,7 @@ void TransferQueue::updateDirtyTiles() void TransferQueue::updateQueueWithBitmap(const TileRenderInfo* renderInfo, const SkBitmap& bitmap) { + TRACE_METHOD(); if (!tryUpdateQueueWithBitmap(renderInfo, bitmap)) { // failed placing bitmap in queue, discard tile's texture so it will be // re-enqueued (and repainted) diff --git a/Source/WebCore/platform/mock/GeolocationServiceMock.cpp b/Source/WebCore/platform/mock/GeolocationServiceMock.cpp index c3ba7b4..b254cb8 100644 --- a/Source/WebCore/platform/mock/GeolocationServiceMock.cpp +++ b/Source/WebCore/platform/mock/GeolocationServiceMock.cpp @@ -80,12 +80,7 @@ void GeolocationServiceMock::setError(PassRefPtr<PositionError> error) makeGeolocationCallbackFromAllInstances(); } -#if PLATFORM(ANDROID) -// TODO: Upstream to webkit.org. See https://bugs.webkit.org/show_bug.cgi?id=34082 -bool GeolocationServiceMock::startUpdating(PositionOptions*, bool /* suspend */) -#else bool GeolocationServiceMock::startUpdating(PositionOptions*) -#endif { m_isActive = true; m_timer.startOneShot(0); diff --git a/Source/WebCore/platform/mock/GeolocationServiceMock.h b/Source/WebCore/platform/mock/GeolocationServiceMock.h index 1b4db93..7d02797 100755 --- a/Source/WebCore/platform/mock/GeolocationServiceMock.h +++ b/Source/WebCore/platform/mock/GeolocationServiceMock.h @@ -46,12 +46,7 @@ class GeolocationServiceMock : public GeolocationService { GeolocationServiceMock(GeolocationServiceClient*); virtual ~GeolocationServiceMock(); -#if PLATFORM(ANDROID) - // TODO: Upstream to webkit.org. See https://bugs.webkit.org/show_bug.cgi?id=34082 - virtual bool startUpdating(PositionOptions*, bool suspend); -#else virtual bool startUpdating(PositionOptions*); -#endif virtual void stopUpdating(); static void setPosition(PassRefPtr<Geoposition> position); |