Recently, I am working on an e-book project to bring together the open-source shelves + ireader page flip and curl. I encountered the following problems when doing the curl effect:
Java. Lang. Unsupported operation exception, Android. View. gles20canvas. clippath (gles20canvas...
The omnipotent Gu Ge told me that this is a hardware acceleration problem, but I have never enabled hardware acceleration. I did a test and the hardware acceleration at the view layer has been eliminated.
The hardware acceleration must have come from the canvas painting layer. After testing, the drawing layer has enabled hardware acceleration.
Give a link to the article about hardware acceleration:Click to view
After reading this information, we solved the problem by setting it in androidmanifest. XML application:
<application android:label="@string/application_name" android:hardwareAccelerated="false">
Certificate ---------------------------------------------------------------------------------------------------------------------------------------------
AboutHardware acceleration
1. Acceleration at different levels:
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. How to determine whether hardware acceleration is enabled
You must perform this test before drawing.Canvas.isHardwareAccelerated()
SubstitutionView.isHardwareAccelerated()
If necessary.
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. After hardware acceleration is enabled, many 2D rendering Methods throw an exception:
- Canvas
clipPath()
clipRegion()
drawPicture()
drawTextOnPath()
drawVertices()
- Paint
setLinearText()
setMaskFilter()
setRasterizer()
- Xfermodes
AvoidXfermode
PixelXorXfermode
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 rectangle
drawBitmapMesh()
: Colors array is ignored
- Paint
setDither()
: Ignored
setFilterBitmap()
: Filtering is always on
setShadowLayer()
: Works with text only
- Porterduduxfermode
PorterDuff.Mode.DARKEN
Will be equivalentSRC_OVER
When blending against the framebuffer.
PorterDuff.Mode.LIGHTEN
Will be equivalentSRC_OVER
When blending against the framebuffer.
PorterDuff.Mode.OVERLAY
Will be equivalentSRC_OVER
When blending against the framebuffer.
- Composeshader
ComposeShader
Can only contain shaders of different types (BitmapShader
AndLinearGradient
For instance, but not two instancesBitmapShader
)
ComposeShader
Cannot containComposeShader