GLES20Canvas.java revision 9d5316e3f56d138504565ff311145ac01621dff4
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 return nClipRect(mRenderer, left, top, right, bottom); 141 } 142 143 private native boolean nClipRect(int renderer, float left, float top, float right, float bottom); 144 145 @Override 146 public boolean clipRect(float left, float top, float right, float bottom, Region.Op op) { 147 throw new UnsupportedOperationException(); 148 } 149 150 @Override 151 public boolean clipRect(int left, int top, int right, int bottom) { 152 return nClipRect(mRenderer, left, top, right, bottom); 153 } 154 155 private native boolean nClipRect(int renderer, int left, int top, int right, int bottom); 156 157 @Override 158 public boolean clipRect(Rect rect) { 159 return clipRect(rect.left, rect.top, rect.right, rect.bottom); 160 } 161 162 @Override 163 public boolean clipRect(Rect rect, Region.Op op) { 164 throw new UnsupportedOperationException(); 165 } 166 167 @Override 168 public boolean clipRect(RectF rect) { 169 return clipRect(rect.left, rect.top, rect.right, rect.bottom); 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 return nGetClipBounds(mRenderer, bounds); 190 } 191 192 private native boolean nGetClipBounds(int renderer, Rect bounds); 193 194 @Override 195 public boolean quickReject(float left, float top, float right, float bottom, EdgeType type) { 196 // TODO: Implement 197 return false; 198 } 199 200 @Override 201 public boolean quickReject(Path path, EdgeType type) { 202 throw new UnsupportedOperationException(); 203 } 204 205 @Override 206 public boolean quickReject(RectF rect, EdgeType type) { 207 return quickReject(rect.left, rect.top, rect.right, rect.bottom, type); 208 } 209 210 /////////////////////////////////////////////////////////////////////////// 211 // Transformations 212 /////////////////////////////////////////////////////////////////////////// 213 214 @Override 215 public void translate(float dx, float dy) { 216 nTranslate(mRenderer, dx, dy); 217 } 218 219 private native void nTranslate(int renderer, float dx, float dy); 220 221 @Override 222 public void skew(float sx, float sy) { 223 throw new UnsupportedOperationException(); 224 } 225 226 @Override 227 public void rotate(float degrees) { 228 nRotate(mRenderer, degrees); 229 } 230 231 private native void nRotate(int renderer, float degrees); 232 233 @Override 234 public void scale(float sx, float sy) { 235 nScale(mRenderer, sx, sy); 236 } 237 238 private native void nScale(int renderer, float sx, float sy); 239 240 @Override 241 public void setMatrix(Matrix matrix) { 242 nSetMatrix(mRenderer, matrix.native_instance); 243 } 244 245 private native void nSetMatrix(int renderer, int matrix); 246 247 @Override 248 public void getMatrix(Matrix matrix) { 249 nGetMatrix(mRenderer, matrix.native_instance); 250 } 251 252 private native void nGetMatrix(int renderer, int matrix); 253 254 @Override 255 public void concat(Matrix matrix) { 256 nConcatMatrix(mRenderer, matrix.native_instance); 257 } 258 259 private native void nConcatMatrix(int renderer, int matrix); 260 261 /////////////////////////////////////////////////////////////////////////// 262 // State management 263 /////////////////////////////////////////////////////////////////////////// 264 265 @Override 266 public int save() { 267 return nSave(mRenderer, 0); 268 } 269 270 @Override 271 public int save(int saveFlags) { 272 return nSave(mRenderer, saveFlags); 273 } 274 275 private native int nSave(int renderer, int flags); 276 277 @Override 278 public int saveLayer(RectF bounds, Paint paint, int saveFlags) { 279 // TODO: Implement 280 return 0; 281 } 282 283 @Override 284 public int saveLayer(float left, float top, float right, float bottom, Paint paint, 285 int saveFlags) { 286 // TODO: Implement 287 return 0; 288 } 289 290 @Override 291 public int saveLayerAlpha(RectF bounds, int alpha, int saveFlags) { 292 // TODO: Implement 293 return 0; 294 } 295 296 @Override 297 public int saveLayerAlpha(float left, float top, float right, float bottom, int alpha, 298 int saveFlags) { 299 // TODO: Implement 300 return 0; 301 } 302 303 @Override 304 public void restore() { 305 nRestore(mRenderer); 306 } 307 308 private native void nRestore(int renderer); 309 310 @Override 311 public void restoreToCount(int saveCount) { 312 nRestoreToCount(mRenderer, saveCount); 313 } 314 315 private native void nRestoreToCount(int renderer, int saveCount); 316 317 @Override 318 public int getSaveCount() { 319 return nGetSaveCount(mRenderer); 320 } 321 322 private native int nGetSaveCount(int renderer); 323 324 /////////////////////////////////////////////////////////////////////////// 325 // Filtering 326 /////////////////////////////////////////////////////////////////////////// 327 328 @Override 329 public void setDrawFilter(DrawFilter filter) { 330 throw new UnsupportedOperationException(); 331 } 332 333 @Override 334 public DrawFilter getDrawFilter() { 335 throw new UnsupportedOperationException(); 336 } 337 338 /////////////////////////////////////////////////////////////////////////// 339 // Drawing 340 /////////////////////////////////////////////////////////////////////////// 341 342 @Override 343 public void drawArc(RectF oval, float startAngle, float sweepAngle, boolean useCenter, 344 Paint paint) { 345 throw new UnsupportedOperationException(); 346 } 347 348 @Override 349 public void drawARGB(int a, int r, int g, int b) { 350 drawColor((a & 0xFF) << 24 | (r & 0xFF) << 16 | (g & 0xFF) << 8 | (b & 0xFF)); 351 } 352 353 @Override 354 public void drawBitmap(Bitmap bitmap, float left, float top, Paint paint) { 355 // TODO: Implement 356 } 357 358 @Override 359 public void drawBitmap(Bitmap bitmap, Matrix matrix, Paint paint) { 360 // TODO: Implement 361 } 362 363 @Override 364 public void drawBitmap(Bitmap bitmap, Rect src, Rect dst, Paint paint) { 365 // TODO: Implement 366 } 367 368 @Override 369 public void drawBitmap(Bitmap bitmap, Rect src, RectF dst, Paint paint) { 370 // TODO: Implement 371 } 372 373 @Override 374 public void drawBitmap(int[] colors, int offset, int stride, float x, float y, 375 int width, int height, boolean hasAlpha, Paint paint) { 376 377 // TODO: Implement 378 } 379 380 @Override 381 public void drawBitmap(int[] colors, int offset, int stride, int x, int y, 382 int width, int height, boolean hasAlpha, Paint paint) { 383 384 // TODO: Implement 385 } 386 387 @Override 388 public void drawBitmapMesh(Bitmap bitmap, int meshWidth, int meshHeight, float[] verts, 389 int vertOffset, int[] colors, int colorOffset, Paint paint) { 390 391 throw new UnsupportedOperationException(); 392 } 393 394 @Override 395 public void drawCircle(float cx, float cy, float radius, Paint paint) { 396 throw new UnsupportedOperationException(); 397 } 398 399 @Override 400 public void drawColor(int color) { 401 drawColor(color, PorterDuff.Mode.SRC_OVER); 402 } 403 404 @Override 405 public void drawColor(int color, PorterDuff.Mode mode) { 406 nDrawColor(mRenderer, color, mode.nativeInt); 407 } 408 409 private native void nDrawColor(int renderer, int color, int mode); 410 411 @Override 412 public void drawLine(float startX, float startY, float stopX, float stopY, Paint paint) { 413 // TODO: Implement 414 } 415 416 @Override 417 public void drawLines(float[] pts, int offset, int count, Paint paint) { 418 // TODO: Implement 419 } 420 421 @Override 422 public void drawLines(float[] pts, Paint paint) { 423 // TODO: Implement 424 } 425 426 @Override 427 public void drawOval(RectF oval, Paint paint) { 428 throw new UnsupportedOperationException(); 429 } 430 431 @Override 432 public void drawPaint(Paint paint) { 433 // TODO: Implement 434 } 435 436 @Override 437 public void drawPath(Path path, Paint paint) { 438 throw new UnsupportedOperationException(); 439 } 440 441 @Override 442 public void drawPicture(Picture picture) { 443 throw new UnsupportedOperationException(); 444 } 445 446 @Override 447 public void drawPicture(Picture picture, Rect dst) { 448 throw new UnsupportedOperationException(); 449 } 450 451 @Override 452 public void drawPicture(Picture picture, RectF dst) { 453 throw new UnsupportedOperationException(); 454 } 455 456 @Override 457 public void drawPoint(float x, float y, Paint paint) { 458 // TODO: Implement 459 } 460 461 @Override 462 public void drawPoints(float[] pts, int offset, int count, Paint paint) { 463 // TODO: Implement 464 } 465 466 @Override 467 public void drawPoints(float[] pts, Paint paint) { 468 // TODO: Implement 469 } 470 471 @Override 472 public void drawPosText(char[] text, int index, int count, float[] pos, Paint paint) { 473 throw new UnsupportedOperationException(); 474 } 475 476 @Override 477 public void drawPosText(String text, float[] pos, Paint paint) { 478 throw new UnsupportedOperationException(); 479 } 480 481 @Override 482 public void drawRect(float left, float top, float right, float bottom, Paint paint) { 483 // TODO: Implement 484 } 485 486 @Override 487 public void drawRect(Rect r, Paint paint) { 488 // TODO: Implement 489 } 490 491 @Override 492 public void drawRect(RectF rect, Paint paint) { 493 // TODO: Implement 494 } 495 496 @Override 497 public void drawRGB(int r, int g, int b) { 498 drawColor(0xFF000000 | (r & 0xFF) << 16 | (g & 0xFF) << 8 | (b & 0xFF)); 499 } 500 501 @Override 502 public void drawRoundRect(RectF rect, float rx, float ry, Paint paint) { 503 throw new UnsupportedOperationException(); 504 } 505 506 @Override 507 public void drawText(char[] text, int index, int count, float x, float y, Paint paint) { 508 // TODO: Implement 509 } 510 511 @Override 512 public void drawText(CharSequence text, int start, int end, float x, float y, Paint paint) { 513 // TODO: Implement 514 } 515 516 @Override 517 public void drawText(String text, int start, int end, float x, float y, Paint paint) { 518 // TODO: Implement 519 } 520 521 @Override 522 public void drawText(String text, float x, float y, Paint paint) { 523 // TODO: Implement 524 } 525 526 @Override 527 public void drawTextOnPath(char[] text, int index, int count, Path path, float hOffset, 528 float vOffset, Paint paint) { 529 530 throw new UnsupportedOperationException(); 531 } 532 533 @Override 534 public void drawTextOnPath(String text, Path path, float hOffset, float vOffset, Paint paint) { 535 throw new UnsupportedOperationException(); 536 } 537 538 @Override 539 public void drawTextRun(char[] text, int index, int count, int contextIndex, int contextCount, 540 float x, float y, int dir, Paint paint) { 541 542 throw new UnsupportedOperationException(); 543 } 544 545 @Override 546 public void drawTextRun(CharSequence text, int start, int end, int contextStart, int contextEnd, 547 float x, float y, int dir, Paint paint) { 548 549 throw new UnsupportedOperationException(); 550 } 551 552 @Override 553 public void drawVertices(VertexMode mode, int vertexCount, float[] verts, int vertOffset, 554 float[] texs, int texOffset, int[] colors, int colorOffset, short[] indices, 555 int indexOffset, int indexCount, Paint paint) { 556 557 throw new UnsupportedOperationException(); 558 } 559} 560