882 Commits

Author SHA1 Message Date
Xin Li
10d9972786 Merge sc-qpr1-dev-plus-aosp-without-vendor@7810918
Bug: 205056467
Merged-In: I13199bc39e9445929195f3d15579cbffe94e92b0
Change-Id: I35fa3c6c2abf679c51033f1395a08d511ed8739f
2021-11-18 17:00:37 +00:00
Brett Chabot
3f8b9fe50b Backport 'Add ability to disable GL draws'.
This feature is intended for use in headless test environments,
where disabling drawing has minimal compatibility impact and can
save significant resource usage when running UI tests.

This feature is controlled via a new system property
'debug.hwui.drawing_enabled', and a HardwareRenderer API that can
override the property value on a per-process basis.

Bug: 201691826
Test: boot emulator
Merged-In: I93c21e680382e03342f235dbf58bd7a5c8a6f767
Change-Id: I391c841e3a0cdcfcc6c7910a316a4dd5e970547d
2021-10-26 21:16:16 +00:00
Nader Jawad
4a6b60a5a8 Conditionally cache RenderEffect results
Added property to conditionally cache SkImage instances
with SkImageFilters applied. Some GL vendor implementations
invoke Fence::waitForver without signalling, leading
to ANRs throughout the system.

Bug: 193145089
Test: manual
Change-Id: I3e478b11b66205d96e9499a362f7412a1d6e952d
2021-09-22 02:27:33 +00:00
Leon Scroggins III
7fbd0ad0f9 CanvasContext::draw: flushAndSubmit when not drawing
Bug: 195081399
Test: manual + dumpsys gfxinfo

CanvasContext::draw has some conditions under which it will not draw. We
still need to flushAndSubmit to free scratch memory if there were
texture uploads this frame.

Change-Id: I60d230cd36bed310a3155e4f1ca647c99c13c4cd
2021-08-06 13:42:49 -04:00
Bo Liu
6a3fc60f43 Switch HWUI to use native performance hint API
Test: None
Bug: 194204196
Change-Id: I80dfdb5d56921c465406cc4534e82738c668d46d
2021-07-22 11:33:01 -04:00
TreeHugger Robot
f560a753fd Merge "In VuklanManager make sure we have a valid semaphore context before destroying it." into sc-dev 2021-07-16 21:26:53 +00:00
Greg Daniel
e8dc397bfd In VuklanManager make sure we have a valid semaphore context before destroying it.
If errors occured during finishFrame that caused us to not have a
semaphore or possibly destroy the semaphore early we will end up
with a null mDestroySemaphoreContext in swapBuffers which we tried
to destroy unconditionally.

I haven't repro'd the connected bug, but based on the crash stack
this seems like the likely cause.

Test: manual code inspection and build.
Bug: 191950033
Change-Id: I0fbd33edff3552b91b980da9e3b2c45bc52a2dd0
2021-07-15 13:38:44 -04:00
John Reck
cf1170fbda Always submit after texture uploads
Ensure GrContext::submit() is always called after either
Bitmap#prepareToDraw() or if DrawFrameTask skipped drawing.

In either case texture uploads & deletions will be scheduled,
but without the submit they won't actually be performed. This
can end up running out of RAM.

Bug: 189393671
Test: manual test app
Change-Id: I57477c64457558487e9e5ec0a979ad9099a8cb2c
2021-07-14 17:06:28 -04:00
TreeHugger Robot
1e67f86165 Merge "Properly protect mFrameMetricsReporter" into sc-dev 2021-07-11 08:30:13 +00:00
Siarhei Vishniakou
07d35cb7dc Properly protect mFrameMetricsReporter
This field actually requires a special lock, mFrameMetricsReporterMutex.
But there isn't a GUARDED_BY annotation for it. And even if there was,
the compiler feature of -Wthread-safety was not active in this code, so
this error would not have been caught.

To fix this, enable the compiler annotation and add GUARDED_BY
annotation to mFrameMetricsReporter.
And finally, use this lock to properly protect this field.

Bug: 192330836
Test: atest hwui_unit_tests
Change-Id: I76950bfa01bbd7ccdc54c4e8c114430b5aeddf1a
2021-07-09 00:32:29 +00:00
John Reck
b7039c6aa5 Reduce number of weakrefs per frame
Disable end-to-end input latency metric to reduce the
number of JNI WeakGlobalRef acquires per-frame.

Bug: 189738006
Test: Observe trace section no longer appears in calculator
Change-Id: I062dad8e7cec93cca5599e51d2b0b1a1b6e39a07
2021-07-07 19:18:34 -04:00
Huihong Luo
540fdf89b1 Reparent surface control for Webview overlay
When the root surface control changes, the parent of the Webview surface control must be changed.

Bug: 191900007
Test: switch app, or turn on/off screen
Change-Id: Ib7b34133776fd5944afc638bfee471afe6a17349
2021-06-28 20:36:40 -07:00
TreeHugger Robot
544b5f5b2e Merge "vsyncId should always be incremental" into sc-dev 2021-06-28 23:58:30 +00:00
John Reck
e947e2e20a Merge "Revert "Delete RenderProxy off of the cleaner thread"" into sc-dev 2021-06-25 19:00:24 +00:00
John Reck
f0b6921e89 Revert "Delete RenderProxy off of the cleaner thread"
This reverts commit da3559683482a61d93b06bed6f46349f6f01dc63.

Bug: b/192050906

If too many RenderProxies are destroyed too quickly, we can end up jamming up the CommonPool preventing RenderThread from making progress if it's waiting on CommonPool tasks.

Change-Id: I8c324bc60891440d9b7be67961f8d5f881dc0f03
2021-06-25 18:59:47 +00:00
Rob Carr
472d962453 Merge "Delete RenderProxy off of the cleaner thread" into sc-dev 2021-06-25 02:18:17 +00:00
John Reck
da35596834 Delete RenderProxy off of the cleaner thread
Speculation for the cause of an ANR. HardwareRenderer's
cleaner can block on RenderThread, which in turn blocks ART's
cleaner thread. This can potentially cause other blockages, but
it's also poor behavior to have such a long-running Cleaner anyway.

Avoid this by putting cleanup to CommonPool.

Bug: 191514384
Test: make, CtsUiRenderingTestCases still passes

Change-Id: I8190f7862528c3ac39ce636f6fca229322480968
2021-06-24 21:58:05 +00:00
Huihong Luo
4df4151bc0 Fix a crash caused by transaction
A native transaction passed from webview is sent back to native side, so java side does not manage the life cycle of the transaction.

Bug: 191414767
Test: Play a video, switch to another app, wait for 10 seconds
Change-Id: I013052c202b445438d6cb6497f5f9a2fc22a2b85
2021-06-24 11:10:06 -07:00
Ady Abraham
505e730e7d vsyncId should always be incremental
In some conditions of scheduling delays, Choreographer may
synthetically advance the indented vsync time. In that case we can't
send a vsync id since there is no one that corresponds to that time.

Test: TBD
Bug: 191840734
Change-Id: I7b2754d5dcb0a3f5fd6cda00a3a2469041116f67
2021-06-23 15:04:04 -07:00
Huihong Luo
17410b668f Merge "Fix z-order for webview surface control" into sc-dev 2021-06-18 19:53:34 +00:00
TreeHugger Robot
5001447b86 Merge "Remove the extra buffer allocation from hwui" into sc-dev 2021-06-18 17:21:39 +00:00
Huihong Luo
34f42fdecd Fix z-order for webview surface control
Set the root surface control transparent, and set the z order of the newly created child surface control to -1.
A new callback is needed to update root surface control in sync from Java side.

Bug: 186750329
Test: use latest APKs from Webview team, play a video, mini toolbar should be visible
Change-Id: I0b37ee8f83fd2b41ff4f2856dbadd31ff6170baf
2021-06-18 10:14:22 -07:00
Ady Abraham
f558ab782c Remove the extra buffer allocation from hwui
SurfaceFlinger will set the maxAcquiredBufferCount on the buffer queue
to account for the extra buffers needed, depends on the refresh rate
and app/sf durations, and there is no needed for any addional buffer
allocation is hwui.

Test: TBD
Bug: 188553729
Change-Id: Ic441a6feb15f6b084d45c9e538b11b7b24e36a0e
2021-06-15 10:25:29 -07:00
Nader Jawad
dd1fcab19a Add logic to clean up resources more frequently
Added call to Skia's performDeferredCleanup method
to free resources that were not referenced within
the last 100 frames or 10 seconds whichever is
furthest away

Bug: 188450217
Test: manual
Change-Id: I3f37e1b5bd01330dbbc2da4a84b1259d56be2768
2021-06-15 10:14:04 -07:00
John Reck
b99e72f722 Merge "Improve picture capture debug path" into sc-dev 2021-06-11 18:28:34 +00:00
John Reck
760051854e Improve picture capture debug path
* Fixes hardware bitmap capture
* Fixes mutable bitmap capture (no flickering)
* Adds basic single-frame LRU cache to avoid
  repeated readbacks of GPU resources
* Does up-front readback of GPU resources
* Moves serialization off RenderThread again thanks
  to up-front readback avoiding needing GPU access
  off-thread
* Reduces RAM usage & improves performance by serializing
  directly to output stream instead of first copying to
  a byte[]

Bug: 174223722
Test: PictureCaptureDemo mirrors the content
Change-Id: If7ec208b61d5b917e82087cc312880fc5a38c943
2021-06-11 01:52:14 +00:00
Greg Daniel
d667077899 Make sure to close vulkan fd's in error cases
In one set of the fixed cases we actually were never closing the
fd. In the other set we would crash with a fatal error. Now both
have been updated to handle the failures and correctly close the
fd to make sure it all works.

However, I don't think this is the route case of the leaking fds
from the bug since I don't believe we are seeing any of the
corresponding error messages in the logs.

Test: Manual running on phone and watching logs.
Bug: 187240173
Change-Id: I18babe91b0ec83ca63199f06d3d02ec10e8aea85
2021-06-09 12:11:49 -04:00
Greg Daniel
ffc50c689f Reset buffer tracking state in VulkanSurface.
When we fail to create an SkSurface from a dequeued
buffer we then call cancelBuffer on that buffer. However,
we don't update our tracking to say the buffer is no
longer dequeued with and doesn't own the fence any more.

I don't think this is the main issue causing the crash in
the attached bug because I don't think we're seeing the
error in the logs for this chunk of code. However this
possibly related issue was found while tracking down our
use of the dequeue_fence fd.

Test: manual building and running of phone
Bug: 187240173

Change-Id: Icb4099eeea5be6aedd5376e07a6e3454f5d1d1e3
2021-06-08 14:30:24 -04:00
Jorim Jaggi
e4a52711e7 Ensure reportFrameMetrics not being called on deleted instance
Since onSurfaceStatsAvailable gets called on binder-thread, we
need to ensure that instance doesn't get released while
onSurfaceStatsAvailable is calling reportFrameMetrics.

Test: Boots
Bug: 188934435
Change-Id: Iafe582d6fe4087a3c4274ee39a2803abaa363fd2
2021-05-31 17:57:50 +02:00
rnlee
ce9762b57f Use TraceUtils.h from gui shared library.
Test: It makes
Bug: 183120308
Change-Id: I331262dd2da59817031f0c708f4c102041dcb5e0
2021-05-22 00:12:43 +00:00
John Reck
248d942bb7 Merge "Fix PixelCopy & BQ crop" into sc-dev 2021-05-20 20:27:28 +00:00
John Reck
2abc5494d8 Fix PixelCopy & BQ crop
Change Surface to return the original crop rect + transform int instead
of a matrix in GL's bottom-left origin in 0..1 space. This avoids doing
an extreme amount of matrix pulling apart to try and guess at the inputs
and map rects around to make it maybe work sometimes along with avoiding
the need to convert that matrix into skia's top-left non-unit space.

This also opens the door to avoiding the 1 texel crop problem if
ASurfaceTexture is similarly adjusted to return the crop+transform
instead of a float[16] matrix as we are using a proper srcRect to
sample from instead of purely done via matrix manipulation. This CL
continues to pass kFast_SrcRectConstraint so we don't actually
benefit but it at least COULD.

Fixes: 183553027
Test: atest android.view.cts.PixelCopyTest (+new testBufferQueueCrop)
Change-Id: I5f638153baed7f67dc43fe9ecb4587f579222b5d
2021-05-18 00:45:23 -04:00
Jorim Jaggi
b891cdf24a Use SwapBuffersCompleted as frame end time
...in case GPU completes really quickly.

Fixes: 181899835
Test: atest FrameMetricsListenerTest --iterations 50
Change-Id: I73b9380f92eb15f94ae4754746ee98c7fbc4e6c7
2021-05-17 23:24:03 +02:00
Greg Daniel
1d9de71ed9 Add a mutex to VulkanManager::initialize.
The initialize call can be made from both an GrallocUploadThread
and the RenderThread. So we need a mutex to make sure both
threads don't try to initialize in parallel.

Bug: 187218890
Test: manual running of device, guessing this could fix bug.
Change-Id: I203afd91fad5eacc131c839dff1a1065864b76f8
2021-05-14 10:42:34 -04:00
Huihong Luo
f410f8134f Merge "Fix leakage of ASurfaceTransactionCallback" into sc-dev 2021-05-14 03:33:53 +00:00
John Reck
f0baa24d43 Fix some FD lifecycle issues
Use unique_fd, it's cool

Bug: 186919605
Test: make, guessing from a pretty clear error message & documentation
Change-Id: Ied546565261708b7e4c2d220dce6d6a89725cc06
2021-05-13 18:15:50 -04:00
John Reck
3920768c72 More benchmark tweaks
Bug: 187718492
Test: this
Change-Id: Ie0cad91e1c7d1a02704fc4b1007ba2c28cb2b3e7
2021-05-12 19:29:03 -04:00
TreeHugger Robot
f196d46fdf Merge "Macrobenchmark tweaks & gpu memory dumping" into sc-dev 2021-05-12 03:21:29 +00:00
TreeHugger Robot
a2883f3b31 Merge "Ignore blocked-on-sf time for ADPF" into sc-dev 2021-05-12 00:44:45 +00:00
John Reck
66e06d4ff1 Macrobenchmark tweaks & gpu memory dumping
Add support for glob matching
Ensure glob matches are alphabetically sorted
Add feature to dump GPU memory usage after a test pass
Adjust gpu memory dump to be a bit more compact (skip empty outputs)

Test: this
Bug: 187718492
Change-Id: I6dc80b2d3379d8d10001116e1240727d9914bc10
2021-05-11 17:06:53 -04:00
Bo Liu
4d0f1f1cce Ignore blocked-on-sf time for ADPF
Subtract out time spent blocked in dequeueBuffer. Also subtract out any
time UI spents waiting on render thread while render thread is blocked
dequeueBuffer, though this calculation is fairly crude.

Test: Checked bouncyball returns reasonable-ish numbers even when HWUI
      is ahead of surface flinger
Bug: 187556381
Change-Id: I368c446d93990ff8b7b645e30509405ba799c79c
2021-05-08 00:54:41 +00:00
Adlai Holler
108be5bcfa Always use Skia reduceOpsTaskSplitting
This feature was previously limited to high-end devices, but now that
there is a fallback when VRAM is limited, it will be enabled globally.

After the feature is rolled out to all major Skia clients, it will be
the only way things work.

Bug: 183612348
Change-Id: Ia99ec154b498ab9315ec5f5285241fde8136c4ab
2021-05-07 20:05:56 +00:00
Huihong Luo
e76f181372 Fix leakage of ASurfaceTransactionCallback
The callback needs to set to null when thread renderer is destroyed.

Bug: 187419942
Bug: 186869429
Test: blaze test --test_strategy=local --test_arg=--device_broker_type=LOCAL_ADB_SERVER //javatests/com/google/android/testing/elizabot/internal/sanity/subscriptionleak:SubscriptionLeakTest_generic_phone_google_31_x86
Change-Id: Ic80c58f102ee5f21830542030021828f6231cc37
2021-05-07 08:17:26 -07:00
Huihong Luo
054b8d3000 Webview overlay support
The basic idea is to create a child surface control from the root surface control passed from ViewRootImpl to the render thread.

Transactions are sent back to the java layer to get merged.

In case of offscreen layers, SurfaceControl must be disabled.

This new feature is disabled for Vulkan at the moment, a new CL will be used to enable the support.

Bug: 173671170
Test: manual, webview apks
Change-Id: I119405d13eca3c59fd3ec78e50dc7739f78411d4
2021-04-17 13:24:48 -07:00
John Reck
31164bc1ec Merge "Fix a logspam" into sc-dev 2021-04-14 13:46:27 +00:00
John Reck
6f97e15e3b Fix a logspam
On skiavk the flush to GPU happens sooner than it does on skiagl,
which was resulting in false-positive warning logs. Adjust the
condition to avoid this, so it should now only log if the GPU
fence time is significantly incorrect.

Fixes: 180488606
Test: doesn't log on skiavk
Change-Id: Ie6546b788663b5d863fb064f55245bead4eb0160
2021-04-13 12:09:12 -04:00
Jorim Jaggi
10f328c580 Change hwui jank detection to use deadline & gpu completion (1/2)
- Use GPU finish time as well as actual deadline to determine jank
rate.
- Use dynamic interval to adjust for 60/90hz switching
- Move frame metrics reporting into JankTracker to adjust the
deadline communicated to the app when in stuffing scenario.
- Adjust double-stuffing detection to be a bit more readable.

Test: GraphicsStatsValidationTest.java
Test: adb shell dumpsys gfxinfo
Test: FrameMetricsListenerTest
Test: Log output of FrameMetricsObserver
Bug: 169858044
Change-Id: I3a6b8ed163e2cf9cf2b67667110340ebe35f98a1
2021-04-13 15:18:27 +00:00
Bo Liu
027b218847 Integrate HWUI with PerformanceHintManager
PerformanceHintManager.Session is in java, so add JNI and a HintSessionWrapper
class in HardwareRenderer. Then pass the two calls as two std::functions
into DrawFrameTask.

Note Session is created per HardwareRenderer, not global (per
RenderThread).

Session includes UI thread, render thread, and the thread pool.
Desired duration is from the intended start duration to the frame
deadline. Add an actual frame start time to compute

Add system properties:
debug.hwui.use_hint_manager to enable PerformanceHintManager
debug.hwui.target_cpu_time_percent to control percentage of frame time
  to be used for target cpu duration.

Test: Manual test that there are no crashes and values make sense.
Bug: 158791282
Change-Id: I83f25433c10daa20033803fb7c4ae45eab34f1d3
2021-04-10 10:21:17 -07:00
Greg Daniel
16d11c6d38 In CanvasContext check at start of frame if GrContext is abandoned.
On Vulkan part of the abandoned check also checks for device lost.
Following what we currently do in GL, we now crash if we are ever
in this state.

Test: local build
Bug: 183722403
Change-Id: I2a41005fd6892e32a8b23dacbc0170d5542fe072
2021-04-08 16:17:35 -04:00
Steven Moreland
f3aba6eed5 Merge "libhwui: RenderThread: fix UAF" into sc-dev 2021-04-02 21:19:27 +00:00