Commit Graph

3333 Commits

Author SHA1 Message Date
Leon Scroggins III
1996dbb19c Make AnimatedImageDrawable.start reset
Bug: b/63908092
Test: Manual: Ie18811ba29a1db163aca08472b04ae185e9344f0

If the animation has already started and stopped (via stop()), restart
the animatino on a call to start().

Change-Id: I0a14a1e643f32469fe5519949ee8ef046107e9a8
2018-01-29 21:08:56 -05:00
Leon Scroggins III
5b7f426ff0 Use a separate thread to decode AnimatedImageDrawable
Bug: 63908092
Test: Manual: Ie18811ba29a1db163aca08472b04ae185e9344f0

Depends on https://skia-review.googlesource.com/#/c/skia/+/101544. That
change removes the Skia class's time checks, and leaving it up to the
client to keep track of the time. In this case, the client wants to keep
track of the time because it only wants to update while it is being
drawn. If it goes off screen (for example), it will just resume where it
left off when it returns on screen. This allows for smooth animations.

If an AnimatedImageDrawable is being drawn to a SkiaRecordingCanvas,
decode on the new (lazily-created) AnimatedImageThread.

When running, always decode one frame ahead on the AnimatedImageThread
so that it will be ready when it is time to display.

During prepareTree, update the time and check whether there is a new
frame ready to draw or the next frame needs to be decoded. In either
case, return true. The next frame to be decoded will be triggered by
onDraw.

Change-Id: If447976e9df417060a950f658dbca9cf7980dd02
2018-01-29 21:08:18 -05:00
Leon Scroggins
c4533b7085 Merge "Expose AnimatedImageDrawable" 2018-01-26 11:16:04 +00:00
Selim Cinek
d41477f494 Merge changes from topic "notification_launch"
* changes:
  Added the reply draft as an extra to the content intent
  Launching notification settings correctly inline
  Launching Notification animations inline
2018-01-25 16:05:15 +00:00
TreeHugger Robot
6834ec8e54 Merge "Fix start/pause behavior for AnimatedImageDrawable" 2018-01-25 05:41:21 +00:00
Andreas Gampe
9548a1b04e Merge "BitmapDrawable: Suppress errorprone warning" am: 25e50ccccb am: 822e828971
am: 9c6acbd248

Change-Id: I4846f6b91fadbbd650e925c70215dea4d4459278
2018-01-25 03:04:07 +00:00
Andreas Gampe
9c6acbd248 Merge "BitmapDrawable: Suppress errorprone warning" am: 25e50ccccb
am: 822e828971

Change-Id: I0481e40c91e5848fc7ab551a794269d9379cbcc9
2018-01-25 02:48:37 +00:00
Leon Scroggins III
127d31a684 Expose AnimatedImageDrawable
Bug: 63908092
Test: I85979ae3d8c6a6dae6e4299dc3be291e12024290

Implement Animatable2, adding listeners for starting and ending the
animation.

Add setLoopCount for changing the loop count.

Add the ability to inflate from XML, by using the name of the class or
"animated-image", which mimics "nine-patch", "bitmap" etc.

Move internal variables to a State class so that they can be transferred
to a default constructed AnimatedImageDrawable.

Change-Id: Ice8149e7de55f7ffb4b4ba9dd9c856582fc42bc9
2018-01-24 19:20:18 -05:00
Selim Cinek
2627d72e61 Launching Notification animations inline
Using the new control mechanism introduced in order
to coordinate notification launches and smoothly
transform the notification into the launching window.

Bug: 69168591
Test: add notification, launch it
Change-Id: Ib2d671c65f276ec596a2f07edf64d65bf27a2882
2018-01-24 23:29:28 +00:00
Derek Sollenberger
c04c265dd5 Merge "Fix bug in ImageDecoder which provided the incorrect density to NinePatchDrawables" 2018-01-24 23:09:53 +00:00
TreeHugger Robot
ab802003b9 Merge "Compute full text layout in MeasuredText and use it for drawing" 2018-01-24 22:07:13 +00:00
John Reck
6e618d6034 Merge "Limit ripple alpha to 50%" 2018-01-24 21:51:06 +00:00
Andreas Gampe
8272fe83e0 BitmapDrawable: Suppress errorprone warning
Suppress a warning for constructor-chaining not using all parameters.

Bug: 72451126
Test: m javac-check RUN_ERROR_PRONE=true
Change-Id: Ie47dec119ec578b79d866d9c5041bb7b68eac146
2018-01-24 13:25:22 -08:00
Siyamed Sinir
4e2b139b82 Merge "Revert "Make ellipsize retry if text doesn't fit"" 2018-01-24 19:45:03 +00:00
Leon Scroggins III
057c91a20d Fix start/pause behavior for AnimatedImageDrawable
Bug: 63908092
Test: HwAccelerationTests

Do not start the animation at creation time

When starting, first update the time, so it doesn't think we skipped a
bunch of frames if we're resuming.

Continue storing the SkPicture when stopped, so that we can continue to
show the same frame, without a jump.

Change-Id: I5ac77f2561fc9f42f8f69ebfbee21fe647cfc75a
2018-01-24 13:05:17 -05:00
Derek Sollenberger
9f074eeee6 Fix bug in ImageDecoder which provided the incorrect density to NinePatchDrawables
Bug: 72381918
Test: ThemeHostTests
Change-Id: I7679d4a8d9c3495fd7b24536f54d23bfef007f26
2018-01-24 17:35:14 +00:00
TreeHugger Robot
0c60f4357f Merge "Revert "Use ImageDecoder for BitmapDrawable"" 2018-01-24 15:57:44 +00:00
Leon Scroggins III
e7addfc999 Revert "Use ImageDecoder for BitmapDrawable"
Bug: 72381918
Test: Covered by existing tests

This CL seems to have broken the theme tests. In addition, it changes
the behavior of a couple of cases of passing InputStreams to the
framework. Previously, the framework used BitmapFactory, which did not
close the InputStreams, but ImageDecoder does.

Planning to reland along with the fix for closing in ag/3497523 and the
fix for the theme tests.

This reverts commit 66c6d78908.

Change-Id: I4ac6d0f2e1e2bb0925ae71c141bfe8a0d37e6a16
2018-01-24 13:33:06 +00:00
Derek Sollenberger
2d14213849 Initial implmentation of AnimatedImageDrawables on the RenderThread.
The current implementation schedules the next frame of the images
to be decoded after the current frame completes but potentially
schedules tasks that will result in a no-op execution if a new
frame is not yet needed.

Test: HwAccelerationTest
Change-Id: I0510cb5a1b801abd651327e924deb586af0306d6
2018-01-24 13:11:39 +00:00
Siyamed Sinir
1a5648a2cd Revert "Make ellipsize retry if text doesn't fit"
This reverts commit e88b5df5b7.

Test: bit FrameworksCoreTests:android.text.StaticLayoutTest
Test: bit FrameworksCoreTests:android.text.DynamicLayoutTest
Test: bit FrameworksCoreTests:android.text.TextUtilsTest
Test: bit CtsTextTestCases:*
Test: atest FilesActivityUiTest

Bug: 71599479
Bug: 31537595
Bug: 64156587

Change-Id: I1afa77a4b90b9b822b409a3f4721c45d0c0a6664
2018-01-23 18:25:36 -08:00
Seigo Nonaka
783f961d2f Compute full text layout in MeasuredText and use it for drawing
The full layout is required for drawing text on UI thread.
To save this work, store the full layout result in MeasuredText and
compose the final layout from stored full layout if possible.

Currently justification/hyphenation is not supported but works normally
as before. Nothing changes on existing non measured text.

StaticLayout creation time for no style text (w/o patch -> w/ patch, N=30)
  MeasuredText Balanced Hyphenation  :    721,297 ->    720,657: (-0.1%)
  MeasuredText Balanced NoHyphenation:    550,588 ->    546,069: (-0.8%)
  MeasuredText Greedy Hyphenation    :    503,582 ->    498,009: (-1.1%)
  MeasuredText Greedy NoHyphenation  :    502,344 ->    498,507: (-0.8%)
  RandomText Balanced Hyphenation    : 19,351,802 -> 19,176,024: (-0.9%)
  RandomText Balanced NoHyphenation  :  8,033,830 ->  7,973,336: (-0.8%)
  RandomText Greedy Hyphenation      :  7,957,335 ->  7,927,316: (-0.4%)
  RandomText Greedy NoHyphenation    :  7,988,884 ->  7,929,717: (-0.7%)

StaticLayout.draw time for no style text (w/o patch -> w/ patch, N=30)
  MeasuredText NoStyled              :    644,453 ->    660,684: (+2.5%)
  MeasuredText NoStyled WithoutCache :  9,251,919 ->    648,992: (-93.0%)
  MeasuredText Styled                :  3,092,353 ->    870,702: (-71.8%)
  MeasuredText Styled WithoutCache   : 12,544,014 ->  1,114,557: (-91.1%)
  RandomText NoStyled                :    582,167 ->    572,092: (-1.7%)
  RandomText NoStyled WithoutCache   :  9,167,670 ->  9,056,447: (-1.2%)
  RandomText Styled                  :  3,064,490 ->  3,029,028: (-1.2%)
  RandomText Styled WithoutCache     : 12,314,863 -> 12,283,026: (-0.3%)

Test: minikin_test
Test: bit CtsTextTestCases:*
Test: bit CtsWidgetTestCases:android.widget.cts.TextViewTest
Test: bit FrameworksCoreTests:android.text.MeasuredParagraphTest
Bug: 63897135

Change-Id: I7e6ec5c953d7d0f767aba4f61f94e62b6f3a3a2b
2018-01-23 17:45:55 -08:00
Leon Scroggins III
e5de9aa4a9 Unhide ImageDecoder
ImageDecoder is a new way to decode Bitmaps (or Drawables) that
streamlines common use cases of BitmapFactory.

Bug: 63909536
Bug: 63908092
Test: I0f36ce34c968fd7fae4d8edebabea3a421859615
      Ib2877276da8464b5f3eef0bbb848de202c90e97e
      I8d1672180d8325ae1caf44f0bbf41036b94e6253
      I405ebc86f7b6b019e0f040f1d4afe2e9d4354e5d
      Iaeb7c27bafb351932f0fabe59461ef50b1e2424a

Change-Id: Iee236ac73e0bc37ef6903a8150c0d2c84e5cf906
2018-01-22 21:41:28 -05:00
Leon Scroggins
cbb60724cf Merge "Use ImageDecoder for BitmapDrawable" 2018-01-19 22:10:53 +00:00
John Reck
1954cf52fa Limit ripple alpha to 50%
Many themes appear to have forgotten to set
the alphas value on the color state list they
pass to RippleDrawable. The previous implementation
always divided the alpha by 2 which resulted in
the accidentally opaque color being 50% opacity instead.

To match that behavior without adding back the
unusual divide by 2 we simply cap the alpha to 128.

Similarly we surpress the hover & focus events if
a press is already in progress, which prevents a funky
background flicker on views with FOCUSABLE_AUTO that
gain focus part way through a click event.

Also fixes a bug where rapid tapping resulted in the
hardware animation appearing to not play as it had
a start value of 0 instead of paint.getAlpha()
Software animation already has this correct behavior,
so no changes needed for the fallback path.

Bug: 72173993
Test: tested hangouts, pin entry
Change-Id: I7110779234422e82cdd5d737aa00c1280b13760c
2018-01-19 13:51:24 -08:00
Derek Sollenberger
66c6d78908 Use ImageDecoder for BitmapDrawable
If required due to density mismatches the ImageDecoder will not
upscale the image at decode time, but instead will decode at the
bitmaps default size and upscale at draw time.  This can be a
significant memory savings for low-dpi assets being used on a high-dpi
device.

However, if the provided asset has a higher dpi level than the bitmaps
default density then we will match BitmapFactories behavior and downscale
the bitmap to match the default density.

Bug: 63909536
Test: CtsGraphicsTestCases
Change-Id: I189306b7a3b706bed32bb267970ade27a57c0e7f
2018-01-19 15:10:05 -05:00
TreeHugger Robot
244c6a65e9 Merge "Treat missing font in fallback chain" 2018-01-19 01:03:55 +00:00
Seigo Nonaka
545faa4c4c Treat missing font in fallback chain
Bug: 72159040
Test: bit FrameworksCoreTests:android.graphics.TypefaceSystemFallbackTest
Change-Id: I481a51811d228b87c9eb07b536a95cb699f1669c
2018-01-18 11:06:34 -08:00
Leon Scroggins III
671cce2605 Make ImageDecoder return animated Drawables
Bug: 63909536
Bug: 63908092
Test: TODO

If ImageDecoder.decodeDrawable is called with an animated image Source
(currently GIF or WebP), return an object of a new (hidden) Drawable
subclass. The new Drawable animates, and it implements Animatable (TODO:
implement Animatable2) so users have some control over the animation.

In addition to the normal features of Drawable, this new one supports
many of the features of ImageDecoder, including scaling, cropping and
PostProcess, which enables circle masks/rounded corners and other
arbitrary after-effects. It does *not* support decoding directly to a
Hardware Bitmap, since it cycles through frames and reuses the same
bitmap memory. But it could be made to use shared memory (TODO?).

TODO: Use a better number for the native allocation registry
TODO: Use the RenderThread to drive the animation, and remove decoding
on the UI thread.
TODO: Add support for modifying the loop count

Android.bp:
- build new AnimatedImageDrawable.cpp

AndroidRuntime.cpp:
- register new native methods

AnimatedImageDrawable.java
AnimatedImageDrawable.cpp:
- new Drawable that handles animated images

Canvas.h, SkiaCanvas.h/.cpp
- New virtual method and implementation for drawing SkAnimatedImages

RecordingCanvas.h/.cpp
- Stub implementation of drawing SkAnimatedImages

ImageDecoder.h/cpp
- Allow code sharing with AnimatedImageDrawable.cpp
  - postProcess
  - access the ImageDecoder struct

Depends on https://skia-review.googlesource.com/c/skia/+/94660 in Skia.

Change-Id: Ie2ec98d9c52deda4d439c6ef8e5dea2861bb93a3
2018-01-17 17:06:57 -05:00
Leon Scroggins III
8c9d8f2aec Ensure that PostProcess Canvas is released
Bug: 63909536
Bug: 63908092
Test: CtsGraphicsTestCases (ImageDecoderTest)

Refactor a method for calling postProcess from ImageDecoder. This will
be shared with the animated drawable (TODO). Call
PostProcess.postProcess in Java inside a try block to ensure that the
Canvas is released. Otherwise, a client could hold on to a pointer to
Canvas and keep using it, even though we have removed its backing.

In addition, share code for calling nDecodeBitmap.

Change-Id: I81ce2befce91ac1e27c78ad059c4b173a2c7e679
2018-01-17 17:04:17 -05:00
TreeHugger Robot
2ae7857ee5 Merge "Report more specific error if codec creation fails" 2018-01-17 20:53:40 +00:00
Leon Scroggins III
c782ad886f Report more specific error if codec creation fails
Bug: 71578461
Test: CtsGraphicsTestCases

Switch to SkCodec::MakeFromStream, and use its error code to determine
the Exception/error message. Then pass that to
SkAndroidCodec::MakeFromCodec. This is essentially what happened
previously (minus error reporting).

Change-Id: Iabaa61a4321d2f2e257db587013afda605b005b0
2018-01-17 14:33:23 +00:00
John Reck
66792c4833 Merge "Update ripple alphas" 2018-01-16 17:54:12 +00:00
John Reck
2d0735fe91 Update ripple alphas
Bug: 63635160
Test: clicked, hovered, and focused stuff
Change-Id: Ic3ba65b467706969c904d7fe313bd3d659dcc4af
2018-01-10 16:12:19 -08:00
TreeHugger Robot
4f63341d73 Merge "Rename onException to onPartialImage" 2018-01-10 22:39:28 +00:00
TreeHugger Robot
2f28dd71ec Merge "Add ImageDecoder.ImageInfo.getMimeType" 2018-01-10 14:38:32 +00:00
TreeHugger Robot
7fe2a370bc Merge "Additions and cleanups for ImageDecoder API" 2018-01-10 12:53:04 +00:00
TreeHugger Robot
a13c47694f Merge "Fix small but crashy edge case in Icon.scaleDown" 2018-01-10 00:09:16 +00:00
Leon Scroggins III
edf26d6e40 Rename onException to onPartialImage
Bug: 63909536
Test: CTS: I8d1672180d8325ae1caf44f0bbf41036b94e6253

In ImageDecoder. The goal is to tell the client that there is a partial
image (which they can use if the callback returns true) and also allow
them to know why the image is partial.

Change how the return value is handled. Instead of returning null, which
is inconsistent with the rest of ImageDecoder, throw the Exception.

Change-Id: I56c38a624c978aa6e6d00fc927b5e355bf9c718a
2018-01-09 16:55:24 -05:00
Leon Scroggins III
1fad09d4d3 Add ImageDecoder.ImageInfo.getMimeType
Bug: 63909536
Test: CTS: Ib2877276da8464b5f3eef0bbb848de202c90e97e

Allows a listener to determine the mimetype.

Change-Id: I0d2aa32f2dbfb37dba97a896037c48814390273d
2018-01-09 16:54:22 -05:00
Leon Scroggins III
b1cc8e6437 Additions and cleanups for ImageDecoder API
Bug: 63909536
Test: CTS: I0f36ce34c968fd7fae4d8edebabea3a421859615

Add overloads for null listener, byte[] without offset + length
Clean up comments

Change-Id: I3dd1dae94cf1fe977d96fcae9b36cbed0adfe749
2018-01-09 15:52:49 -05:00
Leon Scroggins
5dfd8194b2 Merge "Support using ImageDecoder with ContentResolver + URI" 2018-01-08 21:14:50 +00:00
Leon Scroggins III
ed074fd700 Support using ImageDecoder with ContentResolver + URI
Bug: 63909536
Test: CTS: I0f36ce34c968fd7fae4d8edebabea3a421859615

Add ImageDecoder.createSource(ContentResolver, URI), allowing a client
to decode images from files, content, resources, etc.

Prefer using a file descriptor to using an InputStream so the input can
be cheaply seeked and rewound if necessary.

Make ImageDecoder implement AutoCloseable to handle closing the input.

Make decodeDrawable/decodeBitmap always return an object or throw an
IOException. Avoid checking for a file in the Source constructor.

Fix a bug where inner Exception classes were not static.

Update JavaInputStreamAdaptor to be usable by ImageDecoder:
- previously it always swallowed exceptions. Allow them to propagate
  (optionally) so that they can be reported back to the client.
- Add refs to the InputStream and byte[]. ImageDecoder returns from
  native and then uses the JavaInputStreamAdaptor again, making the
  local refs go out of scope.
- Hold on to the JavaVM and convert to the JNIEnv when necessary. Pass
  local env pointers to avoid looking it up multiple times in one call.
- If an exception is thrown inside the doRead() loop, return the number
  of bytes successfully read.

Change-Id: I869dad55521cf942efd010c06baf3f44c1c08374
2018-01-08 12:41:39 -05:00
Robin Lee
76dc52ac36 Fix small but crashy edge case in Icon.scaleDown
Plus a regression test which throws an Exception for the old version. It
shouldn't be an issue in the real world because there's absolutely no
reason any app should be creating 1920*3px icons.

Found while porting the code somewhere else.

Test: runtest -x ./core/tests/coretests/src/android/graphics/drawable/IconTest.java
Change-Id: I1283d982507221914ddad1313e16f63af13e245a
2018-01-04 16:55:24 +00:00
Mihai Popa
e72b5c5163 Update the ttc index attribute documentation
The CL updates the documentation of the ttcIndex attribute added for P,
according to the API review comments.

Bug: 71555180
Test: none
Change-Id: I44a617c4f0a10314008fe5d5b380c6a830f3e04f
2018-01-04 14:36:39 +00:00
Leon Scroggins III
0c01dbf8f2 ImageDecoder (BitmapFactory 2.0)
Bug: 63909536
Bug: 63908092

Test: CTS: I0f36ce34c968fd7fae4d8edebabea3a421859615

One-pager:
https://docs.google.com/document/d/1IWSdXb5O9lu-Zbj7SaNWo5pS7-FHlonFnqazjnecozM/
Design doc:
https://docs.google.com/document/d/15S6DSAV4EwOuJLv29UC_9cdSGdPg3KvOJVn2EHoP3fw/

ImageDecoder is designed to streamline certain patterns of BitmapFactory
use:
- choosing sample size based on actual dimensions
- choosing a specific output size
- post-processing (e.g. for rounded corners)
- copying to HARDWARE
- decode directly to ashmem
- creating a Drawable
- use as an alpha mask
- save RAM (e.g. use RGB_565)

In addition, it will include new features:
- animated drawables (TODO)
- report failures *and* optionally create a partial image
- crop

Add PostProcess to handle post-processing. It is separate from
ImageDecoder so that it may be used in the future by other commands that
might want something similar (e.g. capturing a View).

Consolidate NinePatch code for sharing between BitmapFactory and
ImageDecoder.

Some features left out of this CL:
- Create from ContentResolver + URI
- animation
- report more info in ImageInfo
- more overloads (e.g. null OnHeaderDecodedListener)

Change-Id: Icf011dc1b97b492788e47cf51fcf8abe8e9c7b88
2017-12-19 20:22:17 +00:00
Jorim Jaggi
45be1c4cdc Add surface/shown position to proto output
Change-Id: I4fb16a520af182c8f77982646f6ac9ae82fd9173
2017-12-15 18:44:43 +01:00
John Reck
7bb9f374c0 Tweak ripples
* Fixes the ripple interpolator to match UX spec
* Adjusts behavior if the ripple is re-sized mid-ripple
  to look less bad

Bug: 63635160
Test: mashed a bunch of buttons

Change-Id: I26de59fe81372512b287a646ca7377d052227aee
2017-12-12 11:29:02 -08:00
Doris Liu
6b184d7a43 Private API to turn off anti-aliasing for VectorDrawable
Bug: 69322344
Test: visual inspection on VectorDrawableTest with AA off. Jagged edges
      that are otherwise smooth were spotted.

Change-Id: Ib2dfbd3a941be0b4ff92b8458346f8c8f5015a4b
2017-12-04 16:31:07 -08:00
John Reck
0c453ccb87 Make ripples silky smooth
* Updates press state ripple to match UX spec
* Makes it ungodly silky smooth LIKE BUTTAH
* Update hover & focus states to be closer to UX spec,
  still needs a final pass.

Bug: 63635160
Test: Clicked on a bunch of stuff

Change-Id: I162ab9d8d669002f2ae511f93b5d9fe67f99c533
2017-11-16 16:32:43 -08:00
Xin Li
220871a697 Merge commit '98e12851336b7db16e583f9afac63ecc97465980' from
oc-mr1-dev-plus-aosp-without-vendor into stage-aosp-master.

Change-Id: Ia7b8da4a00d215160e4a4fa40f6044208d1297b7
Merged-In: I19846d2a3ee27aecbae2367a74ee49082eea154d
2017-11-14 12:31:11 -08:00