GLES20Canvas.java revision 85bf02fc16784d935fb9eebfa9cb20fe46ff7951
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 17package android.view; 18 19import android.graphics.Bitmap; 20import android.graphics.Canvas; 21import android.graphics.DrawFilter; 22import android.graphics.Matrix; 23import android.graphics.Paint; 24import android.graphics.Path; 25import android.graphics.Picture; 26import android.graphics.PorterDuff; 27import android.graphics.Rect; 28import android.graphics.RectF; 29import android.graphics.Region; 30 31import javax.microedition.khronos.opengles.GL; 32 33/** 34 * An implementation of Canvas on top of OpenGL ES 2.0. 35 */ 36@SuppressWarnings({"deprecation"}) 37class GLES20Canvas extends Canvas { 38 @SuppressWarnings({"FieldCanBeLocal", "UnusedDeclaration"}) 39 private final GL mGl; 40 private final boolean mOpaque; 41 private final int mRenderer; 42 43 private int mWidth; 44 private int mHeight; 45 46 /////////////////////////////////////////////////////////////////////////// 47 // Constructors 48 /////////////////////////////////////////////////////////////////////////// 49 50 GLES20Canvas(GL gl, boolean translucent) { 51 mGl = gl; 52 mOpaque = !translucent; 53 54 mRenderer = nCreateRenderer(); 55 } 56 57 private native int nCreateRenderer(); 58 59 @Override 60 protected void finalize() throws Throwable { 61 try { 62 super.finalize(); 63 } finally { 64 nDestroyRenderer(mRenderer); 65 } 66 } 67 68 private native void nDestroyRenderer(int renderer); 69 70 /////////////////////////////////////////////////////////////////////////// 71 // Canvas management 72 /////////////////////////////////////////////////////////////////////////// 73 74 @Override 75 public boolean isHardwareAccelerated() { 76 return true; 77 } 78 79 @Override 80 public GL getGL() { 81 throw new UnsupportedOperationException(); 82 } 83 84 @Override 85 public void setBitmap(Bitmap bitmap) { 86 throw new UnsupportedOperationException(); 87 } 88 89 @Override 90 public boolean isOpaque() { 91 return mOpaque; 92 } 93 94 @Override 95 public int getWidth() { 96 return mWidth; 97 } 98 99 @Override 100 public int getHeight() { 101 return mHeight; 102 } 103 104 /////////////////////////////////////////////////////////////////////////// 105 // Setup 106 /////////////////////////////////////////////////////////////////////////// 107 108 @Override 109 public void setViewport(int width, int height) { 110 mWidth = width; 111 mHeight = height; 112 113 nSetViewport(mRenderer, width, height); 114 } 115 116 private native void nSetViewport(int renderer, int width, int height); 117 118 void onPreDraw() { 119 nPrepare(mRenderer); 120 } 121 122 private native void nPrepare(int renderer); 123 124 /////////////////////////////////////////////////////////////////////////// 125 // Clipping 126 /////////////////////////////////////////////////////////////////////////// 127 128 @Override 129 public boolean clipPath(Path path) { 130 throw new UnsupportedOperationException(); 131 } 132 133 @Override 134 public boolean clipPath(Path path, Region.Op op) { 135 throw new UnsupportedOperationException(); 136 } 137 138 @Override 139 public boolean clipRect(float left, float top, float right, float bottom) { 140 // TODO: Implement 141 return false; 142 } 143 144 @Override 145 public boolean clipRect(float left, float top, float right, float bottom, Region.Op op) { 146 throw new UnsupportedOperationException(); 147 } 148 149 @Override 150 public boolean clipRect(int left, int top, int right, int bottom) { 151 // TODO: Implement 152 return false; 153 } 154 155 @Override 156 public boolean clipRect(Rect rect) { 157 // TODO: Implement 158 return false; 159 } 160 161 @Override 162 public boolean clipRect(Rect rect, Region.Op op) { 163 throw new UnsupportedOperationException(); 164 } 165 166 @Override 167 public boolean clipRect(RectF rect) { 168 // TODO: Implement 169 return false; 170 } 171 172 @Override 173 public boolean clipRect(RectF rect, Region.Op op) { 174 throw new UnsupportedOperationException(); 175 } 176 177 @Override 178 public boolean clipRegion(Region region) { 179 throw new UnsupportedOperationException(); 180 } 181 182 @Override 183 public boolean clipRegion(Region region, Region.Op op) { 184 throw new UnsupportedOperationException(); 185 } 186 187 @Override 188 public boolean getClipBounds(Rect bounds) { 189 // TODO: Implement 190 return false; 191 } 192 193 @Override 194 public boolean quickReject(float left, float top, float right, float bottom, EdgeType type) { 195 // TODO: Implement 196 return false; 197 } 198 199 @Override 200 public boolean quickReject(Path path, EdgeType type) { 201 // TODO: Implement 202 return false; 203 } 204 205 @Override 206 public boolean quickReject(RectF rect, EdgeType type) { 207 // TODO: Implement 208 return false; 209 } 210 211 /////////////////////////////////////////////////////////////////////////// 212 // Transformations 213 /////////////////////////////////////////////////////////////////////////// 214 215 @Override 216 public void translate(float dx, float dy) { 217 // TODO: Implement 218 } 219 220 @Override 221 public void skew(float sx, float sy) { 222 throw new UnsupportedOperationException(); 223 } 224 225 @Override 226 public void rotate(float degrees) { 227 // TODO: Implement 228 } 229 230 @Override 231 public void scale(float sx, float sy) { 232 // TODO: Implement 233 } 234 235 236 @Override 237 public void setMatrix(Matrix matrix) { 238 // TODO: Implement 239 } 240 241 @Override 242 public void getMatrix(Matrix ctm) { 243 // TODO: Implement 244 } 245 246 @Override 247 public void concat(Matrix matrix) { 248 // TODO: Implement 249 } 250 251 /////////////////////////////////////////////////////////////////////////// 252 // State management 253 /////////////////////////////////////////////////////////////////////////// 254 255 @Override 256 public int save() { 257 // TODO: Implement 258 return 0; 259 } 260 261 @Override 262 public int save(int saveFlags) { 263 // TODO: Implement 264 return 0; 265 } 266 267 @Override 268 public int saveLayer(RectF bounds, Paint paint, int saveFlags) { 269 // TODO: Implement 270 return 0; 271 } 272 273 @Override 274 public int saveLayer(float left, float top, float right, float bottom, Paint paint, 275 int saveFlags) { 276 // TODO: Implement 277 return 0; 278 } 279 280 @Override 281 public int saveLayerAlpha(RectF bounds, int alpha, int saveFlags) { 282 // TODO: Implement 283 return 0; 284 } 285 286 @Override 287 public int saveLayerAlpha(float left, float top, float right, float bottom, int alpha, 288 int saveFlags) { 289 // TODO: Implement 290 return 0; 291 } 292 293 @Override 294 public void restore() { 295 // TODO: Implement 296 } 297 298 @Override 299 public void restoreToCount(int saveCount) { 300 // TODO: Implement 301 } 302 303 @Override 304 public int getSaveCount() { 305 // TODO: Implement 306 return 0; 307 } 308 309 /////////////////////////////////////////////////////////////////////////// 310 // Filtering 311 /////////////////////////////////////////////////////////////////////////// 312 313 @Override 314 public void setDrawFilter(DrawFilter filter) { 315 throw new UnsupportedOperationException(); 316 } 317 318 @Override 319 public DrawFilter getDrawFilter() { 320 throw new UnsupportedOperationException(); 321 } 322 323 /////////////////////////////////////////////////////////////////////////// 324 // Drawing 325 /////////////////////////////////////////////////////////////////////////// 326 327 @Override 328 public void drawArc(RectF oval, float startAngle, float sweepAngle, boolean useCenter, 329 Paint paint) { 330 throw new UnsupportedOperationException(); 331 } 332 333 @Override 334 public void drawARGB(int a, int r, int g, int b) { 335 drawColor((a & 0xFF) << 24 | (r & 0xFF) << 16 | (g & 0xFF) << 8 | (b & 0xFF)); 336 } 337 338 @Override 339 public void drawBitmap(Bitmap bitmap, float left, float top, Paint paint) { 340 // TODO: Implement 341 } 342 343 @Override 344 public void drawBitmap(Bitmap bitmap, Matrix matrix, Paint paint) { 345 // TODO: Implement 346 } 347 348 @Override 349 public void drawBitmap(Bitmap bitmap, Rect src, Rect dst, Paint paint) { 350 // TODO: Implement 351 } 352 353 @Override 354 public void drawBitmap(Bitmap bitmap, Rect src, RectF dst, Paint paint) { 355 // TODO: Implement 356 } 357 358 @Override 359 public void drawBitmap(int[] colors, int offset, int stride, float x, float y, 360 int width, int height, boolean hasAlpha, Paint paint) { 361 362 // TODO: Implement 363 } 364 365 @Override 366 public void drawBitmap(int[] colors, int offset, int stride, int x, int y, 367 int width, int height, boolean hasAlpha, Paint paint) { 368 369 // TODO: Implement 370 } 371 372 @Override 373 public void drawBitmapMesh(Bitmap bitmap, int meshWidth, int meshHeight, float[] verts, 374 int vertOffset, int[] colors, int colorOffset, Paint paint) { 375 376 throw new UnsupportedOperationException(); 377 } 378 379 @Override 380 public void drawCircle(float cx, float cy, float radius, Paint paint) { 381 throw new UnsupportedOperationException(); 382 } 383 384 @Override 385 public void drawColor(int color) { 386 drawColor(color, PorterDuff.Mode.SRC_OVER); 387 } 388 389 @Override 390 public void drawColor(int color, PorterDuff.Mode mode) { 391 nDrawColor(mRenderer, color, mode.nativeInt); 392 } 393 394 private native void nDrawColor(int renderer, int color, int mode); 395 396 @Override 397 public void drawLine(float startX, float startY, float stopX, float stopY, Paint paint) { 398 // TODO: Implement 399 } 400 401 @Override 402 public void drawLines(float[] pts, int offset, int count, Paint paint) { 403 // TODO: Implement 404 } 405 406 @Override 407 public void drawLines(float[] pts, Paint paint) { 408 // TODO: Implement 409 } 410 411 @Override 412 public void drawOval(RectF oval, Paint paint) { 413 throw new UnsupportedOperationException(); 414 } 415 416 @Override 417 public void drawPaint(Paint paint) { 418 // TODO: Implement 419 } 420 421 @Override 422 public void drawPath(Path path, Paint paint) { 423 throw new UnsupportedOperationException(); 424 } 425 426 @Override 427 public void drawPicture(Picture picture) { 428 throw new UnsupportedOperationException(); 429 } 430 431 @Override 432 public void drawPicture(Picture picture, Rect dst) { 433 throw new UnsupportedOperationException(); 434 } 435 436 @Override 437 public void drawPicture(Picture picture, RectF dst) { 438 throw new UnsupportedOperationException(); 439 } 440 441 @Override 442 public void drawPoint(float x, float y, Paint paint) { 443 // TODO: Implement 444 } 445 446 @Override 447 public void drawPoints(float[] pts, int offset, int count, Paint paint) { 448 // TODO: Implement 449 } 450 451 @Override 452 public void drawPoints(float[] pts, Paint paint) { 453 // TODO: Implement 454 } 455 456 @Override 457 public void drawPosText(char[] text, int index, int count, float[] pos, Paint paint) { 458 throw new UnsupportedOperationException(); 459 } 460 461 @Override 462 public void drawPosText(String text, float[] pos, Paint paint) { 463 throw new UnsupportedOperationException(); 464 } 465 466 @Override 467 public void drawRect(float left, float top, float right, float bottom, Paint paint) { 468 // TODO: Implement 469 } 470 471 @Override 472 public void drawRect(Rect r, Paint paint) { 473 // TODO: Implement 474 } 475 476 @Override 477 public void drawRect(RectF rect, Paint paint) { 478 // TODO: Implement 479 } 480 481 @Override 482 public void drawRGB(int r, int g, int b) { 483 drawColor(0xFF000000 | (r & 0xFF) << 16 | (g & 0xFF) << 8 | (b & 0xFF)); 484 } 485 486 @Override 487 public void drawRoundRect(RectF rect, float rx, float ry, Paint paint) { 488 throw new UnsupportedOperationException(); 489 } 490 491 @Override 492 public void drawText(char[] text, int index, int count, float x, float y, Paint paint) { 493 // TODO: Implement 494 } 495 496 @Override 497 public void drawText(CharSequence text, int start, int end, float x, float y, Paint paint) { 498 // TODO: Implement 499 } 500 501 @Override 502 public void drawText(String text, int start, int end, float x, float y, Paint paint) { 503 // TODO: Implement 504 } 505 506 @Override 507 public void drawText(String text, float x, float y, Paint paint) { 508 // TODO: Implement 509 } 510 511 @Override 512 public void drawTextOnPath(char[] text, int index, int count, Path path, float hOffset, 513 float vOffset, Paint paint) { 514 515 throw new UnsupportedOperationException(); 516 } 517 518 @Override 519 public void drawTextOnPath(String text, Path path, float hOffset, float vOffset, Paint paint) { 520 throw new UnsupportedOperationException(); 521 } 522 523 @Override 524 public void drawTextRun(char[] text, int index, int count, int contextIndex, int contextCount, 525 float x, float y, int dir, Paint paint) { 526 527 throw new UnsupportedOperationException(); 528 } 529 530 @Override 531 public void drawTextRun(CharSequence text, int start, int end, int contextStart, int contextEnd, 532 float x, float y, int dir, Paint paint) { 533 534 throw new UnsupportedOperationException(); 535 } 536 537 @Override 538 public void drawVertices(VertexMode mode, int vertexCount, float[] verts, int vertOffset, 539 float[] texs, int texOffset, int[] colors, int colorOffset, short[] indices, 540 int indexOffset, int indexCount, Paint paint) { 541 542 throw new UnsupportedOperationException(); 543 } 544} 545