diff options
author | Romain Guy <romainguy@google.com> | 2010-06-17 13:42:37 -0700 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2010-06-17 13:42:37 -0700 |
commit | 3b970e78d2974eacc621258bb6e581d458d9bbd3 (patch) | |
tree | 94d54ea85fa68146875b567c04740f3844b3e8e1 /core/java/android/view | |
parent | 4e74ae3d5b27d917ea26d0929015f9fdc64af412 (diff) | |
parent | e4d011201cea40d46cb2b2eef401db8fddc5c9c6 (diff) | |
download | frameworks_base-3b970e78d2974eacc621258bb6e581d458d9bbd3.zip frameworks_base-3b970e78d2974eacc621258bb6e581d458d9bbd3.tar.gz frameworks_base-3b970e78d2974eacc621258bb6e581d458d9bbd3.tar.bz2 |
Merge "Add libhwui, to hardware accelerate the Canvas API using OpenGL ES 2.0."
Diffstat (limited to 'core/java/android/view')
-rw-r--r-- | core/java/android/view/GLES20Canvas.java | 542 | ||||
-rw-r--r-- | core/java/android/view/HardwareRenderer.java | 32 | ||||
-rw-r--r-- | core/java/android/view/ViewRoot.java | 31 |
3 files changed, 581 insertions, 24 deletions
diff --git a/core/java/android/view/GLES20Canvas.java b/core/java/android/view/GLES20Canvas.java new file mode 100644 index 0000000..56c2aac --- /dev/null +++ b/core/java/android/view/GLES20Canvas.java @@ -0,0 +1,542 @@ +/* + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package android.view; + +import android.graphics.Bitmap; +import android.graphics.Canvas; +import android.graphics.DrawFilter; +import android.graphics.Matrix; +import android.graphics.Paint; +import android.graphics.Path; +import android.graphics.Picture; +import android.graphics.PorterDuff; +import android.graphics.Rect; +import android.graphics.RectF; +import android.graphics.Region; + +import javax.microedition.khronos.opengles.GL; + +/** + * An implementation of Canvas on top of OpenGL ES 2.0. + */ +@SuppressWarnings({"deprecation"}) +class GLES20Canvas extends Canvas { + @SuppressWarnings({"FieldCanBeLocal", "UnusedDeclaration"}) + private final GL mGl; + private final boolean mOpaque; + private final int mRenderer; + + private int mWidth; + private int mHeight; + + /////////////////////////////////////////////////////////////////////////// + // Constructors + /////////////////////////////////////////////////////////////////////////// + + GLES20Canvas(GL gl, boolean translucent) { + mGl = gl; + mOpaque = !translucent; + + mRenderer = nCreateRenderer(); + } + + private native int nCreateRenderer(); + + @Override + protected void finalize() throws Throwable { + try { + super.finalize(); + } finally { + nDestroyRenderer(mRenderer); + } + } + + private native void nDestroyRenderer(int renderer); + + /////////////////////////////////////////////////////////////////////////// + // Canvas management + /////////////////////////////////////////////////////////////////////////// + + @Override + public boolean isHardwareAccelerated() { + return true; + } + + @Override + public GL getGL() { + throw new UnsupportedOperationException(); + } + + @Override + public void setBitmap(Bitmap bitmap) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean isOpaque() { + return mOpaque; + } + + @Override + public int getWidth() { + return mWidth; + } + + @Override + public int getHeight() { + return mHeight; + } + + /////////////////////////////////////////////////////////////////////////// + // Setup + /////////////////////////////////////////////////////////////////////////// + + @Override + public void setViewport(int width, int height) { + mWidth = width; + mHeight = height; + + nSetViewport(mRenderer, width, height); + } + + private native void nSetViewport(int renderer, int width, int height); + + void onPreDraw() { + nPrepare(mRenderer); + } + + private native void nPrepare(int renderer); + + /////////////////////////////////////////////////////////////////////////// + // Clipping + /////////////////////////////////////////////////////////////////////////// + + @Override + public boolean clipPath(Path path) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean clipPath(Path path, Region.Op op) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean clipRect(float left, float top, float right, float bottom) { + // TODO: Implement + return false; + } + + @Override + public boolean clipRect(float left, float top, float right, float bottom, Region.Op op) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean clipRect(int left, int top, int right, int bottom) { + // TODO: Implement + return false; + } + + @Override + public boolean clipRect(Rect rect) { + // TODO: Implement + return false; + } + + @Override + public boolean clipRect(Rect rect, Region.Op op) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean clipRect(RectF rect) { + // TODO: Implement + return false; + } + + @Override + public boolean clipRect(RectF rect, Region.Op op) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean clipRegion(Region region) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean clipRegion(Region region, Region.Op op) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean getClipBounds(Rect bounds) { + // TODO: Implement + return false; + } + + @Override + public boolean quickReject(float left, float top, float right, float bottom, EdgeType type) { + // TODO: Implement + return false; + } + + @Override + public boolean quickReject(Path path, EdgeType type) { + // TODO: Implement + return false; + } + + @Override + public boolean quickReject(RectF rect, EdgeType type) { + // TODO: Implement + return false; + } + + /////////////////////////////////////////////////////////////////////////// + // Transformations + /////////////////////////////////////////////////////////////////////////// + + @Override + public void translate(float dx, float dy) { + // TODO: Implement + } + + @Override + public void skew(float sx, float sy) { + throw new UnsupportedOperationException(); + } + + @Override + public void rotate(float degrees) { + // TODO: Implement + } + + @Override + public void scale(float sx, float sy) { + // TODO: Implement + } + + + @Override + public void setMatrix(Matrix matrix) { + // TODO: Implement + } + + @Override + public void getMatrix(Matrix ctm) { + // TODO: Implement + } + + @Override + public void concat(Matrix matrix) { + // TODO: Implement + } + + /////////////////////////////////////////////////////////////////////////// + // State management + /////////////////////////////////////////////////////////////////////////// + + @Override + public int save() { + // TODO: Implement + return 0; + } + + @Override + public int save(int saveFlags) { + // TODO: Implement + return 0; + } + + @Override + public int saveLayer(RectF bounds, Paint paint, int saveFlags) { + // TODO: Implement + return 0; + } + + @Override + public int saveLayer(float left, float top, float right, float bottom, Paint paint, + int saveFlags) { + // TODO: Implement + return 0; + } + + @Override + public int saveLayerAlpha(RectF bounds, int alpha, int saveFlags) { + // TODO: Implement + return 0; + } + + @Override + public int saveLayerAlpha(float left, float top, float right, float bottom, int alpha, + int saveFlags) { + // TODO: Implement + return 0; + } + + @Override + public void restore() { + // TODO: Implement + } + + @Override + public void restoreToCount(int saveCount) { + // TODO: Implement + } + + @Override + public int getSaveCount() { + // TODO: Implement + return 0; + } + + /////////////////////////////////////////////////////////////////////////// + // Filtering + /////////////////////////////////////////////////////////////////////////// + + @Override + public void setDrawFilter(DrawFilter filter) { + throw new UnsupportedOperationException(); + } + + @Override + public DrawFilter getDrawFilter() { + throw new UnsupportedOperationException(); + } + + /////////////////////////////////////////////////////////////////////////// + // Drawing + /////////////////////////////////////////////////////////////////////////// + + @Override + public void drawArc(RectF oval, float startAngle, float sweepAngle, boolean useCenter, + Paint paint) { + throw new UnsupportedOperationException(); + } + + @Override + public void drawARGB(int a, int r, int g, int b) { + // TODO: Implement + } + + @Override + public void drawBitmap(Bitmap bitmap, float left, float top, Paint paint) { + // TODO: Implement + } + + @Override + public void drawBitmap(Bitmap bitmap, Matrix matrix, Paint paint) { + // TODO: Implement + } + + @Override + public void drawBitmap(Bitmap bitmap, Rect src, Rect dst, Paint paint) { + // TODO: Implement + } + + @Override + public void drawBitmap(Bitmap bitmap, Rect src, RectF dst, Paint paint) { + // TODO: Implement + } + + @Override + public void drawBitmap(int[] colors, int offset, int stride, float x, float y, + int width, int height, boolean hasAlpha, Paint paint) { + + // TODO: Implement + } + + @Override + public void drawBitmap(int[] colors, int offset, int stride, int x, int y, + int width, int height, boolean hasAlpha, Paint paint) { + + // TODO: Implement + } + + @Override + public void drawBitmapMesh(Bitmap bitmap, int meshWidth, int meshHeight, float[] verts, + int vertOffset, int[] colors, int colorOffset, Paint paint) { + + throw new UnsupportedOperationException(); + } + + @Override + public void drawCircle(float cx, float cy, float radius, Paint paint) { + throw new UnsupportedOperationException(); + } + + @Override + public void drawColor(int color) { + // TODO: Implement + } + + @Override + public void drawColor(int color, PorterDuff.Mode mode) { + // TODO: Implement + } + + @Override + public void drawLine(float startX, float startY, float stopX, float stopY, Paint paint) { + // TODO: Implement + } + + @Override + public void drawLines(float[] pts, int offset, int count, Paint paint) { + // TODO: Implement + } + + @Override + public void drawLines(float[] pts, Paint paint) { + // TODO: Implement + } + + @Override + public void drawOval(RectF oval, Paint paint) { + throw new UnsupportedOperationException(); + } + + @Override + public void drawPaint(Paint paint) { + // TODO: Implement + } + + @Override + public void drawPath(Path path, Paint paint) { + throw new UnsupportedOperationException(); + } + + @Override + public void drawPicture(Picture picture) { + throw new UnsupportedOperationException(); + } + + @Override + public void drawPicture(Picture picture, Rect dst) { + throw new UnsupportedOperationException(); + } + + @Override + public void drawPicture(Picture picture, RectF dst) { + throw new UnsupportedOperationException(); + } + + @Override + public void drawPoint(float x, float y, Paint paint) { + // TODO: Implement + } + + @Override + public void drawPoints(float[] pts, int offset, int count, Paint paint) { + // TODO: Implement + } + + @Override + public void drawPoints(float[] pts, Paint paint) { + // TODO: Implement + } + + @Override + public void drawPosText(char[] text, int index, int count, float[] pos, Paint paint) { + throw new UnsupportedOperationException(); + } + + @Override + public void drawPosText(String text, float[] pos, Paint paint) { + throw new UnsupportedOperationException(); + } + + @Override + public void drawRect(float left, float top, float right, float bottom, Paint paint) { + // TODO: Implement + } + + @Override + public void drawRect(Rect r, Paint paint) { + // TODO: Implement + } + + @Override + public void drawRect(RectF rect, Paint paint) { + // TODO: Implement + } + + @Override + public void drawRGB(int r, int g, int b) { + // TODO: Implement + } + + @Override + public void drawRoundRect(RectF rect, float rx, float ry, Paint paint) { + throw new UnsupportedOperationException(); + } + + @Override + public void drawText(char[] text, int index, int count, float x, float y, Paint paint) { + // TODO: Implement + } + + @Override + public void drawText(CharSequence text, int start, int end, float x, float y, Paint paint) { + // TODO: Implement + } + + @Override + public void drawText(String text, int start, int end, float x, float y, Paint paint) { + // TODO: Implement + } + + @Override + public void drawText(String text, float x, float y, Paint paint) { + // TODO: Implement + } + + @Override + public void drawTextOnPath(char[] text, int index, int count, Path path, float hOffset, + float vOffset, Paint paint) { + + throw new UnsupportedOperationException(); + } + + @Override + public void drawTextOnPath(String text, Path path, float hOffset, float vOffset, Paint paint) { + throw new UnsupportedOperationException(); + } + + @Override + public void drawTextRun(char[] text, int index, int count, int contextIndex, int contextCount, + float x, float y, int dir, Paint paint) { + + throw new UnsupportedOperationException(); + } + + @Override + public void drawTextRun(CharSequence text, int start, int end, int contextStart, int contextEnd, + float x, float y, int dir, Paint paint) { + + throw new UnsupportedOperationException(); + } + + @Override + public void drawVertices(VertexMode mode, int vertexCount, float[] verts, int vertOffset, + float[] texs, int texOffset, int[] colors, int colorOffset, short[] indices, + int indexOffset, int indexCount, Paint paint) { + + throw new UnsupportedOperationException(); + } +} diff --git a/core/java/android/view/HardwareRenderer.java b/core/java/android/view/HardwareRenderer.java index bff4ecc..c7fe31b 100644 --- a/core/java/android/view/HardwareRenderer.java +++ b/core/java/android/view/HardwareRenderer.java @@ -110,15 +110,16 @@ abstract class HardwareRenderer { * Creates a hardware renderer using OpenGL. * * @param glVersion The version of OpenGL to use (1 for OpenGL 1, 11 for OpenGL 1.1, etc.) + * @param translucent True if the surface is translucent, false otherwise * * @return A hardware renderer backed by OpenGL. */ - static HardwareRenderer createGlRenderer(int glVersion) { + static HardwareRenderer createGlRenderer(int glVersion, boolean translucent) { switch (glVersion) { case 1: - return new Gl10Renderer(); + return new Gl10Renderer(translucent); case 2: - return new Gl20Renderer(); + return new Gl20Renderer(translucent); } throw new IllegalArgumentException("Unknown GL version: " + glVersion); } @@ -174,10 +175,12 @@ abstract class HardwareRenderer { GL mGl; Canvas mCanvas; - int mGlVersion; + final int mGlVersion; + final boolean mTranslucent; - GlRenderer(int glVersion) { + GlRenderer(int glVersion, boolean translucent) { mGlVersion = glVersion; + mTranslucent = translucent; } /** @@ -362,7 +365,7 @@ abstract class HardwareRenderer { * @param glVersion */ EglConfigChooser getConfigChooser(int glVersion) { - return new ComponentSizeChooser(glVersion, 8, 8, 8, 0, 0, 0); + return new ComponentSizeChooser(glVersion, 8, 8, 8, mTranslucent ? 8 : 0, 0, 0); } @Override @@ -520,13 +523,20 @@ abstract class HardwareRenderer { * Hardware renderer using OpenGL ES 2.0. */ static class Gl20Renderer extends GlRenderer { - Gl20Renderer() { - super(2); + private GLES20Canvas mGlCanvas; + + Gl20Renderer(boolean translucent) { + super(2, translucent); } @Override Canvas createCanvas() { - return null; + return mGlCanvas = new GLES20Canvas(mGl, mTranslucent); + } + + @Override + void onPreDraw() { + mGlCanvas.onPreDraw(); } } @@ -535,8 +545,8 @@ abstract class HardwareRenderer { */ @SuppressWarnings({"deprecation"}) static class Gl10Renderer extends GlRenderer { - Gl10Renderer() { - super(1); + Gl10Renderer(boolean translucent) { + super(1, translucent); } @Override diff --git a/core/java/android/view/ViewRoot.java b/core/java/android/view/ViewRoot.java index fc28e69..0c12998 100644 --- a/core/java/android/view/ViewRoot.java +++ b/core/java/android/view/ViewRoot.java @@ -259,17 +259,6 @@ public final class ViewRoot extends Handler implements ViewParent, View.AttachIn mAttachInfo = new View.AttachInfo(sWindowSession, mWindow, this, this); mViewConfiguration = ViewConfiguration.get(context); mDensity = context.getResources().getDisplayMetrics().densityDpi; - - // Only enable hardware acceleration if we are not in the system process - // The window manager creates ViewRoots to display animated preview windows - // of launching apps and we don't want those to be hardware accelerated - if (Process.myUid() != Process.SYSTEM_UID) { - // Try to enable hardware acceleration if requested - if ((context.getApplicationInfo().flags & - ApplicationInfo.FLAG_HARDWARE_ACCELERATED) != 0) { - mHwRenderer = HardwareRenderer.createGlRenderer(1); - } - } } // For debug only @@ -331,13 +320,15 @@ public final class ViewRoot extends Handler implements ViewParent, View.AttachIn /** * We have one child */ - public void setView(View view, WindowManager.LayoutParams attrs, - View panelParentView) { + public void setView(View view, WindowManager.LayoutParams attrs, View panelParentView) { synchronized (this) { if (mView == null) { mView = view; mWindowAttributes.copyFrom(attrs); attrs = mWindowAttributes; + + enableHardwareAcceleration(view, attrs); + if (view instanceof RootViewSurfaceTaker) { mSurfaceHolderCallback = ((RootViewSurfaceTaker)view).willYouTakeTheSurface(); @@ -459,6 +450,20 @@ public final class ViewRoot extends Handler implements ViewParent, View.AttachIn } } + private void enableHardwareAcceleration(View view, WindowManager.LayoutParams attrs) { + // Only enable hardware acceleration if we are not in the system process + // The window manager creates ViewRoots to display animated preview windows + // of launching apps and we don't want those to be hardware accelerated + if (Process.myUid() != Process.SYSTEM_UID) { + // Try to enable hardware acceleration if requested + if ((view.getContext().getApplicationInfo().flags & + ApplicationInfo.FLAG_HARDWARE_ACCELERATED) != 0) { + final boolean translucent = attrs.format != PixelFormat.OPAQUE; + mHwRenderer = HardwareRenderer.createGlRenderer(2, translucent); + } + } + } + public View getView() { return mView; } |