Home | History | Annotate | Download | only in graphics
      1 /*
      2  * Copyright (C) 20188 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 @file:Suppress("NOTHING_TO_INLINE")
     17 
     18 package androidx.core.graphics
     19 
     20 import android.graphics.Canvas
     21 import android.graphics.Picture
     22 
     23 /**
     24  * Creates a new [Canvas] to record commands in this [Picture], executes the specified
     25  * [block] on the newly created canvas and returns this [Picture]. Example:
     26  *
     27  * ```
     28  * return myPicture.record(1280, 720) {
     29  *    drawLine()
     30  *    translate()
     31  *    drawRect()
     32  * }
     33  * ```
     34  */
     35 inline fun Picture.record(width: Int, height: Int, block: Canvas.() -> Unit): Picture {
     36     val c = beginRecording(width, height)
     37     try {
     38         c.block()
     39     } finally {
     40         endRecording()
     41     }
     42     return this
     43 }
     44