hwc: Fix the copybit threshold comparison

Change-Id: Ife9d54d4592e2427e8de6e67b4c8f62b676b2679
libcopybit: protect all c2d copybit API's

- Each client API exposed by the copybit C2D needs
  to be protected.
- Add protection for clear_copybit and blit_copybit
- This is needed as clear_copybit was overriding the
  mapped gpuaddr while copybitwaitthread was waiting
  for transaction to finish and unmap
- After waitforTimestamp, the new addresses were
  unmapped leading to GPU Page fault

Change-Id: Ieeac10e73b05d3b47e602b2de4b4e64892737c9c
CRs-fixed: 470430

Conflicts:
	libcopybit/copybit_c2d.cpp
copybit: Fix type conversion error for GCC 4.7

GCC 4.7 has stricter type conversion rules

Change-Id: I699cfe1ceafb5728fb8e6f34f7b1996d3c812e7e
libcopybit: Fix potential memory and surface leaks in c2d

- Check MAX_SURFACES while mapping GPU addr
 --- While mapping gpu address, first check if the request
     is less than the MAX_SURFACES allowed.
 --- Without this check, when the request exceeded MAX_SURFACES,
     there was memory leak as that gpu addr was not unmapped
- Map the destination surface only once
 --- The destination surface for the c2d blit will be the
     FRAME_BUFFER_TARGET per transaction
 --- Map this only once from the copybit_clear which is the first
     call by hwc for a transaction
- Increase MAX_RGB_SURFACES to 12
 --- To handle use cases where there are more than 8 RGB layers

Change-Id: Iffacde30ee88b9c21d0895cb1922aa981bb079e9
CRs-fixed: 475327
hwc: Reset Layer cache on idle timeout

In the case where MDP composition is possible but we fall back to
the idle timeout, there is a possibility that all of the layer
handles that were cached in the _earlier_ idle timeout are the
same in the _next_ idle timeout. This could cause us to display a
stale frame. Reset LayerCache in prepare if we are in the idle
frame.

Change-Id: I3ab1b0f28044975978a32e082976b038242697d0
hwc: Sync for rotator

Implement sync for rotator.
If a buffer is rotated, it can be used by producer soon after
rotation (and it wont have to wait until vsync).

Mdp waits for the rotator buffer's release fence to signal
to start display.

Hwc waits for previous access to rotator buffer by MDP to finish
before using it.

Change-Id: I5664806a17c44d58af62a2825ce454089fcd31cf

Conflicts:
	libhwcomposer/hwc_utils.cpp
overlay: Use correct downscale for rotator.

Downscale is calculated based on area of dst and src.
Apply sqrt of downscale to each dimension.

Change-Id: I9def4ea5073e0e49a05103505a6b6f5013f0d579
liboverlay: round off rotator downscale factor to nearest integer.

This reduces the MDP clock and bandwidth requirements and
avoids falling back to GPU composition.

CRs-fixed: 457295

Change-Id: I4408ee0485248987342df63669f1a6894ea0dd73
qdutils: Retrieve MDP revision and pipes information from driver.

Userspace can retrieve MDP revision number and number of different
types of MDP pipes (RGB,VG,DMA) information from driver. Add target
specific flag as previous MDP versions do not provide this support.

- Make use of this information while maintaining PipeBook.
- Move PipeBook related functions from overlay utils to PipeBook.

Change-Id: I46578bb27e515c4b9525d90b6619c11d7749914f

Conflicts:
	liboverlay/overlayUtils.cpp
	liboverlay/overlayUtils.h
overlay: Bring back debug.mdpcomp.maxlayer

 * We're having underrun issues with 4-layer composition. It generally
   works, but when the system CPU ramps down and the device is mostly
   idle, underrun is happening.
 * Limiting to 3 layers solves the problem temporarily on these devices.
 * Readd the option so that the issue can be debugged without afflicting
   our current users with massive amounts of flickering.

Change-Id: I7ab7d013f65eaf12a3d21a91229dcaad6a815069
libhwcomposer: align rotator source buffers for tile format.

for tile format make the rotator source buffers aligned to 64 X 32.
This avoids rotator hang during source fetch.

Change-Id: I9e42788cc6f538b155c073028ce41bf48e1d9349
CRs-fixed: 473297
hwc: Fallback to GPU if source image width or height is less than 2

There is h/w limitation when MDP_OP_SCALE_RGB_ENHANCED bit and
MDP4_OP_SCALEX_EN or MDP_OP_SCALEY_EN bit is set.
The minimum block size is 2x2. MDP will hang if the source RGB image
height or width is equal to 1. Hence fallback to GPU in such cases.

Change-Id: I7333b097fd26bfb888865de9c39d1664bc87acca
CRs-fixed: 477581
libgralloc: Change CAMERA_HEAP to ADSP_HEAP

This changes GRALLOC_USAGE_PRIVATE_CAMERA_HEAP to
GRALLOC_USAGE_PRIVATE_ADSP_HEAP as the CAMERA_HEAP
is not used anymore

Change-Id: I5a95f68c4c7f4445ade2398dd239faad9ed16b22

Conflicts:
	libgralloc/alloc_controller.cpp
	libgralloc/gralloc_priv.h
libhwcomposer: print a log if there is any delay in vsync read.

If there is a delay in vsync read print a warning message if
vsync status is enabled.

Change-Id: Iac875323fca441ff5261f8e9ddef2936e433e84e
CRs-fixed: 462993
hwc: Do not include Framebuffer area in calculating total area

In dynamic composition, While calculating total render area of
application layers to decide on which composition to choose,
FrameBuffer layer area shall not be added to the total render area.

Change-Id: I712b601031c6faac2d077a8d601cbf9fa82f3d5b
CRs-fixed: 482264
libcopybit: Fix GPU page fault on c2d use

On HDMI connect or other use cases where finish_copybit
is called, reset dst_surface_mapped and dst_surface_base
as destination surface is already unmapped.

CRs-fixed: 481685
Change-Id: I0073a46178e6b1ecfdbf0a08d8790af4271bc37b
hwc: Only enable vsync delay logging for debug builds

Change-Id: I56d0c67b3742358d4cd7439c7b6f735e0a35a055