Squashed commits of CAF frameworks/native (for review only)

LA.BF.1.1-02410-8x74.0

egl: Addition of eglGpuPerfHintQCOM.

This patch implements a wrapper that hooks into the QCOM
functionality.

Surface: Initialize variable and add a defensive check

Initialize buf variable and make sure to check for return
value of dequeueBuffer() before sending to the client.

frameworks/native: Propagate dirty region in hwc_layer.

This change propagates dirty rect value of each layer down to HWC
in hwc_layer structure.

Conflicts:
	include/gui/IGraphicBufferProducer.h
	libs/gui/BufferQueueProducer.cpp
	libs/gui/Surface.cpp
	services/surfaceflinger/Layer.cpp
	services/surfaceflinger/Layer.h

SurfaceFlinger: Add support for virtual display

- Creates a rendering surface when invoked via hybrid path
- Makes changes in HWC wrapper to handle virtual display via HWC

Conflicts:
services/surfaceflinger/SurfaceFlinger.h
services/surfaceflinger/SurfaceFlinger.cpp

sf: vds: Selectively compose displays via HWC.

1. Replace static force copy flag with member variable

The decision to copy a virtual display using the WriteBack path will be
done when the display is created. We initialize the member variable to
false meaning all virtual display devices are composed via GLES.

2. Select which displays to compose based on sink usage flags

We should compose a display using HWC only if the sink usage contains
GRALLOC_USAGE_PRIVATE_WFD and GRALLOC_USAGE_HW_VIDEO_ENCODER flags.

If this condition is not met then the display is composed using GLES.
This means that GLES composes directly into the sink buffer and signals
the consumer. Furthermore, it is expected that any color conversion will
be handled on the consumer side.

3. Add debug hook for ScreenRecord use case

We add a debug hook which serves to by-pass the checks imposed by (2).
This is useful for debugging purposes and allows us to test VDS
end-to-end when WFD is not working on a particular build.

The debug hook is through the system property: debug.hwc.screenrecord

4. Update composition checks

-mFbProducerSlot is always at least 0 so there is no point in validating
 it when in advanceFrame().
-Release scratch buffers in onFrameCommitted as long as mFbProducerSlot
 is valid.

Conflicts:
services/surfaceflinger/DisplayHardware/VirtualDisplaySurface.cpp

sf: Add dirtyRect information to SF dumpsys

Display dirtyRect information generated for each layer in
SurfaceFlinger Dumpsys.

frameworks/native: Reset dirtyRect after every queuebuffer call.

Sometimes HWR does not generate dirtyRect even when it updates the
buffer. To avoid incorrect DR calculation in such cases reset
cached dirtyRect after every queueBuffer call.

SurfaceFlinger: Change to support framebuffer flip for 2D blitters

- Surfaceflinger does not flip framebuffers when there are
  no layers marked for HWC_FRAMEBUFFER
- This change checks for the HWC_BLIT flag and will request a flip
  to a new FB_TARGET buffer even if there are no FRAMEBUFFER layers

Conflicts:
	services/surfaceflinger/DisplayHardware/HWComposer.cpp
	services/surfaceflinger/Layer.cpp

SF: Avoid wormhole clear for BLIT calls

Do not call GPU clear from SF when composition
type is BLIT as it'll be taken care in HAL.

SF: Modify logic to handle "transparent Region" for displayFrame

sourceCrop and displayFrame calculations according to "transparent Region"
are not synchronized. Because of this mismatch scaling is introduced,
causing corruption in UI. To avoid this scaling, map displayFrame to
sourceCrop, apply reduce and remap result to displayFrame.

CRs-Fixed: 660699,651365

sf: Enable QCOM_BSP if TARGET_USES_QCOM_BSP is set.

Enable QCOM_BSP if TARGET_USES_QCOM_BSP is set in target
BoardConfig

fix copy back dirty region

Copyback dirty region logic does copyback,
even when its not necessary causing 2ms delay.
Fix the logic to copy back only what is necessary.

CRs-fixed: 562334

surfaceflinger: Set max acquired buffer count

If triple framebuffers are enabled, the number of acquired
buffers isn't increased by default. Set the count to one less
than the max buffers to make sure all three buffers come into
play.

SF: Fix invalid reduction of transparent region from a layer.

Reduce transparent region from a layer only if the transparent
region has valid intersection with the layer. Otherwise, reducing
a transparent region lying completely outside of the layer leads to
invalid sourcecrop values for the layer.

CRs-Fixed: 620973

GlES2: Add NULL check

Check for NULL before calling thread specific glGetString.

CRs-fixed: 569609

Init display orientation according to panel orientation

   - Initialize the display default orientation to panel orientation.
   - honor the panel orientation only after the end of boot animation
     or the new orientation is as same as panel orientation.

SF: Ensure boot animation always appears in panel orientation

Ensure that boot animation is always shown in panel
orientation.

CRs-Fixed: 604934

sf: Set view frame of each display using binder

Set the view frame of a display using binder when set projection
for that display changes

surfaceflinger: Allow gpu to render widevine level3

Allow gpu to render widevine level3 but keep
blocking screen shots.

CRs-fixed: 428647,424769,421767

sf: Fix incorrect state reporting in dumpsys

Dumpsys utility access layer compositionType variable
with out proper protection. These variables are modified
during hwc_prepare call. Existing HAL lock protection is not
sufficient to address this issue. Failure to do this will
result in incorrect state reporting in dumpsys.

A new drawLock mutex in HWComposer that will be used in both
dumpsys and draw calls to ensure correct state is accessed.

SF: Check ViewFrame validity before sending to hwc

Check if ViewFrame is valid before sending to hwc to make sure
composition produces valid values.

A ViewFrame can get invalid values when the framework is disconnected
which is a step necessary for some testing scenarios.

sf: Determine if virtual display can use HWC for composition

For HWC virtual display using V4L2 approach:
1. HWC virtual display implementation doesn't send output buffer
   back to Surface Flinger.
2. For non-wfd virtual displays(e.g. Simulated Secondary Displays,
   Screen Record, CTS etc..), configure VDS to use GPU for
   composition on output/sink buffer.
3. For wfd virtual display (a.k.a hybrid wfd), use
   Framebuffer surface (similar to external display mechanism).

For HWC virtual display using VDS approach:
1. HWC is allocated for first virtual display connection.
2. Subsequent virtual display sessions will be composed by GLES driver.
ToDo: Modify VDS component to allocate hwcDisplayId based on
mForceHwcCopy (which is based on Usage Flags)

sf: vds: Allocate display ID for displays composed/copied by HWC

We make VDS responsible for deciding if a display will be composed
by HWC. This is primarily based on the usage flags on the sink
buffer, as well as on the requested display resolution.

With this approach, there are two possible scenarios in which we
make a decision that applies while the display is connected:

1. The display will be composed by HWC, and we use WB to produce
   the final output.
2. The display will be composed by GLES/GPU and HWC has no knowledge
   of this display.

For case 1) we will have a valid display ID and for case 2) we will
have NO_MEMORY as the display ID.

sf: vds: Add support for secure virtual displays

1. Propagate secure flag on display creation

In SurfaceFlinger we have information that tells us whether a
display is secure or not. We need to propagate this information
when creating the corresponding virtual display, allowing us to
configure output buffers with the correct (secure) usage flags.

2. Use secure heap only for sessions that need HW level protection

Use MM heap only if the secure session needs hardware level
protection. At the present moment we are assuming that only displays
with the GRALLOC_USAGE_HW_ENCODER need hardware level protection.

frameworks/native: Modify dirtyRect only on GPU pre-rotation

Modify layer dirtyRect only when the buffers are pre-rotated by
GPU, not when the buffers are scheduled to be rotated during
composition.

Conflicts:
        services/surfaceflinger/Layer.cpp

Add Digital Pen hovering cursor support

Add digital pen hovering cursor support so
that whenever the digital pen is enabled,
the hovering cursor will be shown.

SurfaceFlinger: Dont show Animation on External Display

- With this change the animation effect will not be shown on
  external display.
- It will change from portrait to landscape in one shot.
- Primary would still continue the animation effect
- set property sys.disable_ext_animation to disable animation

CRs-fixed: 453747

Conflicts:
	services/surfaceflinger/DisplayHardware/HWComposer.cpp
	services/surfaceflinger/DisplayHardware/HWComposer.h

Conflicts:
services/surfaceflinger/DisplayHardware/HWComposer.cpp

sf: Invalidate and Delay eDisplayProjectionChanged binder transaction

Invalidate and Delay the binder thread by 50 ms on
eDisplayProjectionChanged to trigger a draw cycle, so that it can fix
one incorrect frame on External, when we disable external animation.

SF: Fix Klockwork errors.

Resolve klockwork errors in frameworks/native
to avoid buffer overflow and memory leaks.

SF: Block gpu rendering for virtual display widevine level3

In MDP3 we are using the widevine level3 for secure content
display. And this should applicable only for primary display
not for screen shot or screen recording

CRs-Fixed: 595469

sf: Allocate displayId based on usage flags for VD devices

Allocate hwcDisplayId for VirtualDisplayDevices based on
the usage flags set by the client.

sf: vds: Queue Sink buffer during invalidate

commit id:f3c07d4f70f33c2fe5b14ca8fbcdfa4133cc72c7 didnt queue sink
buffer if there is no screen update on virtual displays.

This was required to support nested virtual displays. However,
this breaks Miracast WFD Sink initiated pause/resume functionality.

Allow Queueing sink buffers if mForceHwcCopy is true.

sf: Use DirtyRect to optimize Full GPU composition

Use layer DirtyRect information in optimizing full GPU composition by
using startTile and endTile GL calls.

sf: Use Dirty Rect optimization in "Show Surface Updates" setting

When "Show Surface Updates" setting is ON in developer options, flash the
updating part (union dirty rect) instead of full layers when
GPU Tiled DR optimization is ON.

CRs-Fixed: 679386

frameworks/native: Add support for custom layers in Surfaceflinger

  - Check for the EXT_ONLY layer and add only that layer to external
    list and do not add that layer to the primary list
  - Check for INT_ONLY layer and remove that layer from external list
  - These are added to support EXTERNAL_ONLY & INTERNAL_ONLY feature

Surface: Fix gralloc flags conflicting values.

Due to some custom code, unwanted flags (HW) got added with SW flags.
Restrict the flags to custom ones.

sf: Override presentation layer with ext_only layer

Do not add presentation layer to the external list when external only
layer is present.

frameworks/native: Add support for Secure Display

- Add secure UI layers to primary and remove other layers from
  internal and external list for Secure Display usecase.
- Dont let secure UI layers to be captured on screen

SurfaceFlinger: Add support for extendedMode

- Displays only video with full screen on External with no UI controls
- Primary will show only UI controls
- Similar to presentation class, but will be used by a third
  party app, which does not use presentation class
- To enable this set sys.extended_mode to 1

sf: Remove 50ms delay when external animation is disabled

1. Delay display projection transaction by 50ms when disable external
   animation feature is enabled.
2. Read the property sys.disable_ext_animation only during bootup to
   avoid unneccessary read for every draw cycle.

sf: Validate display device id and disable dirtyrect composition

- Add validation check for display device id to prevent out of bound
   array access.

sf: Enable GPU Tiled DR optimization for overlap and mixed mode use cases

Extend the GPU Tiled DR optimization to Overlapping layers use cases
and mixed mode composition

sf: Clear FrameBuffer only if there are GLES composed layers

Clear FrameBuffer Target only if there are layers to be composed by
GLES. Otherwise, it results unnecessary gl calls and increases power
consumption in full MDP comp use cases

sf: Validate display id while introducing 50ms delay

Correct condition check while validating display id while
introducing 50ms delay when external animation is disabled.

sf: Use property to set default app buffer count

For memory optimization (based on RAM size and
screen resolution) making default app buffers count as configurable.

sf: Make default app buffers count to three.

Default two app buffers not sufficient for fast
rendering based test cases. Hence increasing default
app buffer count to three for these use cases only.

sf: Avoid disabling DispSync resync

Avoid disabling DispSync resync if app and SF events aren't
using phase offsets. This prevents hardware VSYNC from turning
on always whenever something needs to be drawn, thereby
bringing down the power numbers.

sf: vds: Fixes and code cleanup for VirtualDisplaySurface

1. Remove unused variable declarations

   Remove static variable sForceHwcCopy that is not required since moving
   to an implementation that uses a local variable mForceHwcCopy.

2. Add a condition to reduce log spam from advanceFrame hook

   When mForceHwcCopy is true, we override the composition type to MIXED.
   Therefore, we need to check whether we are in this scenario and add
   checks to satisfy the state machine requirements and reduce log spam.
   In particular, by setting mForceHwcCopy we can now expect to get an
   advanceFrame when composition type is MIXED and our previous state was
   PREPARED or GLES_DONE.

libgui: Add native window attributes to query usage

This is required to enable GL libraries to query usage
native window attributes to enable/disable tile rendering.

Do not limit android EGL wrapper to RGB formats.

Implementation may support other color buffer type than RGB and luminance, in
that case allow client to choose implementation supported formats

sf : Fix vertices & texture coordinates computation.

Compute crop and display frame for GPU composition also
in the same way it's done for HWC and compute vertices
and texture coordinates for GPU composition. This avoids
pixel shifts in output of GPU composition & overlays.

sf: Fixes for resolution change in SurfaceFlinger

1. Use active config from HWC when querying display attributes

   When we query the display attributes we should use the active
   config as reported by HWC in cases where HWC version is 1.4.
   In all other cases we should revert to the default config,
   config 0, as the active config.

2. Set/update the display config if HWC config change was successful

   The new config should only be applied if HWC succeeded in changing
   the active config. This would otherwise cause failure or undefined
   behavior if the client sets an invalid/unsupported display config.

3. Set the active config at display creation time

   When a new display device is added update the active config by
   querying HWC.

Change-Id: I72a3b819e1124c75ce778081535188f3d12c3056