Skip to content

Support progressive animated webp#2353

Open
chenleejr wants to merge 2 commits into
facebook:mainfrom
chenleejr:master
Open

Support progressive animated webp#2353
chenleejr wants to merge 2 commits into
facebook:mainfrom
chenleejr:master

Conversation

@chenleejr

Copy link
Copy Markdown

Motivation

To support progressive animated webp, so that Fresco can play animation while download the image.

  • change WebPDemux to WebPDemuxPartial in webp.cpp
  • modify the DecodeProducer to decode intermediate webp data
  • Although multiple ClosableImage will be generated during the download, I still only use one AnimatedDrawable2. So I modified AnimatedDrawable2 to support playing from the last frame played by the previous data, and added createDrawable(Drawable previousDrawable, CloseableImage image) to DrawableFactory to update Drawable instead of creating a new Drawable
  • add a ControllerListener to AbstractDraweeController to start animation every time data arrives

Test Plan

We can use ImageRequestBuilder.setProgressiveRenderingEnabled to enable the progressive animated webp. I add a switch to ImageFormatWebpFragment in SHOWCASE module so that we can test the function.

    switchProgressive.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
      @Override
      public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
        ImageRequest request = ImageRequestBuilder.newBuilderWithSource(sampleUris().createWebpAnimatedUri())
          .setProgressiveRenderingEnabled(isChecked).build();
        draweeWebpAnimated.setController(
          Fresco.newDraweeControllerBuilder()
            .setAutoPlayAnimations(true)
            .setOldController(draweeWebpAnimated.getController())
            .setImageRequest(request)
            .build());
      }
    });

First, we construct a weak network environment, by modifying the proxy configuration or modifying the code of NetworkFetchProducer, and then turning on the switch, we can see that some frames can be played before the image is completely downloaded.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

2 participants