1 /* 2 * Copyright 2020 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 17 package androidx.compose.ui.platform 18 19 import android.graphics.Outline 20 import androidx.compose.ui.graphics.BlendMode 21 import androidx.compose.ui.graphics.Canvas 22 import androidx.compose.ui.graphics.CanvasHolder 23 import androidx.compose.ui.graphics.ColorFilter 24 import androidx.compose.ui.graphics.CompositingStrategy 25 import androidx.compose.ui.graphics.Path 26 import androidx.compose.ui.graphics.RenderEffect 27 28 /** 29 * RenderNode on Q+ and RenderNode on M-P devices have different APIs. This interface unifies the 30 * access so that [RenderNodeLayer] can be used for both. 31 */ 32 internal interface DeviceRenderNode { 33 val uniqueId: Long 34 val left: Int 35 val top: Int 36 val right: Int 37 val bottom: Int 38 val width: Int 39 val height: Int 40 var scaleX: Float 41 var scaleY: Float 42 var translationX: Float 43 var translationY: Float 44 var elevation: Float 45 var ambientShadowColor: Int 46 var spotShadowColor: Int 47 var rotationZ: Float 48 var rotationX: Float 49 var rotationY: Float 50 var cameraDistance: Float 51 var pivotX: Float 52 var pivotY: Float 53 var clipToOutline: Boolean 54 var clipToBounds: Boolean 55 var alpha: Float 56 var renderEffect: RenderEffect? 57 var blendMode: BlendMode 58 var colorFilter: ColorFilter? 59 val hasDisplayList: Boolean 60 var compositingStrategy: CompositingStrategy 61 setOutlinenull62 fun setOutline(outline: Outline?) 63 64 fun setPosition(left: Int, top: Int, right: Int, bottom: Int): Boolean 65 66 fun offsetLeftAndRight(offset: Int) 67 68 fun offsetTopAndBottom(offset: Int) 69 70 fun record(canvasHolder: CanvasHolder, clipPath: Path?, drawBlock: (Canvas) -> Unit) 71 72 fun getMatrix(matrix: android.graphics.Matrix) 73 74 fun getInverseMatrix(matrix: android.graphics.Matrix) 75 76 fun drawInto(canvas: android.graphics.Canvas) 77 78 fun setHasOverlappingRendering(hasOverlappingRendering: Boolean): Boolean 79 80 /** 81 * Debugging method used to dump the underlying parameters of the backing RenderNode on the 82 * platform. This is used for testing purposes to avoid having to query the RenderNode directly 83 * and potentially crashing on certain multiplatform configurations 84 */ 85 fun dumpRenderNodeData(): DeviceRenderNodeData 86 87 fun discardDisplayList() 88 } 89 90 /** 91 * Data class representing the actual parameters of the platform RenderNode in the 92 * [DeviceRenderNode] implementation. Before RenderNode was made public API, the parameter inputs 93 * were inconsistent across platform versions. This class is used to verify the result of the 94 * internal RenderNode values for testing purposes based on the consistent inputs provided as part 95 * of the Layer API. For example, [cameraDistance] is negative on RenderNode implementations prior 96 * to Q. 97 */ 98 internal data class DeviceRenderNodeData( 99 val uniqueId: Long, 100 val left: Int, 101 val top: Int, 102 val right: Int, 103 val bottom: Int, 104 val width: Int, 105 val height: Int, 106 var scaleX: Float, 107 var scaleY: Float, 108 var translationX: Float, 109 var translationY: Float, 110 var elevation: Float, 111 var ambientShadowColor: Int, 112 var spotShadowColor: Int, 113 var rotationZ: Float, 114 var rotationX: Float, 115 var rotationY: Float, 116 var cameraDistance: Float, 117 var pivotX: Float, 118 var pivotY: Float, 119 var clipToOutline: Boolean, 120 var clipToBounds: Boolean, 121 var alpha: Float, 122 var renderEffect: RenderEffect?, 123 var blendMode: BlendMode, 124 var colorFilter: ColorFilter?, 125 var compositingStrategy: CompositingStrategy 126 ) 127