Bug: 78866720
Test: Manual + systrace; existing CTS
Previously, we set hasAnimations to true when the AnimatedImageDrawable,
so that we would get a call to redraw. But if the image does not need to
show its next frame yet, the redraw was unnecessary.
Instead, add a new field to TreeInfo::Out, representing the delay time
until the image will need to be redrawn - i.e. when the duration of the
current frame has passed. Each call to prepareTree will post at most one
message to redraw, in time for the earliest animated image to be
redrawn. Post the message for one rendered frame ahead of time, so that
when it is time to show the next frame, the image has already gotten the
message to update.
On a screen with a single animated image, this drops the number of calls
to dispatchFrameCallbacks to as infrequent as possible. It is called
only when we need to draw a new frame of the image. On a screen with
multiple animated images, the calls may be redundant, but they will not
be more frequent than they would be without this change.
Switch to nsecs_t and systemTime internally, matching the rest of HWUI.
Remove mDidDraw and related. Its purpose was to prevent advancing the
animation while the image is not being drawn. But it isn't really
necessary. If it's not drawn, onDraw is not called, which is where we
trigger decoding. And onDraw already has a defense against getting too
far ahead - if its timer indicates that it should skip a frame or show
it very briefly, it will back up its timer. More importantly, mDidDraw
caused a bug, when combined with less frequent redraws. If the display
list containing the drawable doesn't need to be redrawn for other
reasons, the drawable's timer never advanced, so its animation stopped.
Fix software drawing. Compute the milliseconds in the future to draw the
next frame, and add that to SystemClock.uptimeMillis() to compute the
time to pass to scheduleSelf.
Change-Id: I13aab49922fa300f73b327be25561d7120c09ec4
Bug: 78866720
Test: Manual
If the input stream is seekable, SkGifCodec will read from it directly.
If not, it has to copy (parts of) the input in order re-decode when it
loops. Directly use the seekable SkFILEStream so that SkGifCodec skips
the copy, saving memory proportional to the size of the file.
Depends on a change in upstream Skia which allows SkFILEStream to treat
the initial offset as the beginning of the file:
https://skia-review.googlesource.com/c/skia/+/126511
Change-Id: Iefb58785157ba684ad3603778175b3dba97567b2
Bug: 78866720
Test: Manual
It already supports rewinding, and the underlying Asset supports
seeking. Allow it to be seeked so that SkGifCodec can read directly from
it rather than copying data it needs for internal use.
Change-Id: I0765dcf4a507724878a5a700a770d35802c4b7be
Bug: 76448902
Bug: 70889348
Test: Manual + CtsThemeHostTestCases
(Ica5e7e81848c3880accee922ee6f1cc9e26262ca)
Scaling a nine-patch requires scaling its divs. When the scale factor is
not an integer, we have to round. This gets out of sync with the way the
decoder scaled the image, resulting in stretching or keeping fixed the
wrong portions of the image. Making this worse, when we scale down, we
end up with divs colliding with each other, and we have to arbitrarily
adjust them further so they do not collide.
NinePatchDrawable and the drawing code already know how to handle
drawing from the originally-sized image and do a better job stretching
appropriately, so allow them to do their job.
We already do something similar for Bitmaps created by ImageDecoder on
apps targeting P and above - instead of scaling them up, we allow the
BitmapDrawable's scaling code to handle density differences. We
preserved the old behavior (scale up) on apps targeting pre-P because
those apps may rely on the size of the Bitmap contained in a
BitmapDrawable without accounting for its density (see Bug: 74061412).
But that is not an issue for NinePatchDrawables, which do not allow
peeking at their internal Bitmaps.
Rewrite ImageDecoder.computeDensity. There is no need for it to be
static, since it takes an ImageDecoder as a parameter and reads its
fields, including the new field mIsNinePatch. Set mIsNinePatch in the
constructor to avoid another down call into native. Split up the
conditions that result in returning srcDensity without calling
setTargetSize for clarity.
Remove ImageDecoder constructor from the graylist. It was accidentally
added due to the fact that it is called transitively from public APIs.
Change-Id: I3c5ddd67f3352c991515f30ce1c477c9a608833f
Bug: 76448408
Test: I851173b771668f0e6712bebfe06bfb8559801199
Add ImageInfo.getColorSpace() for retrieving the default ColorSpace.
This matches BitmapFactory.Options.outColorSpace.
Add ImageDecoder.setTargetColorSpace() for choosing a new ColorSpace.
This matches BitmapFactory.Options.inPreferredColorSpace.
Rename setSampleSize to setTargetSampleSize to match setTargetSize and
setTargetColorSpace.
Change-Id: If2f4e755dfc163f754849f896de24659198973db
Bug: 73788969
Test: I501e8b76aacd785cb994165ab01dc1b39fea3a1c
Move them into ImageDecoder.DecodeException, which is where they are
actually used. This also provides some more context, so that the prefix
"ERROR_" is no longer necessary, fixing the redundancy/awkwardness in
ERROR_SOURCE_ERROR. Further rename that to SOURCE_MALFORMED_DATA, which
is more descriptive, and does not imply a Java Error.
Change-Id: Ied17ad343650f9c33d9a35b0f9d00ccc22264bd6
Bug: 73788969
Test: If9e27a6ce2604128a619bc4843d62711f94b4d87
Add a new Exception subclass that contains information about the type of
error, and the original Exception, if any. Remove the old
IncompleteException class. If the decode creates a partial image, pass
the information up to Java, where we create the new Exception and pass
it to the callback and/or throw it. Rewrite nDecodeBitmap to always take
the ImageDecoder as a parameter for this callback, and simply use a
boolean to determine whether to call onPostProcess
Check for exceptions in some overlooked cases in native code, and
route to the new type.
Remove FIXME to avoid parsing the whole image. In my limited testing,
it didn't seem to speed anything up, and this should be called in a
background thread anyway. Parsing now also ensures that we've read the
stream when we can have a chance to handle the exception from the right
place.
Remove fixme for b/70626068, which has been marked as WontFix.
Add a TestApi for testing an Exception thrown by an InputStream.
Remove onPartialImage from hiddenapi-light-greylist.txt to fix the build
error this change introduces. onPartialImage was erroneously added to
the list.
Change-Id: I12f69857328e63c993bd669412b06addeb6a74f1
Bug: 73641604
Test: infeasible
Fix nNativeByteSize's return value to be jlong, instead of long.
Add up the bytes used by the SkAnimatedImage and SkPictures and store
them on the AnimatedImageDrawable for registration.
Note that this is an approximation, and it assumes it will be drawn to a
hardware canvas and animated.
Bug: 74408046
Test: Ic6acdc4a1a16840ec6ad9b13b4926c643d0f81ae
Skia incorrectly sets the gamma for LINEAR_EXTENDED_SRGB to 0 as a
misguided optimization attempt. As a result, a HARDWARE Bitmap which
natively has this color space does not match it properly. (Note that we
already catch an F16 Bitmap, above.) Add a workaround in
Bitmap.getColorSpace() to check for the color space explicitly.
Change-Id: Id595e365d1c8d572cfcea214d230a8ce1decdc01
Bug: 70846442
Test: I5110881203c000474116a94a48f2afc9a9b62001
Delay computing decodeColorType until right before we may change it (and
delay reinterpreting the pointer along with it). More interestingly,
defer computing decodeColorSpace until *after* we may have changed the
decodeColorType. Along with a change in Skia, this allows us to match
the color type of inBitmap, as intended.
Change-Id: If0ca4a61d338a13473a96faf900c84010ae46d41
Bug: 73743812
Bug: 71430152
Test: If2c3ee0f32eff77b11ce5a7fe82c02811ed1beb3
This matches how we handle decoding images with a wide gamut. For WebP
and JPEG, we cannot encode with more precision anyway. For PNG, we could
in theory encode to 16 bit linear PNGs. This would be more precise, but
would still throw away information due to normalization. Using 8-bit P3
matches the behavior for the other formats, so it is nice to be
consistent.
Change-Id: I69a44a3eff70e26448a75ecc63ed7604b9c74a95
Bug: 73529437
Test: I27af7c3b2e08fa50bc19e08930d970931ce4b5e9
If isAutoMirrored, and the layout direction is RTL, make
AnimatedImageDrawable draw flipped.
Change-Id: I9a3436ef4cb9df2845a67663a2503c2c1a3dba89
Bug: 73529437
Test: I60fbee6d3610070413e8c46f363ec3c19c2e7c52
Allow setting AnimatedImageDrawable's loop count in xml. Use
"repeatCount" to match the existing attr used by other objects, and
change the Java api from "loop" to "repeat".
Cache the repeat count in the State object for the situation where we
inflate but are waiting on a theme, so that when we get a src we can
apply the existing repeat count.
Change-Id: Ie723fe9a40c64dd0e1e8fd7b5d5cf81e5c5ccd0d
Bug: 70969260
Test: Existing CTS tests
Call jpeg_destroy_compress after compression (and failure), eliminating
a memory leak.
In addition, use a custom method for handling errors. skjpeg_error_exit
was previously used, but that method expects a skjpeg_error_mgr, which
isn't used here. skjpeg_error_mgr is more complex than necessary; it
allows for multiple methods to set their own jmp_bufs, even if they call
each other. The entire compression here is contained in one method. The
code for handling this single jmp_buf is simple, so no need to share
code.
This is a follow-on to If9a33ed10ea60131906a632a7030e0b69a21f4ea, which
removed skjpeg_error_mgr, but incorrectly left the skjpeg_error_exit.
Change-Id: Ib76e07ae0d29b093d3709f60e427b18e0e32bd9d
checkInternalFormat() was not properly checking that the Skia bitmap
color type matches the OpenGL format and type combination. In some
cases this would lead to visual artifacts (e.g. when a 565 type is
uploaded to a 4444 type), while in other cases it would cause reading
out of bounds (e.g. when uploading Alpha_8 with a GL_RGBA format).
Note that valid Bitmap formats are documented at
https://developer.android.com/reference/android/graphics/Bitmap.Config.html
checkInternalFormat() now also matches getInternalFormat() and
getType().
Bug: 73084222
Change-Id: I47cb08657c7d03723d3318c99e0da94434d80ee6
This is 2nd attempt of I7db9e2ca4db68a16648cfb8fcf63555f501304c2
This CL changes the MeasuredText API:
- Rename MeasuredText to PrecomputedText.
- Introduce PrecomputedText.Param which holds all text layout parameters.
- Add API to get PrecomputedText.Param from TextView.
- Remove MeasuredText.Builder and add PrecomputedText.create method instead.
- Remove setRange from MeasuredText since it is not for normal use case.
(It can not be used for TextView)
Bug: 67504091
Bug: 72861572
Test: bit FrameworksCoreTests:android.text.
Test: atest CtsWidgetTestCases:EditTextTest \
CtsWidgetTestCases:TextViewFadingEdgeTest \
FrameworksCoreTests:TextViewFallbackLineSpacingTest \
FrameworksCoreTests:TextViewTest FrameworksCoreTests:TypefaceTest \
CtsGraphicsTestCases:TypefaceTest CtsWidgetTestCases:TextViewTest \
CtsTextTestCases
Change-Id: Ie73bce52c6c673cda58973ddad04627a7cf2e5e9
The last change needs more discussion and found some edge cases. Revert and make small step-by-step changes.
Bug: 73091756
This reverts commit 7fd36d19e309ea515b4048cfaabb8035ceab7baf.
Change-Id: I89ff52a70cf6a5d6c553afa20f83719e1f9eb726
This causes a regression for some characters
This reverts commit ab40df9e6979c955f89a06a358385ecec361c9d9.
Bug: 73054061
Change-Id: Icf1f9d2b89b75031aabb47507135e45a21bc5363
Bug: 63908092
Test: Manual
If the animation is running on the render thread, post a message (in
JNI) to call the listener.
Use a weak reference in the native listener so that it does not create
a cycle.
Don't add a listener if it's already in the list. Remove the native
listener when the Java listeners are all removed.
Call onAnimationEnd when the animation is stopped manually.
Change-Id: I5dc070089fb1cf399ac3316292592f614f2738f0
The supporting broken font is over engineering and it works the same as
default font fallback in most cases.
Removing fallback logic and return default fallback.
Test: bit CtsTextTestCases:*
Test: bit CtsGraphicsTestCases:*
Test: ./gradlew appcompat-v7:connectedDebugAndroidTest
Test: ./gradlew support-compat:connectedDebugAndroidTest
Bug: 65024629
Change-Id: Ib3fc0d638c6aee904cdf865082f8d5ae7d31ba48