From d62df3789ca05962bd9c04c6b1bd0a3a81c965db Mon Sep 17 00:00:00 2001 From: Panayot Cankov Date: Fri, 25 Aug 2017 10:45:58 +0300 Subject: [PATCH] Do not change the Android layer types (hardware/software) (#4625) --- .../ui/animation/animation.android.ts | 29 +------------------ tns-core-modules/ui/core/view/view.android.ts | 6 ---- .../ui/styling/background.android.ts | 18 +----------- tns-core-modules/utils/utils.d.ts | 10 ------- 4 files changed, 2 insertions(+), 61 deletions(-) diff --git a/tns-core-modules/ui/animation/animation.android.ts b/tns-core-modules/ui/animation/animation.android.ts index a918ba523..2f5c75d46 100644 --- a/tns-core-modules/ui/animation/animation.android.ts +++ b/tns-core-modules/ui/animation/animation.android.ts @@ -8,7 +8,7 @@ import { translateXProperty, translateYProperty, scaleXProperty, scaleYProperty } from "../styling/style-properties"; -import { CacheLayerType, layout } from "../../utils/utils"; +import { layout } from "../../utils/utils"; import lazy from "../../utils/lazy"; export * from "./animation-common"; @@ -161,8 +161,6 @@ export class Animation extends AnimationBase { } } - this._enableHardwareAcceleration(); - if (traceEnabled()) { traceWrite("Starting " + this._nativeAnimatorsArray.length + " animations " + (this._playSequentially ? "sequentially." : "together."), traceCategories.Animation); } @@ -190,7 +188,6 @@ export class Animation extends AnimationBase { } this._propertyUpdateCallbacks.forEach(v => v()); - this._disableHardwareAcceleration(); this._resolveAnimationFinishedPromise(); if (this._target) { @@ -200,7 +197,6 @@ export class Animation extends AnimationBase { private _onAndroidAnimationCancel() { // tslint:disable-line this._propertyResetCallbacks.forEach(v => v()); - this._disableHardwareAcceleration(); this._rejectAnimationFinishedPromise(); if (this._target) { @@ -465,27 +461,4 @@ export class Animation extends AnimationBase { private static _getAndroidRepeatCount(iterations: number): number { return (iterations === Number.POSITIVE_INFINITY) ? android.view.animation.Animation.INFINITE : iterations - 1; } - - private _enableHardwareAcceleration() { - for (let i = 0, length = this._propertyAnimations.length; i < length; i++) { - let cache = this._propertyAnimations[i].target.nativeViewProtected; - if (cache) { - let layerType = cache.getLayerType(); - if (layerType !== android.view.View.LAYER_TYPE_HARDWARE) { - cache.layerType = layerType; - cache.setLayerType(android.view.View.LAYER_TYPE_HARDWARE, null); - } - } - } - } - - private _disableHardwareAcceleration() { - for (let i = 0, length = this._propertyAnimations.length; i < length; i++) { - let cache = this._propertyAnimations[i].target.nativeViewProtected; - if (cache && cache.layerType !== undefined) { - cache.setLayerType(cache.layerType, null); - cache.layerType = undefined; - } - } - } } diff --git a/tns-core-modules/ui/core/view/view.android.ts b/tns-core-modules/ui/core/view/view.android.ts index 7c852f8b3..1becfaa01 100644 --- a/tns-core-modules/ui/core/view/view.android.ts +++ b/tns-core-modules/ui/core/view/view.android.ts @@ -1,7 +1,6 @@ // Definitions. import { Point, CustomLayoutView as CustomLayoutViewDefinition, dip } from "."; import { GestureTypes, GestureEventData } from "../../gestures"; -import { CacheLayerType } from "../../../utils/utils"; // Types. import { Background, ad as androidBackground } from "../../styling/background"; @@ -510,11 +509,6 @@ export class View extends ViewCommon { } (nativeView).background = undefined; - const cache = nativeView; - if (cache.layerType !== undefined) { - cache.setLayerType(cache.layerType, null); - cache.layerType = undefined; - } } } } diff --git a/tns-core-modules/ui/styling/background.android.ts b/tns-core-modules/ui/styling/background.android.ts index 41ea2d2e4..a9df7df25 100644 --- a/tns-core-modules/ui/styling/background.android.ts +++ b/tns-core-modules/ui/styling/background.android.ts @@ -1,5 +1,5 @@ import { View } from "../core/view"; -import { CacheLayerType, isDataURI, isFileOrResourcePath, layout, RESOURCE_PREFIX, FILE_PREFIX } from "../../utils/utils"; +import { isDataURI, isFileOrResourcePath, layout, RESOURCE_PREFIX, FILE_PREFIX } from "../../utils/utils"; import { parse } from "../../css-value"; import { path, knownFolders } from "../../file-system"; import * as application from "../../application"; @@ -38,7 +38,6 @@ export module ad { } const background = view.style.backgroundInternal; - const cache = view.nativeViewProtected; const drawable = nativeView.getBackground(); const androidView = view as AndroidView; // use undefined as not set. getBackground will never return undefined only Drawable or null; @@ -68,16 +67,6 @@ export module ad { } else { refreshBorderDrawable(view, backgroundDrawable); } - - // This should be done only when backgroundImage is set!!! - if ((background.hasBorderWidth() || background.hasBorderRadius() || background.clipPath) && getSDK() < 18) { - // Switch to software because of unsupported canvas methods if hardware acceleration is on: - // http://developer.android.com/guide/topics/graphics/hardware-accel.html - if (cache.layerType === undefined) { - cache.layerType = cache.getLayerType(); - cache.setLayerType(android.view.View.LAYER_TYPE_SOFTWARE, null); - } - } } else { const cachedDrawable = androidView._cachedDrawable; let defaultDrawable: android.graphics.drawable.Drawable; @@ -92,11 +81,6 @@ export module ad { org.nativescript.widgets.ViewHelper.setBackground(nativeView, defaultDrawable); // TODO: Do we need to clear the drawable here? Can't we just reuse it again? androidView._cachedDrawable = undefined; - - if (cache.layerType !== undefined) { - cache.setLayerType(cache.layerType, null); - cache.layerType = undefined; - } } // TODO: Can we move BorderWidths as separate native setter? diff --git a/tns-core-modules/utils/utils.d.ts b/tns-core-modules/utils/utils.d.ts index 47564ff62..383cb07ca 100644 --- a/tns-core-modules/utils/utils.d.ts +++ b/tns-core-modules/utils/utils.d.ts @@ -15,16 +15,6 @@ export const FILE_PREFIX: string; interface Owned { owner: any; } - -/** - * Used to cache and restore Android views' layer type, i.e. android.view.View.getLayerType and android.view.View.setLayerType. - * @private - */ -interface CacheLayerType { - layerType: number; - setLayerType(layerType: number, paint: any): void; - getLayerType(): number; -} //@endprivate /**