最近在做一個電子書項目,想要把開源的Shelves+iReader的翻頁卷曲等弄到一起,在做卷曲效果時遇到以下問題:
java.lang.unsupported operation exception, android.view.GLES20Canvas.clipPath(GLES20Canvas...
萬能的谷哥告訴我,這是硬件加速的問題,可是我從來沒開啟過硬件加速啊,做了個測試,View層的硬件加速已經干掉了
,那硬件加速肯定來自於Canvas繪制層了,測試了下,果然是繪制層開啟了硬件加速。
給一個鏈接,講硬件加速講的很清楚的文章:點擊查看
綜合看了之后解決了,即在AndroidManifest.xml application下設定:
<application android:label="@string/application_name" android:hardwareAccelerated="false">
---------------------------------------------------------------------------------------------------------------------------------------------
關於 Hardware Acceleration
1、不同層級的加速:
Application
<applicationandroid:hardwareAccelerated="true" ...>
Activity
<application android:hardwareAccelerated="true"> <activity ... /> <activity android:hardwareAccelerated="false" /> </application>
Window
getWindow().setFlags(
WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED,
WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED);
View
myView.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
2、如何判斷是否開啟了硬件加速
在繪制之前,你必須做該測試 Canvas.isHardwareAccelerated()
替代View.isHardwareAccelerated()
在必要時。
View.isHardwareAccelerated() ;//returns true if the View is attached to a hardware accelerated window. Canvas.isHardwareAccelerated();// returns true if the Canvas is hardware accelerated
3、開啟硬件加速之后,許多2D的繪制方法會拋出異常:
- Canvas
- Paint
- Xfermodes
In addition, some operations behave differently with hardware acceleration enabled:
- Canvas
clipRect()
:XOR
,Difference
andReverseDifference
clip modes are ignored. 3D transforms do not apply to the clip rectangledrawBitmapMesh()
: colors array is ignored
- Paint
setDither()
: ignoredsetFilterBitmap()
: filtering is always onsetShadowLayer()
: works with text only
- PorterDuffXfermode
PorterDuff.Mode.DARKEN
will be equivalent toSRC_OVER
when blending against the framebuffer.PorterDuff.Mode.LIGHTEN
will be equivalent toSRC_OVER
when blending against the framebuffer.PorterDuff.Mode.OVERLAY
will be equivalent toSRC_OVER
when blending against the framebuffer.
- ComposeShader
ComposeShader
can only contain shaders of different types (aBitmapShader
and aLinearGradient
for instance, but not two instances ofBitmapShader
)ComposeShader
cannot contain aComposeShader