Igor Demin | b3f9d00 | 2020-07-09 19:29:41 +0300 | [diff] [blame^] | 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 | @file:Suppress("DEPRECATION_ERROR") |
| 18 | |
| 19 | package androidx.ui.desktop |
| 20 | |
| 21 | import androidx.compose.InternalComposeApi |
| 22 | import androidx.ui.graphics.DesktopCanvas |
| 23 | import androidx.ui.graphics.DesktopImageShader |
| 24 | import androidx.ui.graphics.DesktopInternalCanvasHolder |
| 25 | import androidx.ui.graphics.DesktopLinearGradientShader |
| 26 | import androidx.ui.graphics.DesktopPaint |
| 27 | import androidx.ui.graphics.DesktopPath |
| 28 | import androidx.ui.graphics.DesktopRadialGradientShader |
| 29 | import androidx.ui.graphics.GraphicsFactory |
| 30 | import androidx.ui.text.platform.paragraphActualFactory |
| 31 | import androidx.ui.text.platform.paragraphIntrinsicsActualFactory |
| 32 | import org.jetbrains.skija.Library |
| 33 | |
| 34 | /** |
| 35 | * Can be called multiple times. |
| 36 | * |
| 37 | * Initialization will occur only on the first call. The next calls will do nothing. |
| 38 | * |
| 39 | * Should be called in a class that uses Jetpack Compose Api: |
| 40 | * |
| 41 | * class SomeClass { |
| 42 | * companion object { |
| 43 | * init { |
| 44 | * initCompose() |
| 45 | * } |
| 46 | * } |
| 47 | * } |
| 48 | */ |
| 49 | fun initCompose() { |
| 50 | // call object initializer only once |
| 51 | ComposeInit |
| 52 | } |
| 53 | |
| 54 | @OptIn(androidx.ui.text.platform.InternalPlatformTextApi::class, InternalComposeApi::class) |
| 55 | private object ComposeInit { |
| 56 | init { |
| 57 | Library.load("/", "skija") |
| 58 | // Until https://github.com/Kotlin/kotlinx.coroutines/issues/2039 is resolved |
| 59 | // we have to set this property manually for coroutines to work. |
| 60 | System.getProperties().setProperty("kotlinx.coroutines.fast.service.loader", "false") |
| 61 | |
| 62 | GraphicsFactory.nativeCanvas = ::DesktopCanvas |
| 63 | GraphicsFactory.imageCanvas = ::DesktopCanvas |
| 64 | GraphicsFactory.canvasHolder = ::DesktopInternalCanvasHolder |
| 65 | GraphicsFactory.paint = ::DesktopPaint |
| 66 | GraphicsFactory.path = { DesktopPath() } |
| 67 | GraphicsFactory.Shader.linear = ::DesktopLinearGradientShader |
| 68 | GraphicsFactory.Shader.radial = ::DesktopRadialGradientShader |
| 69 | GraphicsFactory.Shader.image = ::DesktopImageShader |
| 70 | paragraphIntrinsicsActualFactory = ::DesktopParagraphIntrinsics |
| 71 | paragraphActualFactory = ::DesktopParagraph |
| 72 | } |
| 73 | } |