Alan Viverette | 3da604b | 2020-06-10 18:34:39 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2016 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 com.android.layoutlib.bridge.android.graphics; |
| 18 | |
| 19 | import android.graphics.Bitmap; |
| 20 | import android.graphics.Canvas; |
| 21 | import android.graphics.Matrix; |
| 22 | import android.graphics.NinePatch; |
| 23 | import android.graphics.Paint; |
| 24 | import android.graphics.Path; |
| 25 | import android.graphics.Picture; |
| 26 | import android.graphics.PorterDuff.Mode; |
| 27 | import android.graphics.Rect; |
| 28 | import android.graphics.RectF; |
| 29 | |
| 30 | /** |
| 31 | * Canvas implementation that does not do any rendering |
| 32 | */ |
| 33 | public class NopCanvas extends Canvas { |
| 34 | private boolean mIsInitialized = false; |
| 35 | |
| 36 | public NopCanvas() { |
| 37 | super(); |
| 38 | mIsInitialized = true; |
| 39 | } |
| 40 | |
| 41 | @Override |
| 42 | public boolean isHardwareAccelerated() { |
| 43 | // We return true the first time so there are no allocations for the software renderer in |
| 44 | // the constructor |
| 45 | return !mIsInitialized; |
| 46 | } |
| 47 | |
| 48 | @Override |
| 49 | public int save() { |
| 50 | return 0; |
| 51 | } |
| 52 | |
| 53 | @Override |
| 54 | public int save(int saveFlags) { |
| 55 | return 0; |
| 56 | } |
| 57 | |
| 58 | @Override |
| 59 | public int saveLayer(RectF bounds, Paint paint, int saveFlags) { |
| 60 | return 0; |
| 61 | } |
| 62 | |
| 63 | @Override |
| 64 | public int saveLayer(RectF bounds, Paint paint) { |
| 65 | return 0; |
| 66 | } |
| 67 | |
| 68 | @Override |
| 69 | public int saveLayer(float left, float top, float right, float bottom, Paint paint, |
| 70 | int saveFlags) { |
| 71 | return 0; |
| 72 | } |
| 73 | |
| 74 | @Override |
| 75 | public int saveLayer(float left, float top, float right, float bottom, Paint paint) { |
| 76 | return 0; |
| 77 | } |
| 78 | |
| 79 | @Override |
| 80 | public int saveLayerAlpha(RectF bounds, int alpha, int saveFlags) { |
| 81 | return 0; |
| 82 | } |
| 83 | |
| 84 | @Override |
| 85 | public int saveLayerAlpha(RectF bounds, int alpha) { |
| 86 | return 0; |
| 87 | } |
| 88 | |
| 89 | @Override |
| 90 | public int saveLayerAlpha(float left, float top, float right, float bottom, int alpha, |
| 91 | int saveFlags) { |
| 92 | return 0; |
| 93 | } |
| 94 | |
| 95 | @Override |
| 96 | public int saveLayerAlpha(float left, float top, float right, float bottom, int alpha) { |
| 97 | return 0; |
| 98 | } |
| 99 | |
| 100 | @Override |
| 101 | public void restore() { |
| 102 | } |
| 103 | |
| 104 | @Override |
| 105 | public int getSaveCount() { |
| 106 | return 0; |
| 107 | } |
| 108 | |
| 109 | @Override |
| 110 | public void restoreToCount(int saveCount) { |
| 111 | } |
| 112 | |
| 113 | @Override |
| 114 | public void drawRGB(int r, int g, int b) { |
| 115 | } |
| 116 | |
| 117 | @Override |
| 118 | public void drawARGB(int a, int r, int g, int b) { |
| 119 | } |
| 120 | |
| 121 | @Override |
| 122 | public void drawColor(int color) { |
| 123 | } |
| 124 | |
| 125 | @Override |
| 126 | public void drawColor(int color, Mode mode) { |
| 127 | } |
| 128 | |
| 129 | @Override |
| 130 | public void drawPaint(Paint paint) { |
| 131 | } |
| 132 | |
| 133 | @Override |
| 134 | public void drawPoints(float[] pts, int offset, int count, Paint paint) { |
| 135 | } |
| 136 | |
| 137 | @Override |
| 138 | public void drawPoints(float[] pts, Paint paint) { |
| 139 | } |
| 140 | |
| 141 | @Override |
| 142 | public void drawPoint(float x, float y, Paint paint) { |
| 143 | } |
| 144 | |
| 145 | @Override |
| 146 | public void drawLine(float startX, float startY, float stopX, float stopY, Paint paint) { |
| 147 | } |
| 148 | |
| 149 | @Override |
| 150 | public void drawLines(float[] pts, int offset, int count, Paint paint) { |
| 151 | } |
| 152 | |
| 153 | @Override |
| 154 | public void drawLines(float[] pts, Paint paint) { |
| 155 | } |
| 156 | |
| 157 | @Override |
| 158 | public void drawRect(RectF rect, Paint paint) { |
| 159 | } |
| 160 | |
| 161 | @Override |
| 162 | public void drawRect(Rect r, Paint paint) { |
| 163 | } |
| 164 | |
| 165 | @Override |
| 166 | public void drawRect(float left, float top, float right, float bottom, Paint paint) { |
| 167 | } |
| 168 | |
| 169 | @Override |
| 170 | public void drawOval(RectF oval, Paint paint) { |
| 171 | } |
| 172 | |
| 173 | @Override |
| 174 | public void drawOval(float left, float top, float right, float bottom, Paint paint) { |
| 175 | } |
| 176 | |
| 177 | @Override |
| 178 | public void drawCircle(float cx, float cy, float radius, Paint paint) { |
| 179 | } |
| 180 | |
| 181 | @Override |
| 182 | public void drawArc(RectF oval, float startAngle, float sweepAngle, boolean useCenter, |
| 183 | Paint paint) { |
| 184 | } |
| 185 | |
| 186 | @Override |
| 187 | public void drawArc(float left, float top, float right, float bottom, float startAngle, |
| 188 | float sweepAngle, boolean useCenter, Paint paint) { |
| 189 | } |
| 190 | |
| 191 | @Override |
| 192 | public void drawRoundRect(RectF rect, float rx, float ry, Paint paint) { |
| 193 | } |
| 194 | |
| 195 | @Override |
| 196 | public void drawRoundRect(float left, float top, float right, float bottom, float rx, float ry, |
| 197 | Paint paint) { |
| 198 | } |
| 199 | |
| 200 | @Override |
| 201 | public void drawPath(Path path, Paint paint) { |
| 202 | } |
| 203 | |
| 204 | @Override |
| 205 | protected void throwIfCannotDraw(Bitmap bitmap) { |
| 206 | } |
| 207 | |
| 208 | @Override |
| 209 | public void drawPatch(NinePatch patch, Rect dst, Paint paint) { |
| 210 | } |
| 211 | |
| 212 | @Override |
| 213 | public void drawPatch(NinePatch patch, RectF dst, Paint paint) { |
| 214 | } |
| 215 | |
| 216 | @Override |
| 217 | public void drawBitmap(Bitmap bitmap, float left, float top, Paint paint) { |
| 218 | } |
| 219 | |
| 220 | @Override |
| 221 | public void drawBitmap(Bitmap bitmap, Rect src, RectF dst, Paint paint) { |
| 222 | } |
| 223 | |
| 224 | @Override |
| 225 | public void drawBitmap(Bitmap bitmap, Rect src, Rect dst, Paint paint) { |
| 226 | } |
| 227 | |
| 228 | @Override |
| 229 | public void drawBitmap(int[] colors, int offset, int stride, float x, float y, int width, |
| 230 | int height, boolean hasAlpha, Paint paint) { |
| 231 | } |
| 232 | |
| 233 | @Override |
| 234 | public void drawBitmap(int[] colors, int offset, int stride, int x, int y, int width, |
| 235 | int height, boolean hasAlpha, Paint paint) { |
| 236 | } |
| 237 | |
| 238 | @Override |
| 239 | public void drawBitmap(Bitmap bitmap, Matrix matrix, Paint paint) { |
| 240 | } |
| 241 | |
| 242 | @Override |
| 243 | public void drawBitmapMesh(Bitmap bitmap, int meshWidth, int meshHeight, float[] verts, |
| 244 | int vertOffset, int[] colors, int colorOffset, Paint paint) { |
| 245 | } |
| 246 | |
| 247 | @Override |
| 248 | public void drawVertices(VertexMode mode, int vertexCount, float[] verts, int vertOffset, |
| 249 | float[] texs, int texOffset, int[] colors, int colorOffset, short[] indices, |
| 250 | int indexOffset, int indexCount, Paint paint) { |
| 251 | } |
| 252 | |
| 253 | @Override |
| 254 | public void drawText(char[] text, int index, int count, float x, float y, Paint paint) { |
| 255 | } |
| 256 | |
| 257 | @Override |
| 258 | public void drawText(String text, float x, float y, Paint paint) { |
| 259 | } |
| 260 | |
| 261 | @Override |
| 262 | public void drawText(String text, int start, int end, float x, float y, Paint paint) { |
| 263 | } |
| 264 | |
| 265 | @Override |
| 266 | public void drawText(CharSequence text, int start, int end, float x, float y, Paint paint) { |
| 267 | } |
| 268 | |
| 269 | @Override |
| 270 | public void drawTextRun(char[] text, int index, int count, int contextIndex, int contextCount, |
| 271 | float x, float y, boolean isRtl, Paint paint) { |
| 272 | } |
| 273 | |
| 274 | @Override |
| 275 | public void drawTextRun(CharSequence text, int start, int end, int contextStart, int contextEnd, |
| 276 | float x, float y, boolean isRtl, Paint paint) { |
| 277 | } |
| 278 | |
| 279 | @Override |
| 280 | public void drawPosText(char[] text, int index, int count, float[] pos, Paint paint) { |
| 281 | } |
| 282 | |
| 283 | @Override |
| 284 | public void drawPosText(String text, float[] pos, Paint paint) { |
| 285 | } |
| 286 | |
| 287 | @Override |
| 288 | public void drawTextOnPath(char[] text, int index, int count, Path path, float hOffset, |
| 289 | float vOffset, Paint paint) { |
| 290 | } |
| 291 | |
| 292 | @Override |
| 293 | public void drawTextOnPath(String text, Path path, float hOffset, float vOffset, Paint paint) { |
| 294 | } |
| 295 | |
| 296 | @Override |
| 297 | public void drawPicture(Picture picture) { |
| 298 | } |
| 299 | |
| 300 | @Override |
| 301 | public void drawPicture(Picture picture, RectF dst) { |
| 302 | } |
| 303 | |
| 304 | @Override |
| 305 | public void drawPicture(Picture picture, Rect dst) { |
| 306 | } |
| 307 | } |