Commit Graph

3457 Commits

Author SHA1 Message Date
Leon Scroggins III
4534745f53 Fix rounding of padding in NinePatchDrawable
Bug: 73088142
Test: Test app at https://buganizer.corp.google.com/issues/73088142#comment6
Test: GridWidgetTest.testItemDecorationAndMarginsAndOpticalBounds

In computeBitmapSize, treat padding as a size in scaleFromDensity. This
results in rounding instead of truncating. This matches the way optical
insets are handled. It also matches the padding we would have gotten if
we had scaled at decode time.

Change-Id: I7d3a83ba824b8dc81187ce9b2d9889d4a87f88ac
2018-04-13 13:12:49 -04:00
Seigo Nonaka
1cf0b6cbfd Merge "Add common weight name to the API description" into pi-dev 2018-04-09 16:46:26 +00:00
Seigo Nonaka
f2944cd61b Add common weight name to the API description
Bug: 76448718
Test: m docs
Change-Id: Id0ce0b2bcbf4f6b0cf1aa97c4d2c3c5117dc62c2
2018-04-09 14:29:41 +00:00
TreeHugger Robot
9cb6759072 Merge "Never scale nine-patches in ImageDecoder" into pi-dev 2018-04-05 22:42:39 +00:00
TreeHugger Robot
d2c218f78a Merge "Rename set/get-ConserveMemory" into pi-dev 2018-04-05 20:44:58 +00:00
Leon Scroggins III
7d940ba43d Never scale nine-patches in ImageDecoder
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
2018-04-05 12:50:32 -04:00
Leon Scroggins
d9cb59629d Merge "Add docs for setTargetSize and setTargetSampleSize" into pi-dev 2018-04-05 13:29:38 +00:00
Leon Scroggins III
ac959199e5 Rename set/get-ConserveMemory
Bug: 76448408
Test: Ie83dbdeab5cc3dcd6bd56dd874412ed67eb52c02
Change-Id: I714b159bb70a48e5644801cc7fef8e32ee93896a
2018-04-04 19:58:30 -04:00
Leon Scroggins III
d97e26428d Add docs for setTargetSize and setTargetSampleSize
Bug: 77507530
Test: No change in behavior, no new tests

Add @Px and @IntRange annotations, and be explicit that setTargetSize
refers to pixels. Add a comment to setTargetSampleSize that is like
calling setTargetSize with particular values, to try to make it clear
how the two are related.

Change-Id: Ie7e9429bc8c548f44d382358c161425f666ba82f
2018-04-03 11:59:29 -04:00
Leon Scroggins
8880a9e0b9 Merge "Update javadocs for ImageDecoder and related" into pi-dev 2018-04-03 14:43:01 +00:00
TreeHugger Robot
ffe1c2a266 Merge "Restore saveLayer APIs back into the public API." into pi-dev 2018-04-02 14:28:48 +00:00
Leon Scroggins III
d84c652a4e Update javadocs for ImageDecoder and related
Bug: 76461699
Bug: 76448408
Test: No change in behavior, no new tests

Add class level docs for ImageDecoder, including sample code. Update
wording to be more clear and less wordy. Fix broken attempts at using
sample code.

Incorporate advice at go/android-api-guidelines and
https://developers.google.com/style/api-reference-comments

Change-Id: Iaf1334993f6cd2d3f6e53d3fb70ef9c7a95c9a76
2018-03-30 20:13:39 -04:00
Leon Scroggins III
d9b53a097d Remove chaining from ImageDecoder setters
Bug: 76448408
Test: Infeasible
Change-Id: Ib0ef0a9a9b0f36481ed1bbb16ecaccd180df8915
2018-03-30 15:02:56 -04:00
Derek Sollenberger
2d4f01ba7f Restore saveLayer APIs back into the public API.
The saveLayer APIs are restored from @removed but will treat input
as ALL_SAVE_FLAGS and generate exceptions on newer API levels.

We internally used these calls in one situation that now use a
different @hide API to support the previous behavior until we
refactor that code.

Partial revert of "Remove deprecated android.graphics.Canvas APIs"
This reverts commit 7b837616ae.

Bug: 77276963
Bug: 73777445
Test: CtsGraphicsTestCases
Change-Id: I7acd4ffd5ac41a58d2be8b48cf50119c2b896708
2018-03-30 14:40:04 -04:00
Leon Scroggins
3c4e33a4fe Merge changes from topics "DocumentSource", "ID_API" into pi-dev
* changes:
  Add documentation for ImageDecoder and its Source
  Rename getters and setters on ImageDecoder
2018-03-30 00:53:53 +00:00
Leon Scroggins III
0a87cb3128 Add documentation for ImageDecoder and its Source
Bug: 76448408
Bug: 76462125
Test: Iec21bad971dc9cffc807a412bb6329757c499baa

- Document DecodeException.getSource
- Add thread annotations
- slice() ByteBuffer inside createImageDecoder, so it can be reused
- Make ResourceSource thread safe by locking around mResDensity
- Specify that OnHeaderDecodedListener is necessary for changing default
  settings

Change-Id: I3b55d3ba1b0a2276938cb521449bceb7aa9f96e2
2018-03-29 18:47:52 -04:00
Leon Scroggins
bf1fe9aecd Merge "Add in/out ColorSpace to ImageDecoder" into pi-dev 2018-03-29 20:27:43 +00:00
Leon Scroggins III
d62f27250a Rename getters and setters on ImageDecoder
Bug: 76448408
Test: Ib8782ff10072c81a5ed2a1031a70475fffee7ccf

- Use "is" prefix for booleans instead of "get"
- Reverse "require" and "unpremultiplied" for a more natural sound
- Add "Required" to "Mutable" methods
- Add "Enabled" to "DecodeAsAlphaMask" methods

Change-Id: I644ddccd37898d89609e4534ece4ea70f74587c4
2018-03-29 15:35:30 -04:00
Leon Scroggins III
1a69f4598f Add in/out ColorSpace to ImageDecoder
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
2018-03-29 13:44:22 -04:00
John Reck
9434b66bf7 Merge "Move Path to NAR" into pi-dev 2018-03-29 16:53:41 +00:00
John Reck
205d83e108 Move Path to NAR
Bug: 74686528
Test: PathTest#testUseAfterFinalize
Change-Id: Ic1c9df6f1b63ea5795a6c3a54b8fc50fdaf0a5f4
2018-03-28 14:36:58 -07:00
Leon Scroggins III
64481195e1 Rename ImageDecoder.setResize
Bug: 76448408
Bug: 73537624
Test: Ib40d65c68a6c709b6456f2145ad8a5557a941494

setResize is two verbs, and "resize" implies we're changing the size of
an existing object. In truth, the method specifies the desired size. So
rename setResize(int, int) to setTargetSize, which clearly specifies the
behavior.

Rename setResize(int sampleSize) to setSampleSize.

Hide getSampledSize, which looks too similar to the newly named
setSampleSize. In addition, b/76448408 suggests hiding it. It isn't
really necessary anyway, since a client can just call setSampleSize - no
need to query and call setTargetSize manually.

Since there is no way for a client to know that a RAW image couldn't be
decoded to the desired size (could previously be done with
getSampledSize), make setSampleSize do the extra scaling. This is a
better API anyway.

Change-Id: I84c29fdc6bdfb999a7f712fdc069304ae9676ba6
2018-03-28 11:24:12 -04:00
Jesse Hall
bef42cd87f Merge "Docs: add more detail to SurfaceTexture#getTimestamp" into pi-dev 2018-03-27 18:54:28 +00:00
Jesse Hall
b5afc250bc Docs: add more detail to SurfaceTexture#getTimestamp
Copies language from <android/surface_texture.h> that connects
EGL/Vulkan presentation timestamps to SurfaceTexture#getTimestamp.

In the process, reorganized the existing language to talk about
general properties of the timestamp, and then talk about behavior of
specific producers instead of mixing them together.

Bug: 72755997
Test: make docs
Change-Id: I88253f9e23df7d7c4fe3c1c51ff2ac494da1913c
(cherry picked from commit 63d2a0e000)
2018-03-27 17:08:04 +00:00
Derek Sollenberger
7b837616ae Remove deprecated android.graphics.Canvas APIs
Bug: 73777445
Test: compile
Change-Id: Ie68f2fbe3c3be82f3c20529d535875d4cc204b7c
2018-03-27 14:36:50 +00:00
TreeHugger Robot
6f5e83df3a Merge "Update AnimatedImageDrawable docs" into pi-dev 2018-03-27 12:47:22 +00:00
Leon Scroggins III
53f09ee1f1 Update AnimatedImageDrawable docs
Bug: 73529437
Test: No change in behavior, no new tests

Document that it can be inflated from xml, and reference the attributes
that it supports.

Add a comment describing what the class does with respect to animation.

Update the comment for start() to better reflect when the callback is
called.

Change-Id: I660cbc4e185dca8bc7a43a185f91ae0485ef8753
2018-03-26 10:44:47 -04:00
John Reck
29c8b5458a Add missing computeOpacity call
Change-Id: I3b668842d4cd072a0625c32cae0a1ade0e322a7d
Fixes: 73285195
Test: GradientDrawableTest#testGetOpacity
2018-03-23 15:38:18 -07:00
TreeHugger Robot
dfdc379144 Merge "detect api version, and start respecting offsets" into pi-dev 2018-03-23 11:25:19 +00:00
Leon Scroggins
ceb14e015b Merge changes from topics "DecodeException_ERROR", "AID_autoStart", "onPartialImage" into pi-dev
* changes:
  Rename ImageDecoder.ERRORs
  Add the ability to autoStart AID from xml
  Re-write onPartialImage API
2018-03-22 21:53:05 +00:00
TreeHugger Robot
e7c26531c0 Merge "Disable Bitmap density scaling to Picture" into pi-dev 2018-03-22 21:34:32 +00:00
Leon Scroggins III
cf7294fda6 Rename ImageDecoder.ERRORs
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
2018-03-22 13:09:02 -04:00
Leon Scroggins III
5388f79a45 Disable Bitmap density scaling to Picture
Bug: 76144110
Test: I95165583649a1df86782d3684f7bf9bcd8dab7bd

This matches the behavior of DisplayListCanvas. Not scaling means that
we can draw a Bitmap to a Picture, and then play that back in HW mode
and see the same result.

Change-Id: I7421431bad0531112e06ab5c14814b6b6f1591d9
2018-03-22 12:36:22 -04:00
Leon Scroggins III
1dd88daf92 Add the ability to autoStart AID from xml
Bug: 73529437
Test: Ic818bbf1091d12631aedd6475d225fa4a708b29c
Change-Id: I4807409895a057e775bfee5dea407e8dc1af94be
2018-03-22 09:05:42 -04:00
Mike Reed
322bc57a33 detect api version, and start respecting offsets
Test: make

Bug: 36471624
Change-Id: Ica10c557bf35e8d707fabbafab49d22109916fd3
2018-03-21 17:39:01 +00:00
Leon Scroggins III
1d2bf2b846 Re-write onPartialImage API
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
2018-03-21 12:55:46 -04:00
Leon Scroggins
d848f75f99 Merge "Report native allocation size of AnimatedImageDrawable" into pi-dev 2018-03-21 16:48:19 +00:00
Leon Scroggins III
eb3b38e22c Report native allocation size of AnimatedImageDrawable
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.
2018-03-21 09:28:00 -04:00
Leon Scroggins
83ad4e53b6 Merge "Scale up in ImageDecoder based on API level" into pi-dev 2018-03-20 16:44:44 +00:00
Leon Scroggins
51d2cc45d8 Merge "Add an asset source for ImageDecoder" into pi-dev 2018-03-20 14:33:43 +00:00
Leon Scroggins III
8290eaba47 Scale up in ImageDecoder based on API level
Bug: 74061412
Bug: 73893665
Test: Manual, I5669a97c70d726826c5c00bc1413c2f97d95d88c

ImageDecoder typically does not scale a Bitmap up to handle density.
This saves memory, and we already handle the density by scaling at
draw time. But some apps rely on the size of the Bitmap without taking
density into account. For backwards compatibility, on apps that are
built for a pre-P version of Android, scale up in ImageDecoder.

Change-Id: I9991d1286e386b47fc57bcfbf0c6652beb1a53ef
2018-03-20 10:30:32 -04:00
TreeHugger Robot
c45c2d65a5 Merge "Work around incorrect Skia gamma" into pi-dev 2018-03-19 22:10:31 +00:00
Leon Scroggins III
121ef98bfb Add an asset source for ImageDecoder
Bug: 74545298
Test: I6a633553bbb5ff26d84aaf5371b8b43a770afd4f

This allows using ImageDecoder to decode a file in the "assets"
directory of an app.

Change-Id: I2193f052cc2e16c55c7f68f7e51e07cd24ee4df9
2018-03-19 13:01:57 -04:00
Leon Scroggins III
1eccac89c1 Add ImageDecoder.Source for resources
Bug: 74545298
Test: Ibc283c2e8aee999e951de51f3a43b581a765aaf5

Although resources can already be accessed with ContentResolver + URI,
this allows a simple method to do the same.

Change-Id: I1bf698f36d5540f6de7cb9957e4223123d0f4331
2018-03-19 13:01:52 -04:00
Seigo Nonaka
83143d005b Remove mtOffset from drawTextRun
Bug: 72998298
Test: atest CtsWidgetTestCases:EditTextTest
    CtsWidgetTestCases:TextViewFadingEdgeTest
    FrameworksCoreTests:TextViewFallbackLineSpacingTest
    FrameworksCoreTests:TextViewTest FrameworksCoreTests:TypefaceTest
    CtsGraphicsTestCases:TypefaceTest CtsWidgetTestCases:TextViewTest
    CtsTextTestCases FrameworksCoreTests:android.text
    CtsWidgetTestCases:TextViewPrecomputedTextTest

Change-Id: Ia886c1ce9f7387559d7fe00b34ce03378d56ecec
2018-03-15 04:09:19 +00:00
TreeHugger Robot
13cd2c9227 Merge "Document the byte packing order of the current Bitmap.Configs" into pi-dev 2018-03-14 20:23:29 +00:00
Derek Sollenberger
186ea1218e Document the byte packing order of the current Bitmap.Configs
This CL documents the byte order for 585, 8888, and fp16 buffers.

Test: documenting existing behavior
Bug: 71518511
Change-Id: I128344db318eb4597b6eb00f0ae317e369145152
2018-03-14 13:29:22 -04:00
TreeHugger Robot
1b8333d1fb Merge "Unhide getWeight of Typeface" into pi-dev 2018-03-13 22:24:41 +00:00
Leon Scroggins III
ce89a6e656 Work around incorrect Skia gamma
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
2018-03-13 15:39:39 -04:00
Seigo Nonaka
59897ec4ab Revive old private api for saving supportlib-v27
The method signature of the createFromFamiliesWithDefault is changed
for supporting multiple font fallback. The old method is used by
supportlib-v27.

Bug: 73981003
Test: Manually done
Change-Id: I45ee9975b0f15481b60362113b89d4a1bf5a5338
2018-03-13 11:45:43 -07:00