Fresco Arch

#Fresco

##Outline

  1. Architecture
  2. Usage
  3. Drawee
  4. ImagePipeline

##Architecture

##Memory

####Regions of Memory

  1. Java Heap: limited, GC
  2. Native Heap: as large as the memory size; Program is responsible for freeing memory
  3. Ashmen: (Anonymous Shared Memory) like native heap; pin or unpin, lazy free purging facility.

####Purgeable bitmaps

1
2
3
BitmapFactory.Options = new BitmapFactory.Options();
options.inPurgeable = true;
Bitmap bitmap = BitmapFactory.decodeByteArray(jepeg, 0, jpeg.length, options);

####Fast UI and fast memory
NDK: AndroidBitmap_lockPixels, and unlockPixels match.
Solution: call lockPixels without a matching unlockPixels

####Write code in Java, think in C++

In C++, smart pointer implement reference counting.

In Java:

  1. SharedReference:

    • addReference(): increase reference count
    • deleteReference():decrease reference count
    • when reference count goes to 0, resource disposal(such as Bitmap.recycle)
  2. CloseableReference:

    • implemented interfaces :Closeable, Cloneable
    • constructor and clone() method call addReference()
    • close() method calls deleteReference()

Java developers need only follow two simple rules:

  1. On assigning a CloseableReference to a new object, call .clone().
  2. Before going out of scope, call .close(), usually in a finally block.

####Pipeline

DataSource

Produce series of continuous results. Future can get only one result.

DataSource:

  1. DataSubscriber
  2. Executor

Producer/Consumer framework:

  1. Producer : produceResults()
  2. Consumer : onNewResult(), onFailure(), onCancellation(), onProgressUpdate()

##Drawee
MVC-like

  1. DraweeHierarchy: Model
  2. DraweeController: connect to the image pipeline or any image loader.
  3. DraweeView: