[go: nahoru, domu]

blob: 6682a79d4e69754caa5bca8097a19b76886f45e0 [file] [log] [blame]
Igor Deminb3f9d002020-07-09 19:29:41 +03001/*
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
19package androidx.ui.desktop
20
21import androidx.compose.InternalComposeApi
22import androidx.ui.graphics.DesktopCanvas
23import androidx.ui.graphics.DesktopImageShader
24import androidx.ui.graphics.DesktopInternalCanvasHolder
25import androidx.ui.graphics.DesktopLinearGradientShader
26import androidx.ui.graphics.DesktopPaint
27import androidx.ui.graphics.DesktopPath
28import androidx.ui.graphics.DesktopRadialGradientShader
29import androidx.ui.graphics.GraphicsFactory
30import androidx.ui.text.platform.paragraphActualFactory
31import androidx.ui.text.platform.paragraphIntrinsicsActualFactory
32import 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 */
49fun initCompose() {
50 // call object initializer only once
51 ComposeInit
52}
53
54@OptIn(androidx.ui.text.platform.InternalPlatformTextApi::class, InternalComposeApi::class)
55private 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}