Completely solve the java. Lang. Unsupported operation exception caused by canvas, Android. View. gles20canvas. clippath (gles20

Source: Internet
Author: User
Tags unsupported

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,DifferenceAndReverseDifferenceClip 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.DARKENWill be equivalentSRC_OVERWhen blending against the framebuffer.
    • PorterDuff.Mode.LIGHTENWill be equivalentSRC_OVERWhen blending against the framebuffer.
    • PorterDuff.Mode.OVERLAYWill be equivalentSRC_OVERWhen blending against the framebuffer.
  • Composeshader
    • ComposeShaderCan only contain shaders of different types (BitmapShaderAndLinearGradientFor instance, but not two instancesBitmapShader)
    • ComposeShaderCannot containComposeShader
 

 

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.