John Reck | f666ad7 | 2014-03-14 16:24:57 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2010 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 android.view; |
| 18 | |
Chris Craik | 49e6c73 | 2014-03-31 12:34:11 -0700 | [diff] [blame] | 19 | import android.annotation.NonNull; |
Chris Craik | a753f4c | 2014-07-24 12:39:17 -0700 | [diff] [blame] | 20 | import android.annotation.Nullable; |
John Reck | f666ad7 | 2014-03-14 16:24:57 -0700 | [diff] [blame] | 21 | import android.graphics.Matrix; |
Chris Craik | b49f446 | 2014-03-20 12:44:20 -0700 | [diff] [blame] | 22 | import android.graphics.Outline; |
John Reck | 25fbb3f | 2014-06-12 13:46:45 -0700 | [diff] [blame] | 23 | import android.graphics.Paint; |
Chris Craik | a753f4c | 2014-07-24 12:39:17 -0700 | [diff] [blame] | 24 | import android.graphics.Rect; |
Doris Liu | 766431a | 2016-02-04 22:17:11 +0000 | [diff] [blame] | 25 | import android.graphics.drawable.AnimatedVectorDrawable; |
John Reck | f666ad7 | 2014-03-14 16:24:57 -0700 | [diff] [blame] | 26 | |
| 27 | /** |
| 28 | * <p>A display list records a series of graphics related operations and can replay |
| 29 | * them later. Display lists are usually built by recording operations on a |
Chris Craik | f6829a0 | 2015-03-10 10:28:59 -0700 | [diff] [blame] | 30 | * {@link DisplayListCanvas}. Replaying the operations from a display list avoids |
John Reck | f666ad7 | 2014-03-14 16:24:57 -0700 | [diff] [blame] | 31 | * executing application code on every frame, and is thus much more efficient.</p> |
| 32 | * |
| 33 | * <p>Display lists are used internally for all views by default, and are not |
| 34 | * typically used directly. One reason to consider using a display is a custom |
| 35 | * {@link View} implementation that needs to issue a large number of drawing commands. |
| 36 | * When the view invalidates, all the drawing commands must be reissued, even if |
| 37 | * large portions of the drawing command stream stay the same frame to frame, which |
| 38 | * can become a performance bottleneck. To solve this issue, a custom View might split |
| 39 | * its content into several display lists. A display list is updated only when its |
| 40 | * content, and only its content, needs to be updated.</p> |
| 41 | * |
| 42 | * <p>A text editor might for instance store each paragraph into its own display list. |
| 43 | * Thus when the user inserts or removes characters, only the display list of the |
| 44 | * affected paragraph needs to be recorded again.</p> |
| 45 | * |
| 46 | * <h3>Hardware acceleration</h3> |
Chris Craik | f6829a0 | 2015-03-10 10:28:59 -0700 | [diff] [blame] | 47 | * <p>Display lists can only be replayed using a {@link DisplayListCanvas}. They are not |
John Reck | f666ad7 | 2014-03-14 16:24:57 -0700 | [diff] [blame] | 48 | * supported in software. Always make sure that the {@link android.graphics.Canvas} |
| 49 | * you are using to render a display list is hardware accelerated using |
| 50 | * {@link android.graphics.Canvas#isHardwareAccelerated()}.</p> |
| 51 | * |
| 52 | * <h3>Creating a display list</h3> |
| 53 | * <pre class="prettyprint"> |
| 54 | * HardwareRenderer renderer = myView.getHardwareRenderer(); |
| 55 | * if (renderer != null) { |
| 56 | * DisplayList displayList = renderer.createDisplayList(); |
Chris Craik | f6829a0 | 2015-03-10 10:28:59 -0700 | [diff] [blame] | 57 | * DisplayListCanvas canvas = displayList.start(width, height); |
John Reck | f666ad7 | 2014-03-14 16:24:57 -0700 | [diff] [blame] | 58 | * try { |
| 59 | * // Draw onto the canvas |
| 60 | * // For instance: canvas.drawBitmap(...); |
| 61 | * } finally { |
| 62 | * displayList.end(); |
| 63 | * } |
| 64 | * } |
| 65 | * </pre> |
| 66 | * |
| 67 | * <h3>Rendering a display list on a View</h3> |
| 68 | * <pre class="prettyprint"> |
| 69 | * protected void onDraw(Canvas canvas) { |
| 70 | * if (canvas.isHardwareAccelerated()) { |
Chris Craik | f6829a0 | 2015-03-10 10:28:59 -0700 | [diff] [blame] | 71 | * DisplayListCanvas displayListCanvas = (DisplayListCanvas) canvas; |
| 72 | * displayListCanvas.drawDisplayList(mDisplayList); |
John Reck | f666ad7 | 2014-03-14 16:24:57 -0700 | [diff] [blame] | 73 | * } |
| 74 | * } |
| 75 | * </pre> |
| 76 | * |
| 77 | * <h3>Releasing resources</h3> |
| 78 | * <p>This step is not mandatory but recommended if you want to release resources |
| 79 | * held by a display list as soon as possible.</p> |
| 80 | * <pre class="prettyprint"> |
| 81 | * // Mark this display list invalid, it cannot be used for drawing anymore, |
| 82 | * // and release resources held by this display list |
| 83 | * displayList.clear(); |
| 84 | * </pre> |
| 85 | * |
| 86 | * <h3>Properties</h3> |
| 87 | * <p>In addition, a display list offers several properties, such as |
| 88 | * {@link #setScaleX(float)} or {@link #setLeft(int)}, that can be used to affect all |
| 89 | * the drawing commands recorded within. For instance, these properties can be used |
| 90 | * to move around a large number of images without re-issuing all the individual |
| 91 | * <code>drawBitmap()</code> calls.</p> |
| 92 | * |
| 93 | * <pre class="prettyprint"> |
| 94 | * private void createDisplayList() { |
| 95 | * mDisplayList = DisplayList.create("MyDisplayList"); |
Chris Craik | f6829a0 | 2015-03-10 10:28:59 -0700 | [diff] [blame] | 96 | * DisplayListCanvas canvas = mDisplayList.start(width, height); |
John Reck | f666ad7 | 2014-03-14 16:24:57 -0700 | [diff] [blame] | 97 | * try { |
| 98 | * for (Bitmap b : mBitmaps) { |
| 99 | * canvas.drawBitmap(b, 0.0f, 0.0f, null); |
| 100 | * canvas.translate(0.0f, b.getHeight()); |
| 101 | * } |
| 102 | * } finally { |
| 103 | * displayList.end(); |
| 104 | * } |
| 105 | * } |
| 106 | * |
| 107 | * protected void onDraw(Canvas canvas) { |
| 108 | * if (canvas.isHardwareAccelerated()) { |
Chris Craik | f6829a0 | 2015-03-10 10:28:59 -0700 | [diff] [blame] | 109 | * DisplayListCanvas displayListCanvas = (DisplayListCanvas) canvas; |
| 110 | * displayListCanvas.drawDisplayList(mDisplayList); |
John Reck | f666ad7 | 2014-03-14 16:24:57 -0700 | [diff] [blame] | 111 | * } |
| 112 | * } |
| 113 | * |
| 114 | * private void moveContentBy(int x) { |
| 115 | * // This will move all the bitmaps recorded inside the display list |
| 116 | * // by x pixels to the right and redraw this view. All the commands |
| 117 | * // recorded in createDisplayList() won't be re-issued, only onDraw() |
| 118 | * // will be invoked and will execute very quickly |
| 119 | * mDisplayList.offsetLeftAndRight(x); |
| 120 | * invalidate(); |
| 121 | * } |
| 122 | * </pre> |
| 123 | * |
| 124 | * <h3>Threading</h3> |
| 125 | * <p>Display lists must be created on and manipulated from the UI thread only.</p> |
| 126 | * |
| 127 | * @hide |
| 128 | */ |
| 129 | public class RenderNode { |
John Reck | f666ad7 | 2014-03-14 16:24:57 -0700 | [diff] [blame] | 130 | |
| 131 | private boolean mValid; |
John Reck | 119907c | 2014-08-14 09:02:01 -0700 | [diff] [blame] | 132 | // Do not access directly unless you are ThreadedRenderer |
| 133 | final long mNativeRenderNode; |
| 134 | private final View mOwningView; |
John Reck | f666ad7 | 2014-03-14 16:24:57 -0700 | [diff] [blame] | 135 | |
John Reck | 119907c | 2014-08-14 09:02:01 -0700 | [diff] [blame] | 136 | private RenderNode(String name, View owningView) { |
John Reck | 8de65a8 | 2014-04-09 15:23:38 -0700 | [diff] [blame] | 137 | mNativeRenderNode = nCreate(name); |
John Reck | 119907c | 2014-08-14 09:02:01 -0700 | [diff] [blame] | 138 | mOwningView = owningView; |
John Reck | f648108 | 2016-02-02 15:18:23 -0800 | [diff] [blame] | 139 | if (mOwningView instanceof SurfaceView) { |
| 140 | nRequestPositionUpdates(mNativeRenderNode, (SurfaceView) mOwningView); |
| 141 | } |
John Reck | f666ad7 | 2014-03-14 16:24:57 -0700 | [diff] [blame] | 142 | } |
| 143 | |
| 144 | /** |
John Reck | e45b1fd | 2014-04-15 09:50:16 -0700 | [diff] [blame] | 145 | * @see RenderNode#adopt(long) |
| 146 | */ |
| 147 | private RenderNode(long nativePtr) { |
| 148 | mNativeRenderNode = nativePtr; |
John Reck | 119907c | 2014-08-14 09:02:01 -0700 | [diff] [blame] | 149 | mOwningView = null; |
John Reck | e45b1fd | 2014-04-15 09:50:16 -0700 | [diff] [blame] | 150 | } |
| 151 | |
| 152 | /** |
Chris Craik | 9a347f1 | 2014-06-27 17:23:47 -0700 | [diff] [blame] | 153 | * Creates a new RenderNode that can be used to record batches of |
| 154 | * drawing operations, and store / apply render properties when drawn. |
John Reck | f666ad7 | 2014-03-14 16:24:57 -0700 | [diff] [blame] | 155 | * |
Chris Craik | 9a347f1 | 2014-06-27 17:23:47 -0700 | [diff] [blame] | 156 | * @param name The name of the RenderNode, used for debugging purpose. May be null. |
John Reck | f666ad7 | 2014-03-14 16:24:57 -0700 | [diff] [blame] | 157 | * |
Chris Craik | 9a347f1 | 2014-06-27 17:23:47 -0700 | [diff] [blame] | 158 | * @return A new RenderNode. |
John Reck | f666ad7 | 2014-03-14 16:24:57 -0700 | [diff] [blame] | 159 | */ |
John Reck | 119907c | 2014-08-14 09:02:01 -0700 | [diff] [blame] | 160 | public static RenderNode create(String name, @Nullable View owningView) { |
| 161 | return new RenderNode(name, owningView); |
John Reck | f666ad7 | 2014-03-14 16:24:57 -0700 | [diff] [blame] | 162 | } |
| 163 | |
| 164 | /** |
John Reck | e45b1fd | 2014-04-15 09:50:16 -0700 | [diff] [blame] | 165 | * Adopts an existing native render node. |
| 166 | * |
| 167 | * Note: This will *NOT* incRef() on the native object, however it will |
| 168 | * decRef() when it is destroyed. The caller should have already incRef'd it |
| 169 | */ |
| 170 | public static RenderNode adopt(long nativePtr) { |
| 171 | return new RenderNode(nativePtr); |
| 172 | } |
| 173 | |
| 174 | |
| 175 | /** |
Chris Craik | 49e6c73 | 2014-03-31 12:34:11 -0700 | [diff] [blame] | 176 | * Starts recording a display list for the render node. All |
| 177 | * operations performed on the returned canvas are recorded and |
| 178 | * stored in this display list. |
John Reck | f666ad7 | 2014-03-14 16:24:57 -0700 | [diff] [blame] | 179 | * |
Chris Craik | 49e6c73 | 2014-03-31 12:34:11 -0700 | [diff] [blame] | 180 | * Calling this method will mark the render node invalid until |
Chris Craik | f6829a0 | 2015-03-10 10:28:59 -0700 | [diff] [blame] | 181 | * {@link #end(DisplayListCanvas)} is called. |
Chris Craik | 49e6c73 | 2014-03-31 12:34:11 -0700 | [diff] [blame] | 182 | * Only valid render nodes can be replayed. |
John Reck | f666ad7 | 2014-03-14 16:24:57 -0700 | [diff] [blame] | 183 | * |
Chris Craik | 49e6c73 | 2014-03-31 12:34:11 -0700 | [diff] [blame] | 184 | * @param width The width of the recording viewport |
| 185 | * @param height The height of the recording viewport |
John Reck | f666ad7 | 2014-03-14 16:24:57 -0700 | [diff] [blame] | 186 | * |
| 187 | * @return A canvas to record drawing operations. |
| 188 | * |
Chris Craik | f6829a0 | 2015-03-10 10:28:59 -0700 | [diff] [blame] | 189 | * @see #end(DisplayListCanvas) |
John Reck | f666ad7 | 2014-03-14 16:24:57 -0700 | [diff] [blame] | 190 | * @see #isValid() |
| 191 | */ |
Chris Craik | f6829a0 | 2015-03-10 10:28:59 -0700 | [diff] [blame] | 192 | public DisplayListCanvas start(int width, int height) { |
Derek Sollenberger | cc882b6 | 2015-07-09 15:51:20 -0400 | [diff] [blame] | 193 | return DisplayListCanvas.obtain(this, width, height); |
John Reck | f666ad7 | 2014-03-14 16:24:57 -0700 | [diff] [blame] | 194 | } |
| 195 | |
| 196 | /** |
| 197 | * Ends the recording for this display list. A display list cannot be |
| 198 | * replayed if recording is not finished. Calling this method marks |
| 199 | * the display list valid and {@link #isValid()} will return true. |
| 200 | * |
| 201 | * @see #start(int, int) |
| 202 | * @see #isValid() |
| 203 | */ |
Chris Craik | 3891f3a | 2015-04-02 15:28:08 -0700 | [diff] [blame] | 204 | public void end(DisplayListCanvas canvas) { |
Chris Craik | 003cc3d | 2015-10-16 10:24:55 -0700 | [diff] [blame] | 205 | long displayList = canvas.finishRecording(); |
| 206 | nSetDisplayList(mNativeRenderNode, displayList); |
John Reck | f666ad7 | 2014-03-14 16:24:57 -0700 | [diff] [blame] | 207 | canvas.recycle(); |
| 208 | mValid = true; |
| 209 | } |
| 210 | |
| 211 | /** |
| 212 | * Reset native resources. This is called when cleaning up the state of display lists |
| 213 | * during destruction of hardware resources, to ensure that we do not hold onto |
| 214 | * obsolete resources after related resources are gone. |
John Reck | f666ad7 | 2014-03-14 16:24:57 -0700 | [diff] [blame] | 215 | */ |
Chris Craik | 003cc3d | 2015-10-16 10:24:55 -0700 | [diff] [blame] | 216 | public void discardDisplayList() { |
John Reck | f666ad7 | 2014-03-14 16:24:57 -0700 | [diff] [blame] | 217 | if (!mValid) return; |
| 218 | |
Chris Craik | 003cc3d | 2015-10-16 10:24:55 -0700 | [diff] [blame] | 219 | nSetDisplayList(mNativeRenderNode, 0); |
John Reck | f666ad7 | 2014-03-14 16:24:57 -0700 | [diff] [blame] | 220 | mValid = false; |
| 221 | } |
| 222 | |
John Reck | f666ad7 | 2014-03-14 16:24:57 -0700 | [diff] [blame] | 223 | /** |
Chris Craik | df0c431 | 2014-03-28 16:55:08 -0700 | [diff] [blame] | 224 | * Returns whether the RenderNode's display list content is currently usable. |
| 225 | * If this returns false, the display list should be re-recorded prior to replaying it. |
John Reck | f666ad7 | 2014-03-14 16:24:57 -0700 | [diff] [blame] | 226 | * |
| 227 | * @return boolean true if the display list is able to be replayed, false otherwise. |
| 228 | */ |
| 229 | public boolean isValid() { return mValid; } |
| 230 | |
| 231 | long getNativeDisplayList() { |
| 232 | if (!mValid) { |
| 233 | throw new IllegalStateException("The display list is not valid."); |
| 234 | } |
John Reck | 8de65a8 | 2014-04-09 15:23:38 -0700 | [diff] [blame] | 235 | return mNativeRenderNode; |
John Reck | f666ad7 | 2014-03-14 16:24:57 -0700 | [diff] [blame] | 236 | } |
| 237 | |
| 238 | /////////////////////////////////////////////////////////////////////////// |
Chris Craik | 49e6c73 | 2014-03-31 12:34:11 -0700 | [diff] [blame] | 239 | // Matrix manipulation |
| 240 | /////////////////////////////////////////////////////////////////////////// |
| 241 | |
| 242 | public boolean hasIdentityMatrix() { |
John Reck | 8de65a8 | 2014-04-09 15:23:38 -0700 | [diff] [blame] | 243 | return nHasIdentityMatrix(mNativeRenderNode); |
Chris Craik | 49e6c73 | 2014-03-31 12:34:11 -0700 | [diff] [blame] | 244 | } |
| 245 | |
| 246 | public void getMatrix(@NonNull Matrix outMatrix) { |
John Reck | 8de65a8 | 2014-04-09 15:23:38 -0700 | [diff] [blame] | 247 | nGetTransformMatrix(mNativeRenderNode, outMatrix.native_instance); |
Chris Craik | 49e6c73 | 2014-03-31 12:34:11 -0700 | [diff] [blame] | 248 | } |
| 249 | |
| 250 | public void getInverseMatrix(@NonNull Matrix outMatrix) { |
John Reck | 8de65a8 | 2014-04-09 15:23:38 -0700 | [diff] [blame] | 251 | nGetInverseTransformMatrix(mNativeRenderNode, outMatrix.native_instance); |
Chris Craik | 49e6c73 | 2014-03-31 12:34:11 -0700 | [diff] [blame] | 252 | } |
| 253 | |
| 254 | /////////////////////////////////////////////////////////////////////////// |
| 255 | // RenderProperty Setters |
John Reck | f666ad7 | 2014-03-14 16:24:57 -0700 | [diff] [blame] | 256 | /////////////////////////////////////////////////////////////////////////// |
| 257 | |
John Reck | 25fbb3f | 2014-06-12 13:46:45 -0700 | [diff] [blame] | 258 | public boolean setLayerType(int layerType) { |
| 259 | return nSetLayerType(mNativeRenderNode, layerType); |
| 260 | } |
| 261 | |
sergeyv | 342a7e6 | 2016-03-24 16:06:46 -0700 | [diff] [blame] | 262 | public boolean setLayerPaint(@Nullable Paint paint) { |
Derek Sollenberger | dfba4d3 | 2014-09-02 15:42:54 -0400 | [diff] [blame] | 263 | return nSetLayerPaint(mNativeRenderNode, paint != null ? paint.getNativeInstance() : 0); |
John Reck | f666ad7 | 2014-03-14 16:24:57 -0700 | [diff] [blame] | 264 | } |
| 265 | |
Chris Craik | a753f4c | 2014-07-24 12:39:17 -0700 | [diff] [blame] | 266 | public boolean setClipBounds(@Nullable Rect rect) { |
| 267 | if (rect == null) { |
| 268 | return nSetClipBoundsEmpty(mNativeRenderNode); |
| 269 | } else { |
| 270 | return nSetClipBounds(mNativeRenderNode, rect.left, rect.top, rect.right, rect.bottom); |
| 271 | } |
| 272 | } |
| 273 | |
John Reck | f666ad7 | 2014-03-14 16:24:57 -0700 | [diff] [blame] | 274 | /** |
Chris Craik | 49e6c73 | 2014-03-31 12:34:11 -0700 | [diff] [blame] | 275 | * Set whether the Render node should clip itself to its bounds. This property is controlled by |
John Reck | f666ad7 | 2014-03-14 16:24:57 -0700 | [diff] [blame] | 276 | * the view's parent. |
| 277 | * |
| 278 | * @param clipToBounds true if the display list should clip to its bounds |
| 279 | */ |
John Reck | 79c7de7 | 2014-05-23 10:33:31 -0700 | [diff] [blame] | 280 | public boolean setClipToBounds(boolean clipToBounds) { |
| 281 | return nSetClipToBounds(mNativeRenderNode, clipToBounds); |
John Reck | f666ad7 | 2014-03-14 16:24:57 -0700 | [diff] [blame] | 282 | } |
| 283 | |
| 284 | /** |
John Reck | f666ad7 | 2014-03-14 16:24:57 -0700 | [diff] [blame] | 285 | * Sets whether the display list should be drawn immediately after the |
Chris Craik | 49e6c73 | 2014-03-31 12:34:11 -0700 | [diff] [blame] | 286 | * closest ancestor display list containing a projection receiver. |
John Reck | f666ad7 | 2014-03-14 16:24:57 -0700 | [diff] [blame] | 287 | * |
| 288 | * @param shouldProject true if the display list should be projected onto a |
| 289 | * containing volume. |
| 290 | */ |
John Reck | 79c7de7 | 2014-05-23 10:33:31 -0700 | [diff] [blame] | 291 | public boolean setProjectBackwards(boolean shouldProject) { |
| 292 | return nSetProjectBackwards(mNativeRenderNode, shouldProject); |
John Reck | f666ad7 | 2014-03-14 16:24:57 -0700 | [diff] [blame] | 293 | } |
| 294 | |
| 295 | /** |
| 296 | * Sets whether the display list is a projection receiver - that its parent |
| 297 | * DisplayList should draw any descendent DisplayLists with |
| 298 | * ProjectBackwards=true directly on top of it. Default value is false. |
| 299 | */ |
John Reck | 79c7de7 | 2014-05-23 10:33:31 -0700 | [diff] [blame] | 300 | public boolean setProjectionReceiver(boolean shouldRecieve) { |
| 301 | return nSetProjectionReceiver(mNativeRenderNode, shouldRecieve); |
John Reck | f666ad7 | 2014-03-14 16:24:57 -0700 | [diff] [blame] | 302 | } |
| 303 | |
| 304 | /** |
| 305 | * Sets the outline, defining the shape that casts a shadow, and the path to |
| 306 | * be clipped if setClipToOutline is set. |
| 307 | * |
Chris Craik | b49f446 | 2014-03-20 12:44:20 -0700 | [diff] [blame] | 308 | * Deep copies the data into native to simplify reference ownership. |
John Reck | f666ad7 | 2014-03-14 16:24:57 -0700 | [diff] [blame] | 309 | */ |
Chris Craik | 136d1af | 2016-04-04 13:40:39 -0700 | [diff] [blame] | 310 | public boolean setOutline(@Nullable Outline outline) { |
Chris Craik | 0645128 | 2014-07-21 10:25:54 -0700 | [diff] [blame] | 311 | if (outline == null) { |
| 312 | return nSetOutlineNone(mNativeRenderNode); |
Chris Craik | b49f446 | 2014-03-20 12:44:20 -0700 | [diff] [blame] | 313 | } |
Chris Craik | 136d1af | 2016-04-04 13:40:39 -0700 | [diff] [blame] | 314 | |
| 315 | switch(outline.mMode) { |
| 316 | case Outline.MODE_EMPTY: |
| 317 | return nSetOutlineEmpty(mNativeRenderNode); |
| 318 | case Outline.MODE_ROUND_RECT: |
| 319 | return nSetOutlineRoundRect(mNativeRenderNode, outline.mRect.left, outline.mRect.top, |
| 320 | outline.mRect.right, outline.mRect.bottom, outline.mRadius, outline.mAlpha); |
| 321 | case Outline.MODE_CONVEX_PATH: |
| 322 | return nSetOutlineConvexPath(mNativeRenderNode, outline.mPath.mNativePath, |
| 323 | outline.mAlpha); |
| 324 | } |
| 325 | |
John Reck | 79c7de7 | 2014-05-23 10:33:31 -0700 | [diff] [blame] | 326 | throw new IllegalArgumentException("Unrecognized outline?"); |
John Reck | f666ad7 | 2014-03-14 16:24:57 -0700 | [diff] [blame] | 327 | } |
| 328 | |
Chris Craik | 5c75c52 | 2014-09-05 14:08:08 -0700 | [diff] [blame] | 329 | public boolean hasShadow() { |
| 330 | return nHasShadow(mNativeRenderNode); |
| 331 | } |
| 332 | |
John Reck | f666ad7 | 2014-03-14 16:24:57 -0700 | [diff] [blame] | 333 | /** |
| 334 | * Enables or disables clipping to the outline. |
| 335 | * |
| 336 | * @param clipToOutline true if clipping to the outline. |
| 337 | */ |
John Reck | 79c7de7 | 2014-05-23 10:33:31 -0700 | [diff] [blame] | 338 | public boolean setClipToOutline(boolean clipToOutline) { |
| 339 | return nSetClipToOutline(mNativeRenderNode, clipToOutline); |
John Reck | f666ad7 | 2014-03-14 16:24:57 -0700 | [diff] [blame] | 340 | } |
| 341 | |
Chris Craik | deeda3d | 2014-05-05 19:09:33 -0700 | [diff] [blame] | 342 | public boolean getClipToOutline() { |
| 343 | return nGetClipToOutline(mNativeRenderNode); |
| 344 | } |
| 345 | |
John Reck | f666ad7 | 2014-03-14 16:24:57 -0700 | [diff] [blame] | 346 | /** |
Chris Craik | 8c271ca | 2014-03-25 10:33:01 -0700 | [diff] [blame] | 347 | * Controls the RenderNode's circular reveal clip. |
| 348 | */ |
Chris Craik | af4d04c | 2014-07-29 12:50:14 -0700 | [diff] [blame] | 349 | public boolean setRevealClip(boolean shouldClip, |
Chris Craik | 8c271ca | 2014-03-25 10:33:01 -0700 | [diff] [blame] | 350 | float x, float y, float radius) { |
Chris Craik | af4d04c | 2014-07-29 12:50:14 -0700 | [diff] [blame] | 351 | return nSetRevealClip(mNativeRenderNode, shouldClip, x, y, radius); |
Chris Craik | 8c271ca | 2014-03-25 10:33:01 -0700 | [diff] [blame] | 352 | } |
| 353 | |
| 354 | /** |
John Reck | f666ad7 | 2014-03-14 16:24:57 -0700 | [diff] [blame] | 355 | * Set the static matrix on the display list. The specified matrix is combined with other |
| 356 | * transforms (such as {@link #setScaleX(float)}, {@link #setRotation(float)}, etc.) |
| 357 | * |
| 358 | * @param matrix A transform matrix to apply to this display list |
John Reck | f666ad7 | 2014-03-14 16:24:57 -0700 | [diff] [blame] | 359 | */ |
John Reck | 79c7de7 | 2014-05-23 10:33:31 -0700 | [diff] [blame] | 360 | public boolean setStaticMatrix(Matrix matrix) { |
| 361 | return nSetStaticMatrix(mNativeRenderNode, matrix.native_instance); |
John Reck | f666ad7 | 2014-03-14 16:24:57 -0700 | [diff] [blame] | 362 | } |
| 363 | |
| 364 | /** |
| 365 | * Set the Animation matrix on the display list. This matrix exists if an Animation is |
| 366 | * currently playing on a View, and is set on the display list during at draw() time. When |
| 367 | * the Animation finishes, the matrix should be cleared by sending <code>null</code> |
| 368 | * for the matrix parameter. |
| 369 | * |
| 370 | * @param matrix The matrix, null indicates that the matrix should be cleared. |
John Reck | f666ad7 | 2014-03-14 16:24:57 -0700 | [diff] [blame] | 371 | */ |
John Reck | 79c7de7 | 2014-05-23 10:33:31 -0700 | [diff] [blame] | 372 | public boolean setAnimationMatrix(Matrix matrix) { |
| 373 | return nSetAnimationMatrix(mNativeRenderNode, |
John Reck | f666ad7 | 2014-03-14 16:24:57 -0700 | [diff] [blame] | 374 | (matrix != null) ? matrix.native_instance : 0); |
| 375 | } |
| 376 | |
| 377 | /** |
| 378 | * Sets the translucency level for the display list. |
| 379 | * |
| 380 | * @param alpha The translucency of the display list, must be a value between 0.0f and 1.0f |
| 381 | * |
| 382 | * @see View#setAlpha(float) |
| 383 | * @see #getAlpha() |
| 384 | */ |
John Reck | 79c7de7 | 2014-05-23 10:33:31 -0700 | [diff] [blame] | 385 | public boolean setAlpha(float alpha) { |
| 386 | return nSetAlpha(mNativeRenderNode, alpha); |
John Reck | f666ad7 | 2014-03-14 16:24:57 -0700 | [diff] [blame] | 387 | } |
| 388 | |
| 389 | /** |
| 390 | * Returns the translucency level of this display list. |
| 391 | * |
| 392 | * @return A value between 0.0f and 1.0f |
| 393 | * |
| 394 | * @see #setAlpha(float) |
| 395 | */ |
| 396 | public float getAlpha() { |
John Reck | 8de65a8 | 2014-04-09 15:23:38 -0700 | [diff] [blame] | 397 | return nGetAlpha(mNativeRenderNode); |
John Reck | f666ad7 | 2014-03-14 16:24:57 -0700 | [diff] [blame] | 398 | } |
| 399 | |
| 400 | /** |
| 401 | * Sets whether the display list renders content which overlaps. Non-overlapping rendering |
| 402 | * can use a fast path for alpha that avoids rendering to an offscreen buffer. By default |
| 403 | * display lists consider they do not have overlapping content. |
| 404 | * |
| 405 | * @param hasOverlappingRendering False if the content is guaranteed to be non-overlapping, |
| 406 | * true otherwise. |
| 407 | * |
| 408 | * @see android.view.View#hasOverlappingRendering() |
| 409 | * @see #hasOverlappingRendering() |
| 410 | */ |
John Reck | 79c7de7 | 2014-05-23 10:33:31 -0700 | [diff] [blame] | 411 | public boolean setHasOverlappingRendering(boolean hasOverlappingRendering) { |
| 412 | return nSetHasOverlappingRendering(mNativeRenderNode, hasOverlappingRendering); |
John Reck | f666ad7 | 2014-03-14 16:24:57 -0700 | [diff] [blame] | 413 | } |
| 414 | |
| 415 | /** |
| 416 | * Indicates whether the content of this display list overlaps. |
| 417 | * |
| 418 | * @return True if this display list renders content which overlaps, false otherwise. |
| 419 | * |
| 420 | * @see #setHasOverlappingRendering(boolean) |
| 421 | */ |
| 422 | public boolean hasOverlappingRendering() { |
| 423 | //noinspection SimplifiableIfStatement |
John Reck | 8de65a8 | 2014-04-09 15:23:38 -0700 | [diff] [blame] | 424 | return nHasOverlappingRendering(mNativeRenderNode); |
John Reck | f666ad7 | 2014-03-14 16:24:57 -0700 | [diff] [blame] | 425 | } |
| 426 | |
John Reck | 79c7de7 | 2014-05-23 10:33:31 -0700 | [diff] [blame] | 427 | public boolean setElevation(float lift) { |
| 428 | return nSetElevation(mNativeRenderNode, lift); |
Chris Craik | cc39e16 | 2014-04-25 18:34:11 -0700 | [diff] [blame] | 429 | } |
| 430 | |
| 431 | public float getElevation() { |
| 432 | return nGetElevation(mNativeRenderNode); |
| 433 | } |
| 434 | |
John Reck | f666ad7 | 2014-03-14 16:24:57 -0700 | [diff] [blame] | 435 | /** |
| 436 | * Sets the translation value for the display list on the X axis. |
| 437 | * |
| 438 | * @param translationX The X axis translation value of the display list, in pixels |
| 439 | * |
| 440 | * @see View#setTranslationX(float) |
| 441 | * @see #getTranslationX() |
| 442 | */ |
John Reck | 79c7de7 | 2014-05-23 10:33:31 -0700 | [diff] [blame] | 443 | public boolean setTranslationX(float translationX) { |
| 444 | return nSetTranslationX(mNativeRenderNode, translationX); |
John Reck | f666ad7 | 2014-03-14 16:24:57 -0700 | [diff] [blame] | 445 | } |
| 446 | |
| 447 | /** |
| 448 | * Returns the translation value for this display list on the X axis, in pixels. |
| 449 | * |
| 450 | * @see #setTranslationX(float) |
| 451 | */ |
| 452 | public float getTranslationX() { |
John Reck | 8de65a8 | 2014-04-09 15:23:38 -0700 | [diff] [blame] | 453 | return nGetTranslationX(mNativeRenderNode); |
John Reck | f666ad7 | 2014-03-14 16:24:57 -0700 | [diff] [blame] | 454 | } |
| 455 | |
| 456 | /** |
| 457 | * Sets the translation value for the display list on the Y axis. |
| 458 | * |
| 459 | * @param translationY The Y axis translation value of the display list, in pixels |
| 460 | * |
| 461 | * @see View#setTranslationY(float) |
| 462 | * @see #getTranslationY() |
| 463 | */ |
John Reck | 79c7de7 | 2014-05-23 10:33:31 -0700 | [diff] [blame] | 464 | public boolean setTranslationY(float translationY) { |
| 465 | return nSetTranslationY(mNativeRenderNode, translationY); |
John Reck | f666ad7 | 2014-03-14 16:24:57 -0700 | [diff] [blame] | 466 | } |
| 467 | |
| 468 | /** |
| 469 | * Returns the translation value for this display list on the Y axis, in pixels. |
| 470 | * |
| 471 | * @see #setTranslationY(float) |
| 472 | */ |
| 473 | public float getTranslationY() { |
John Reck | 8de65a8 | 2014-04-09 15:23:38 -0700 | [diff] [blame] | 474 | return nGetTranslationY(mNativeRenderNode); |
John Reck | f666ad7 | 2014-03-14 16:24:57 -0700 | [diff] [blame] | 475 | } |
| 476 | |
| 477 | /** |
| 478 | * Sets the translation value for the display list on the Z axis. |
| 479 | * |
| 480 | * @see View#setTranslationZ(float) |
| 481 | * @see #getTranslationZ() |
| 482 | */ |
John Reck | 79c7de7 | 2014-05-23 10:33:31 -0700 | [diff] [blame] | 483 | public boolean setTranslationZ(float translationZ) { |
| 484 | return nSetTranslationZ(mNativeRenderNode, translationZ); |
John Reck | f666ad7 | 2014-03-14 16:24:57 -0700 | [diff] [blame] | 485 | } |
| 486 | |
| 487 | /** |
| 488 | * Returns the translation value for this display list on the Z axis. |
| 489 | * |
| 490 | * @see #setTranslationZ(float) |
| 491 | */ |
| 492 | public float getTranslationZ() { |
John Reck | 8de65a8 | 2014-04-09 15:23:38 -0700 | [diff] [blame] | 493 | return nGetTranslationZ(mNativeRenderNode); |
John Reck | f666ad7 | 2014-03-14 16:24:57 -0700 | [diff] [blame] | 494 | } |
| 495 | |
| 496 | /** |
| 497 | * Sets the rotation value for the display list around the Z axis. |
| 498 | * |
| 499 | * @param rotation The rotation value of the display list, in degrees |
| 500 | * |
| 501 | * @see View#setRotation(float) |
| 502 | * @see #getRotation() |
| 503 | */ |
John Reck | 79c7de7 | 2014-05-23 10:33:31 -0700 | [diff] [blame] | 504 | public boolean setRotation(float rotation) { |
| 505 | return nSetRotation(mNativeRenderNode, rotation); |
John Reck | f666ad7 | 2014-03-14 16:24:57 -0700 | [diff] [blame] | 506 | } |
| 507 | |
| 508 | /** |
| 509 | * Returns the rotation value for this display list around the Z axis, in degrees. |
| 510 | * |
| 511 | * @see #setRotation(float) |
| 512 | */ |
| 513 | public float getRotation() { |
John Reck | 8de65a8 | 2014-04-09 15:23:38 -0700 | [diff] [blame] | 514 | return nGetRotation(mNativeRenderNode); |
John Reck | f666ad7 | 2014-03-14 16:24:57 -0700 | [diff] [blame] | 515 | } |
| 516 | |
| 517 | /** |
| 518 | * Sets the rotation value for the display list around the X axis. |
| 519 | * |
| 520 | * @param rotationX The rotation value of the display list, in degrees |
| 521 | * |
| 522 | * @see View#setRotationX(float) |
| 523 | * @see #getRotationX() |
| 524 | */ |
John Reck | 79c7de7 | 2014-05-23 10:33:31 -0700 | [diff] [blame] | 525 | public boolean setRotationX(float rotationX) { |
| 526 | return nSetRotationX(mNativeRenderNode, rotationX); |
John Reck | f666ad7 | 2014-03-14 16:24:57 -0700 | [diff] [blame] | 527 | } |
| 528 | |
| 529 | /** |
| 530 | * Returns the rotation value for this display list around the X axis, in degrees. |
| 531 | * |
| 532 | * @see #setRotationX(float) |
| 533 | */ |
| 534 | public float getRotationX() { |
John Reck | 8de65a8 | 2014-04-09 15:23:38 -0700 | [diff] [blame] | 535 | return nGetRotationX(mNativeRenderNode); |
John Reck | f666ad7 | 2014-03-14 16:24:57 -0700 | [diff] [blame] | 536 | } |
| 537 | |
| 538 | /** |
| 539 | * Sets the rotation value for the display list around the Y axis. |
| 540 | * |
| 541 | * @param rotationY The rotation value of the display list, in degrees |
| 542 | * |
| 543 | * @see View#setRotationY(float) |
| 544 | * @see #getRotationY() |
| 545 | */ |
John Reck | 79c7de7 | 2014-05-23 10:33:31 -0700 | [diff] [blame] | 546 | public boolean setRotationY(float rotationY) { |
| 547 | return nSetRotationY(mNativeRenderNode, rotationY); |
John Reck | f666ad7 | 2014-03-14 16:24:57 -0700 | [diff] [blame] | 548 | } |
| 549 | |
| 550 | /** |
| 551 | * Returns the rotation value for this display list around the Y axis, in degrees. |
| 552 | * |
| 553 | * @see #setRotationY(float) |
| 554 | */ |
| 555 | public float getRotationY() { |
John Reck | 8de65a8 | 2014-04-09 15:23:38 -0700 | [diff] [blame] | 556 | return nGetRotationY(mNativeRenderNode); |
John Reck | f666ad7 | 2014-03-14 16:24:57 -0700 | [diff] [blame] | 557 | } |
| 558 | |
| 559 | /** |
| 560 | * Sets the scale value for the display list on the X axis. |
| 561 | * |
| 562 | * @param scaleX The scale value of the display list |
| 563 | * |
| 564 | * @see View#setScaleX(float) |
| 565 | * @see #getScaleX() |
| 566 | */ |
John Reck | 79c7de7 | 2014-05-23 10:33:31 -0700 | [diff] [blame] | 567 | public boolean setScaleX(float scaleX) { |
| 568 | return nSetScaleX(mNativeRenderNode, scaleX); |
John Reck | f666ad7 | 2014-03-14 16:24:57 -0700 | [diff] [blame] | 569 | } |
| 570 | |
| 571 | /** |
| 572 | * Returns the scale value for this display list on the X axis. |
| 573 | * |
| 574 | * @see #setScaleX(float) |
| 575 | */ |
| 576 | public float getScaleX() { |
John Reck | 8de65a8 | 2014-04-09 15:23:38 -0700 | [diff] [blame] | 577 | return nGetScaleX(mNativeRenderNode); |
John Reck | f666ad7 | 2014-03-14 16:24:57 -0700 | [diff] [blame] | 578 | } |
| 579 | |
| 580 | /** |
| 581 | * Sets the scale value for the display list on the Y axis. |
| 582 | * |
| 583 | * @param scaleY The scale value of the display list |
| 584 | * |
| 585 | * @see View#setScaleY(float) |
| 586 | * @see #getScaleY() |
| 587 | */ |
John Reck | 79c7de7 | 2014-05-23 10:33:31 -0700 | [diff] [blame] | 588 | public boolean setScaleY(float scaleY) { |
| 589 | return nSetScaleY(mNativeRenderNode, scaleY); |
John Reck | f666ad7 | 2014-03-14 16:24:57 -0700 | [diff] [blame] | 590 | } |
| 591 | |
| 592 | /** |
| 593 | * Returns the scale value for this display list on the Y axis. |
| 594 | * |
| 595 | * @see #setScaleY(float) |
| 596 | */ |
| 597 | public float getScaleY() { |
John Reck | 8de65a8 | 2014-04-09 15:23:38 -0700 | [diff] [blame] | 598 | return nGetScaleY(mNativeRenderNode); |
John Reck | f666ad7 | 2014-03-14 16:24:57 -0700 | [diff] [blame] | 599 | } |
| 600 | |
| 601 | /** |
John Reck | f666ad7 | 2014-03-14 16:24:57 -0700 | [diff] [blame] | 602 | * Sets the pivot value for the display list on the X axis |
| 603 | * |
| 604 | * @param pivotX The pivot value of the display list on the X axis, in pixels |
| 605 | * |
| 606 | * @see View#setPivotX(float) |
| 607 | * @see #getPivotX() |
| 608 | */ |
John Reck | 79c7de7 | 2014-05-23 10:33:31 -0700 | [diff] [blame] | 609 | public boolean setPivotX(float pivotX) { |
| 610 | return nSetPivotX(mNativeRenderNode, pivotX); |
John Reck | f666ad7 | 2014-03-14 16:24:57 -0700 | [diff] [blame] | 611 | } |
| 612 | |
| 613 | /** |
| 614 | * Returns the pivot value for this display list on the X axis, in pixels. |
| 615 | * |
| 616 | * @see #setPivotX(float) |
| 617 | */ |
| 618 | public float getPivotX() { |
John Reck | 8de65a8 | 2014-04-09 15:23:38 -0700 | [diff] [blame] | 619 | return nGetPivotX(mNativeRenderNode); |
John Reck | f666ad7 | 2014-03-14 16:24:57 -0700 | [diff] [blame] | 620 | } |
| 621 | |
| 622 | /** |
| 623 | * Sets the pivot value for the display list on the Y axis |
| 624 | * |
| 625 | * @param pivotY The pivot value of the display list on the Y axis, in pixels |
| 626 | * |
| 627 | * @see View#setPivotY(float) |
| 628 | * @see #getPivotY() |
| 629 | */ |
John Reck | 79c7de7 | 2014-05-23 10:33:31 -0700 | [diff] [blame] | 630 | public boolean setPivotY(float pivotY) { |
| 631 | return nSetPivotY(mNativeRenderNode, pivotY); |
John Reck | f666ad7 | 2014-03-14 16:24:57 -0700 | [diff] [blame] | 632 | } |
| 633 | |
| 634 | /** |
| 635 | * Returns the pivot value for this display list on the Y axis, in pixels. |
| 636 | * |
| 637 | * @see #setPivotY(float) |
| 638 | */ |
| 639 | public float getPivotY() { |
John Reck | 8de65a8 | 2014-04-09 15:23:38 -0700 | [diff] [blame] | 640 | return nGetPivotY(mNativeRenderNode); |
John Reck | f666ad7 | 2014-03-14 16:24:57 -0700 | [diff] [blame] | 641 | } |
| 642 | |
Chris Craik | 49e6c73 | 2014-03-31 12:34:11 -0700 | [diff] [blame] | 643 | public boolean isPivotExplicitlySet() { |
John Reck | 8de65a8 | 2014-04-09 15:23:38 -0700 | [diff] [blame] | 644 | return nIsPivotExplicitlySet(mNativeRenderNode); |
Chris Craik | 49e6c73 | 2014-03-31 12:34:11 -0700 | [diff] [blame] | 645 | } |
| 646 | |
John Reck | f666ad7 | 2014-03-14 16:24:57 -0700 | [diff] [blame] | 647 | /** |
| 648 | * Sets the camera distance for the display list. Refer to |
| 649 | * {@link View#setCameraDistance(float)} for more information on how to |
| 650 | * use this property. |
| 651 | * |
| 652 | * @param distance The distance in Z of the camera of the display list |
| 653 | * |
| 654 | * @see View#setCameraDistance(float) |
| 655 | * @see #getCameraDistance() |
| 656 | */ |
John Reck | 79c7de7 | 2014-05-23 10:33:31 -0700 | [diff] [blame] | 657 | public boolean setCameraDistance(float distance) { |
| 658 | return nSetCameraDistance(mNativeRenderNode, distance); |
John Reck | f666ad7 | 2014-03-14 16:24:57 -0700 | [diff] [blame] | 659 | } |
| 660 | |
| 661 | /** |
| 662 | * Returns the distance in Z of the camera of the display list. |
| 663 | * |
| 664 | * @see #setCameraDistance(float) |
| 665 | */ |
| 666 | public float getCameraDistance() { |
John Reck | 8de65a8 | 2014-04-09 15:23:38 -0700 | [diff] [blame] | 667 | return nGetCameraDistance(mNativeRenderNode); |
John Reck | f666ad7 | 2014-03-14 16:24:57 -0700 | [diff] [blame] | 668 | } |
| 669 | |
| 670 | /** |
| 671 | * Sets the left position for the display list. |
| 672 | * |
| 673 | * @param left The left position, in pixels, of the display list |
| 674 | * |
| 675 | * @see View#setLeft(int) |
John Reck | f666ad7 | 2014-03-14 16:24:57 -0700 | [diff] [blame] | 676 | */ |
John Reck | 79c7de7 | 2014-05-23 10:33:31 -0700 | [diff] [blame] | 677 | public boolean setLeft(int left) { |
| 678 | return nSetLeft(mNativeRenderNode, left); |
John Reck | f666ad7 | 2014-03-14 16:24:57 -0700 | [diff] [blame] | 679 | } |
| 680 | |
| 681 | /** |
John Reck | f666ad7 | 2014-03-14 16:24:57 -0700 | [diff] [blame] | 682 | * Sets the top position for the display list. |
| 683 | * |
| 684 | * @param top The top position, in pixels, of the display list |
| 685 | * |
| 686 | * @see View#setTop(int) |
John Reck | f666ad7 | 2014-03-14 16:24:57 -0700 | [diff] [blame] | 687 | */ |
John Reck | 79c7de7 | 2014-05-23 10:33:31 -0700 | [diff] [blame] | 688 | public boolean setTop(int top) { |
| 689 | return nSetTop(mNativeRenderNode, top); |
John Reck | f666ad7 | 2014-03-14 16:24:57 -0700 | [diff] [blame] | 690 | } |
| 691 | |
| 692 | /** |
John Reck | f666ad7 | 2014-03-14 16:24:57 -0700 | [diff] [blame] | 693 | * Sets the right position for the display list. |
| 694 | * |
| 695 | * @param right The right position, in pixels, of the display list |
| 696 | * |
| 697 | * @see View#setRight(int) |
John Reck | f666ad7 | 2014-03-14 16:24:57 -0700 | [diff] [blame] | 698 | */ |
John Reck | 79c7de7 | 2014-05-23 10:33:31 -0700 | [diff] [blame] | 699 | public boolean setRight(int right) { |
| 700 | return nSetRight(mNativeRenderNode, right); |
John Reck | f666ad7 | 2014-03-14 16:24:57 -0700 | [diff] [blame] | 701 | } |
| 702 | |
| 703 | /** |
John Reck | f666ad7 | 2014-03-14 16:24:57 -0700 | [diff] [blame] | 704 | * Sets the bottom position for the display list. |
| 705 | * |
| 706 | * @param bottom The bottom position, in pixels, of the display list |
| 707 | * |
| 708 | * @see View#setBottom(int) |
John Reck | f666ad7 | 2014-03-14 16:24:57 -0700 | [diff] [blame] | 709 | */ |
John Reck | 79c7de7 | 2014-05-23 10:33:31 -0700 | [diff] [blame] | 710 | public boolean setBottom(int bottom) { |
| 711 | return nSetBottom(mNativeRenderNode, bottom); |
John Reck | f666ad7 | 2014-03-14 16:24:57 -0700 | [diff] [blame] | 712 | } |
| 713 | |
| 714 | /** |
John Reck | f666ad7 | 2014-03-14 16:24:57 -0700 | [diff] [blame] | 715 | * Sets the left and top positions for the display list |
| 716 | * |
| 717 | * @param left The left position of the display list, in pixels |
| 718 | * @param top The top position of the display list, in pixels |
| 719 | * @param right The right position of the display list, in pixels |
| 720 | * @param bottom The bottom position of the display list, in pixels |
| 721 | * |
| 722 | * @see View#setLeft(int) |
| 723 | * @see View#setTop(int) |
| 724 | * @see View#setRight(int) |
| 725 | * @see View#setBottom(int) |
| 726 | */ |
John Reck | 79c7de7 | 2014-05-23 10:33:31 -0700 | [diff] [blame] | 727 | public boolean setLeftTopRightBottom(int left, int top, int right, int bottom) { |
| 728 | return nSetLeftTopRightBottom(mNativeRenderNode, left, top, right, bottom); |
John Reck | f666ad7 | 2014-03-14 16:24:57 -0700 | [diff] [blame] | 729 | } |
| 730 | |
| 731 | /** |
| 732 | * Offsets the left and right positions for the display list |
| 733 | * |
| 734 | * @param offset The amount that the left and right positions of the display |
| 735 | * list are offset, in pixels |
| 736 | * |
| 737 | * @see View#offsetLeftAndRight(int) |
| 738 | */ |
Chris Craik | a753f4c | 2014-07-24 12:39:17 -0700 | [diff] [blame] | 739 | public boolean offsetLeftAndRight(int offset) { |
John Reck | 79c7de7 | 2014-05-23 10:33:31 -0700 | [diff] [blame] | 740 | return nOffsetLeftAndRight(mNativeRenderNode, offset); |
John Reck | f666ad7 | 2014-03-14 16:24:57 -0700 | [diff] [blame] | 741 | } |
| 742 | |
| 743 | /** |
| 744 | * Offsets the top and bottom values for the display list |
| 745 | * |
| 746 | * @param offset The amount that the top and bottom positions of the display |
| 747 | * list are offset, in pixels |
| 748 | * |
| 749 | * @see View#offsetTopAndBottom(int) |
| 750 | */ |
Chris Craik | a753f4c | 2014-07-24 12:39:17 -0700 | [diff] [blame] | 751 | public boolean offsetTopAndBottom(int offset) { |
John Reck | 79c7de7 | 2014-05-23 10:33:31 -0700 | [diff] [blame] | 752 | return nOffsetTopAndBottom(mNativeRenderNode, offset); |
John Reck | f666ad7 | 2014-03-14 16:24:57 -0700 | [diff] [blame] | 753 | } |
| 754 | |
| 755 | /** |
| 756 | * Outputs the display list to the log. This method exists for use by |
| 757 | * tools to output display lists for selected nodes to the log. |
John Reck | f666ad7 | 2014-03-14 16:24:57 -0700 | [diff] [blame] | 758 | */ |
| 759 | public void output() { |
John Reck | 8de65a8 | 2014-04-09 15:23:38 -0700 | [diff] [blame] | 760 | nOutput(mNativeRenderNode); |
John Reck | f666ad7 | 2014-03-14 16:24:57 -0700 | [diff] [blame] | 761 | } |
| 762 | |
John Reck | fe5e7b7 | 2014-05-23 17:42:28 -0700 | [diff] [blame] | 763 | /** |
| 764 | * Gets the size of the DisplayList for debug purposes. |
| 765 | */ |
| 766 | public int getDebugSize() { |
| 767 | return nGetDebugSize(mNativeRenderNode); |
| 768 | } |
| 769 | |
John Reck | 44b49f0 | 2016-03-25 14:29:48 -0700 | [diff] [blame] | 770 | /** |
| 771 | * Called by native when the passed displaylist is removed from the draw tree |
| 772 | */ |
| 773 | void onRenderNodeDetached() { |
| 774 | discardDisplayList(); |
| 775 | if (mOwningView != null) { |
| 776 | mOwningView.onRenderNodeDetached(this); |
| 777 | } |
| 778 | } |
| 779 | |
John Reck | f666ad7 | 2014-03-14 16:24:57 -0700 | [diff] [blame] | 780 | /////////////////////////////////////////////////////////////////////////// |
John Reck | e45b1fd | 2014-04-15 09:50:16 -0700 | [diff] [blame] | 781 | // Animations |
| 782 | /////////////////////////////////////////////////////////////////////////// |
| 783 | |
| 784 | public void addAnimator(RenderNodeAnimator animator) { |
John Reck | 119907c | 2014-08-14 09:02:01 -0700 | [diff] [blame] | 785 | if (mOwningView == null || mOwningView.mAttachInfo == null) { |
| 786 | throw new IllegalStateException("Cannot start this animator on a detached view!"); |
| 787 | } |
John Reck | e45b1fd | 2014-04-15 09:50:16 -0700 | [diff] [blame] | 788 | nAddAnimator(mNativeRenderNode, animator.getNativeAnimator()); |
John Reck | 119907c | 2014-08-14 09:02:01 -0700 | [diff] [blame] | 789 | mOwningView.mAttachInfo.mViewRootImpl.registerAnimatingRenderNode(this); |
| 790 | } |
| 791 | |
Doris Liu | 8b08320 | 2016-02-19 21:46:06 +0000 | [diff] [blame] | 792 | public boolean isAttached() { |
| 793 | return mOwningView != null && mOwningView.mAttachInfo != null; |
| 794 | } |
| 795 | |
Doris Liu | 28cfd20 | 2016-02-22 16:51:40 -0800 | [diff] [blame] | 796 | public void addAnimator(AnimatedVectorDrawable.VectorDrawableAnimatorRT animatorSet) { |
Doris Liu | 766431a | 2016-02-04 22:17:11 +0000 | [diff] [blame] | 797 | if (mOwningView == null || mOwningView.mAttachInfo == null) { |
| 798 | throw new IllegalStateException("Cannot start this animator on a detached view!"); |
| 799 | } |
| 800 | nAddAnimator(mNativeRenderNode, animatorSet.getAnimatorNativePtr()); |
| 801 | mOwningView.mAttachInfo.mViewRootImpl.registerAnimatingRenderNode(this); |
| 802 | } |
| 803 | |
John Reck | 119907c | 2014-08-14 09:02:01 -0700 | [diff] [blame] | 804 | public void endAllAnimators() { |
| 805 | nEndAllAnimators(mNativeRenderNode); |
John Reck | e45b1fd | 2014-04-15 09:50:16 -0700 | [diff] [blame] | 806 | } |
| 807 | |
John Reck | e45b1fd | 2014-04-15 09:50:16 -0700 | [diff] [blame] | 808 | /////////////////////////////////////////////////////////////////////////// |
John Reck | f666ad7 | 2014-03-14 16:24:57 -0700 | [diff] [blame] | 809 | // Native methods |
| 810 | /////////////////////////////////////////////////////////////////////////// |
| 811 | |
John Reck | 44b49f0 | 2016-03-25 14:29:48 -0700 | [diff] [blame] | 812 | // Intentionally not static because it acquires a reference to 'this' |
| 813 | private native long nCreate(String name); |
| 814 | |
John Reck | 8de65a8 | 2014-04-09 15:23:38 -0700 | [diff] [blame] | 815 | private static native void nDestroyRenderNode(long renderNode); |
Chris Craik | 003cc3d | 2015-10-16 10:24:55 -0700 | [diff] [blame] | 816 | private static native void nSetDisplayList(long renderNode, long newData); |
John Reck | f666ad7 | 2014-03-14 16:24:57 -0700 | [diff] [blame] | 817 | |
Chris Craik | 49e6c73 | 2014-03-31 12:34:11 -0700 | [diff] [blame] | 818 | // Matrix |
| 819 | |
John Reck | 8de65a8 | 2014-04-09 15:23:38 -0700 | [diff] [blame] | 820 | private static native void nGetTransformMatrix(long renderNode, long nativeMatrix); |
| 821 | private static native void nGetInverseTransformMatrix(long renderNode, long nativeMatrix); |
| 822 | private static native boolean nHasIdentityMatrix(long renderNode); |
Chris Craik | 49e6c73 | 2014-03-31 12:34:11 -0700 | [diff] [blame] | 823 | |
John Reck | f666ad7 | 2014-03-14 16:24:57 -0700 | [diff] [blame] | 824 | // Properties |
| 825 | |
Chris Craik | a753f4c | 2014-07-24 12:39:17 -0700 | [diff] [blame] | 826 | private static native boolean nOffsetTopAndBottom(long renderNode, int offset); |
| 827 | private static native boolean nOffsetLeftAndRight(long renderNode, int offset); |
John Reck | 79c7de7 | 2014-05-23 10:33:31 -0700 | [diff] [blame] | 828 | private static native boolean nSetLeftTopRightBottom(long renderNode, int left, int top, |
John Reck | f666ad7 | 2014-03-14 16:24:57 -0700 | [diff] [blame] | 829 | int right, int bottom); |
John Reck | 79c7de7 | 2014-05-23 10:33:31 -0700 | [diff] [blame] | 830 | private static native boolean nSetBottom(long renderNode, int bottom); |
| 831 | private static native boolean nSetRight(long renderNode, int right); |
| 832 | private static native boolean nSetTop(long renderNode, int top); |
| 833 | private static native boolean nSetLeft(long renderNode, int left); |
| 834 | private static native boolean nSetCameraDistance(long renderNode, float distance); |
| 835 | private static native boolean nSetPivotY(long renderNode, float pivotY); |
| 836 | private static native boolean nSetPivotX(long renderNode, float pivotX); |
John Reck | 25fbb3f | 2014-06-12 13:46:45 -0700 | [diff] [blame] | 837 | private static native boolean nSetLayerType(long renderNode, int layerType); |
| 838 | private static native boolean nSetLayerPaint(long renderNode, long paint); |
John Reck | 79c7de7 | 2014-05-23 10:33:31 -0700 | [diff] [blame] | 839 | private static native boolean nSetClipToBounds(long renderNode, boolean clipToBounds); |
Chris Craik | a753f4c | 2014-07-24 12:39:17 -0700 | [diff] [blame] | 840 | private static native boolean nSetClipBounds(long renderNode, int left, int top, |
| 841 | int right, int bottom); |
| 842 | private static native boolean nSetClipBoundsEmpty(long renderNode); |
John Reck | 79c7de7 | 2014-05-23 10:33:31 -0700 | [diff] [blame] | 843 | private static native boolean nSetProjectBackwards(long renderNode, boolean shouldProject); |
| 844 | private static native boolean nSetProjectionReceiver(long renderNode, boolean shouldRecieve); |
| 845 | private static native boolean nSetOutlineRoundRect(long renderNode, int left, int top, |
Chris Craik | 77b5cad | 2014-07-30 18:23:07 -0700 | [diff] [blame] | 846 | int right, int bottom, float radius, float alpha); |
| 847 | private static native boolean nSetOutlineConvexPath(long renderNode, long nativePath, |
| 848 | float alpha); |
John Reck | 79c7de7 | 2014-05-23 10:33:31 -0700 | [diff] [blame] | 849 | private static native boolean nSetOutlineEmpty(long renderNode); |
Chris Craik | 0645128 | 2014-07-21 10:25:54 -0700 | [diff] [blame] | 850 | private static native boolean nSetOutlineNone(long renderNode); |
Chris Craik | 5c75c52 | 2014-09-05 14:08:08 -0700 | [diff] [blame] | 851 | private static native boolean nHasShadow(long renderNode); |
John Reck | 79c7de7 | 2014-05-23 10:33:31 -0700 | [diff] [blame] | 852 | private static native boolean nSetClipToOutline(long renderNode, boolean clipToOutline); |
| 853 | private static native boolean nSetRevealClip(long renderNode, |
Chris Craik | af4d04c | 2014-07-29 12:50:14 -0700 | [diff] [blame] | 854 | boolean shouldClip, float x, float y, float radius); |
John Reck | 79c7de7 | 2014-05-23 10:33:31 -0700 | [diff] [blame] | 855 | private static native boolean nSetAlpha(long renderNode, float alpha); |
| 856 | private static native boolean nSetHasOverlappingRendering(long renderNode, |
John Reck | f666ad7 | 2014-03-14 16:24:57 -0700 | [diff] [blame] | 857 | boolean hasOverlappingRendering); |
John Reck | 79c7de7 | 2014-05-23 10:33:31 -0700 | [diff] [blame] | 858 | private static native boolean nSetElevation(long renderNode, float lift); |
| 859 | private static native boolean nSetTranslationX(long renderNode, float translationX); |
| 860 | private static native boolean nSetTranslationY(long renderNode, float translationY); |
| 861 | private static native boolean nSetTranslationZ(long renderNode, float translationZ); |
| 862 | private static native boolean nSetRotation(long renderNode, float rotation); |
| 863 | private static native boolean nSetRotationX(long renderNode, float rotationX); |
| 864 | private static native boolean nSetRotationY(long renderNode, float rotationY); |
| 865 | private static native boolean nSetScaleX(long renderNode, float scaleX); |
| 866 | private static native boolean nSetScaleY(long renderNode, float scaleY); |
| 867 | private static native boolean nSetStaticMatrix(long renderNode, long nativeMatrix); |
| 868 | private static native boolean nSetAnimationMatrix(long renderNode, long animationMatrix); |
John Reck | f666ad7 | 2014-03-14 16:24:57 -0700 | [diff] [blame] | 869 | |
John Reck | 8de65a8 | 2014-04-09 15:23:38 -0700 | [diff] [blame] | 870 | private static native boolean nHasOverlappingRendering(long renderNode); |
Chris Craik | deeda3d | 2014-05-05 19:09:33 -0700 | [diff] [blame] | 871 | private static native boolean nGetClipToOutline(long renderNode); |
John Reck | 8de65a8 | 2014-04-09 15:23:38 -0700 | [diff] [blame] | 872 | private static native float nGetAlpha(long renderNode); |
John Reck | 8de65a8 | 2014-04-09 15:23:38 -0700 | [diff] [blame] | 873 | private static native float nGetCameraDistance(long renderNode); |
| 874 | private static native float nGetScaleX(long renderNode); |
| 875 | private static native float nGetScaleY(long renderNode); |
Chris Craik | cc39e16 | 2014-04-25 18:34:11 -0700 | [diff] [blame] | 876 | private static native float nGetElevation(long renderNode); |
John Reck | 8de65a8 | 2014-04-09 15:23:38 -0700 | [diff] [blame] | 877 | private static native float nGetTranslationX(long renderNode); |
| 878 | private static native float nGetTranslationY(long renderNode); |
| 879 | private static native float nGetTranslationZ(long renderNode); |
| 880 | private static native float nGetRotation(long renderNode); |
| 881 | private static native float nGetRotationX(long renderNode); |
| 882 | private static native float nGetRotationY(long renderNode); |
| 883 | private static native boolean nIsPivotExplicitlySet(long renderNode); |
| 884 | private static native float nGetPivotX(long renderNode); |
| 885 | private static native float nGetPivotY(long renderNode); |
| 886 | private static native void nOutput(long renderNode); |
John Reck | fe5e7b7 | 2014-05-23 17:42:28 -0700 | [diff] [blame] | 887 | private static native int nGetDebugSize(long renderNode); |
John Reck | f666ad7 | 2014-03-14 16:24:57 -0700 | [diff] [blame] | 888 | |
John Reck | f648108 | 2016-02-02 15:18:23 -0800 | [diff] [blame] | 889 | private static native void nRequestPositionUpdates(long renderNode, SurfaceView callback); |
| 890 | |
John Reck | f666ad7 | 2014-03-14 16:24:57 -0700 | [diff] [blame] | 891 | /////////////////////////////////////////////////////////////////////////// |
John Reck | e45b1fd | 2014-04-15 09:50:16 -0700 | [diff] [blame] | 892 | // Animations |
| 893 | /////////////////////////////////////////////////////////////////////////// |
| 894 | |
| 895 | private static native void nAddAnimator(long renderNode, long animatorPtr); |
John Reck | 119907c | 2014-08-14 09:02:01 -0700 | [diff] [blame] | 896 | private static native void nEndAllAnimators(long renderNode); |
John Reck | e45b1fd | 2014-04-15 09:50:16 -0700 | [diff] [blame] | 897 | |
| 898 | /////////////////////////////////////////////////////////////////////////// |
John Reck | f666ad7 | 2014-03-14 16:24:57 -0700 | [diff] [blame] | 899 | // Finalization |
| 900 | /////////////////////////////////////////////////////////////////////////// |
| 901 | |
| 902 | @Override |
| 903 | protected void finalize() throws Throwable { |
| 904 | try { |
John Reck | 8de65a8 | 2014-04-09 15:23:38 -0700 | [diff] [blame] | 905 | nDestroyRenderNode(mNativeRenderNode); |
John Reck | f666ad7 | 2014-03-14 16:24:57 -0700 | [diff] [blame] | 906 | } finally { |
| 907 | super.finalize(); |
| 908 | } |
| 909 | } |
| 910 | } |