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