Commit Graph

1627 Commits

Author SHA1 Message Date
Leon Scroggins III
84d069d1c9 Fix AnimatedImageDrawables using ByteBuffers
Bug: 140715166
Test: I56dc6e9865c2701746c95ea584bcc70fe4d62a6c

AnimatedImageDrawable, when created from a ByteBuffer, needs to get a
pointer to the JNI interface in order to read the ByteBuffer (or
byte[]). But the AnimatedImageThread is not attached to the JVM. Attach
it as necessary.

Change-Id: I51b69b5b70f8c5865d5e5ed065e42267fa556202
Merged-In: I51b69b5b70f8c5865d5e5ed065e42267fa556202
(cherry picked from commit a7ec12f7ef)
2019-10-10 18:03:07 +00:00
Orion Hodson
02440d3b1b Use libnativehelper to get access to NIO buffer internals
Changes to android_opengl_* are generated by editing glgen stubs and
re-running gen script.

Bug: 124338141
Test: atest CtsGraphicsTestCases

(cherry picked from commit 61783592df)

Change-Id: I179f90177c8b1b50a923baecef3b5071a9a25ccf
Merged-In: I715123e66f4ace1d6a11a42c8eafc1d02995e88b
2019-04-11 16:51:33 +01:00
Leon Scroggins III
71fae62f5f Pass Bitmap's native instance to JNI where feasible
Test: CtsGraphicsTestCases, CtsUiRenderingTestCases,
      CtsRenderscriptTestCases

This is significantly faster than passing the Java object down and then
calling a JNI method to retrieve the pointer. See
https://buganizer.corp.google.com/issues/16656908#comment19

In some cases this changes what used to be native crashes (due to
android::BitmapWrapper:assertValid's LOG_ALWAYS_FATAL_IF) into
NullPointerExceptions (if a caller used a null Bitmap).

In addition:
- Remove unnecessary JNIEnv param from toBitmap(jlong)
- Change instances of toBitmap(JNIEnv*, jobject) to the above
- Replace calls to GraphicsJNI::getSkBitmap() to inline calls to
  toBitmap/getSkBitmap
- make Canvas#nInitRaster @FastNative (FIXME: Could these be
  @CriticalNative?)

Change-Id: I6194097be1b6e6952eba70e1e7052a5a250eed93
2019-03-27 13:39:23 -04:00
Leon Scroggins III
ca8aef6376 Remove bitmap::getBitmapAllocationByteCount
Test: I7eb02bc2389aadc10ee0b65993bb7e2dab27a129

Also remove gBitmap_getAllocationByteCountMethodID. These called into
Java, which then called back into native. Instead, call the native method
directly. The only extra wrinkle is that the Java method returns 0
if (mRecycled). But we would never reach that return value, since if
it was recycled, we would have crashed in native Bitmap::assertValid.
Instead, throw an IllegalArgumentException when attempting to reuse
it.

This avoids the overhead of two JNI calls, which tend to be slow.

Change-Id: I29e8d2428036252cfad532b1351e3a3d33817b43
2019-03-26 16:50:32 -04:00
Luca Stefani
79a5f4b18b Merge "Remove unused HarfBuzz src in libandroid_runtime" am: b9940315bf am: dbc06c23a6
am: e35e3b62c9

Change-Id: Ifd171e6077f55cdd0f0e037413d195c0d5ae55f5
2019-03-18 14:28:56 -07:00
Leon Scroggins
576c8b77f4 Merge "Revert "Speculative fix for createBitmap crash"" 2019-03-15 15:17:23 +00:00
Leon Scroggins
c052fa2032 Merge changes I241824bf,I9021864f
* changes:
  Convert ColorLong in native code in Paint
  Restore Paint#nSetColor(@ColorInt)
2019-03-15 12:14:20 +00:00
TreeHugger Robot
7e7a8efd5f Merge "Stop double-counting native memory in graphics classes" 2019-03-14 17:03:30 +00:00
Leon Scroggins III
10965f3922 Convert ColorLong in native code in Paint
Bug: 127580253
Test: CtsGraphicsTestCases
Perf: systrace

Follow on to I0b42c17159b290868a6bed7b90da096995504c4d, which did this
for other classes. I expect this to be more efficient due to passing
fewer JNI parameters, which appears to be the case based on the systrace
data for setColor(@ColorLong):

Duration:
(w/o this change)       (w/ this change)
avg:	0.010 ms        0.005 ms
max:	9.130 ms        0.239 ms
min:	0.002 ms        0.002 ms
std:	0.052 ms        0.004 ms

The average is twice as fast, the max is significantly shorter, and the
standard deviation is much smaller as well.

Change-Id: I241824bf2a934746df93da1063b14f3080486cb5
2019-03-14 10:59:37 -04:00
Leon Scroggins III
bbdb731275 Stop double-counting native memory in graphics classes
Bug: 121304803
Test: Infeasible

Previously, the NativeAllocationRegistry needed to report how much
native memory was being held onto by the Java class in order to get a
more accurate count of how much memory was in use. But recent changes
allow the system to have an even more accurate view of the native memory
with mallinfo(). Further, the AOSP change
Idccb8b50d26c8c3e93cc34040d784f74dfcdbf51 introduces new APIs that allow
distinguishing between large native malloc allocations, which should
cause more frequent mallinfo() checks, and whose sizes need be available
to ahat etc, and smaller native malloc allocations.

Bitmap and AnimatedImageDrawable use the version for large native malloc
allocations. The rest pass an implied size of 0. Note that many of the
old Registries used somewhat arbitrary sizes, reinforcing the fact that
the new way of keeping track of this is better.

Add Bitmap::pixelStorageType to differentiate between types of memory
that should be accounted for by the Registry.

Update Bitmap::getAllocationByteCount to report the actual size of
ashmem allocation.

Fix a typo in LineBreaker.java, discovered while looking to find
existing callers of Bitmap's constructor.

Change-Id: I57c407258450aeaf08b47df32432466639d9faed
2019-03-14 14:50:46 +00:00
Leon Scroggins III
03b3e236a0 Restore Paint#nSetColor(@ColorInt)
Bug: 127580253
Test: CtsGraphicsTestCases
Perf: systrace

Restored with a partial revert of "Add Paint#get(ShadowLayer)ColorLong"
(commit 6ee411010e).

The original CL combined the @ColorInt and @ColorLong version for
simplicity, but required doing extra work for the @ColorInt version.
Separating them back out speeds it up at the cost of more code.
Using systrace I see the following stats:

Duration:
(w/o this change)       (w/ this change)
avg:    0.020 ms        0.001 ms
max:    9.141 ms        0.072 ms
min:    0.005 ms        0.001 ms
std:    0.074 ms        0.001 ms

This change shows a significant speed improvement. It does not do the
same for setShadowLayer, which is likely used less frequently.

Change-Id: I9021864fcad7d0149b93674f09339f805c272994
2019-03-14 10:33:57 -04:00
Leon Scroggins III
300af26592 Revert "Speculative fix for createBitmap crash"
Bug: 112551574
Test: make

This reverts commit 023c0fc006.

This was a speculative fix for issue 112551574. Some further digging
revealed that the crash was only occurring in O, b/c it had been fixed
(tracked in issue 63044157). This "fix" and logging are not necessary.

Change-Id: I3a25597d1a38c4acab34fef936283e9a57bae826
2019-03-14 12:12:30 +00:00
TreeHugger Robot
7e8c759140 Merge "Change TabStop type from int to float" 2019-03-13 23:00:28 +00:00
Seigo Nonaka
d5621edc35 Change TabStop type from int to float
This is from API council feedback.

Bug: 124794899
Test: atest CtsTextTestCases
Test: atest CtsGraphicsTestCases
Change-Id: Ifa95f87067239cca9c0791bf079045e4f645c3ad
2019-03-12 12:27:47 -07:00
Luca Stefani
41da9a9a65 Remove unused HarfBuzz src in libandroid_runtime
Test: m libandroid_runtime
Change-Id: Idc0c4d482b47e502a350103e71ad58901226c819
2019-03-12 19:17:03 +01:00
Seigo Nonaka
fb1b479314 Hide packing structure from public API
The hyphen edit is packed into 8bit integer in native library, but this
should not be exposed to public API as API council suggested.

This CL includes:
- Removing packing structure from HyphenEdit and move constants from
  Hyphenator to Paint.
- Replace LineBreaker's getLineHyphenEdit with two separate start/end
  function.
- Replace Paint's getHyphenEdit with two separate start/end function.
- StaticLayout still relies on this packing mechanism but no longer need
  to be the same packing structure as in Minikin.

Bug: 124794844
Test: atest CtsGraphicsTestCases
Test: atest CtsTextTestCases
Change-Id: I8206061f554cf6e119b2b565162f54317eac630a
2019-03-11 16:51:47 -07:00
TreeHugger Robot
1b042a7c6e Merge "Pass ColorSpace to AnimatedImageDrawable" 2019-03-06 03:37:23 +00:00
Aurimas Liutikas
1ea6075433 Start running CtsGraphicsTestCases for changes to graphics code.
Start using test mapping for graphics CTS tests and graphics code.

Test: None
Change-Id: I6a3addef7f21683f621f530766323743cafec825
2019-02-28 10:16:27 -08:00
Leon Scroggins III
eac1423a31 Pass ColorSpace to AnimatedImageDrawable
Bug: 123301872
Bug: 117601185
Test: Manual (Ie18811ba29a1db163aca08472b04ae185e9344f0)
Test: CTS (Ie4b0a232effc67ab7a7fc6070302c722177cadfa)
Test: Infeasible (verify desired ColorSpace is used)

When calling setTargetColorSpace on an ImageDecoder for an animated
image, pass this to the AnimatedImageDrawable. Also respect an EXTENDED
ColorSpace as a cue to decode to RGBA_F16, as with Bitmaps.

Call ImageDecoder#checkState for AnimatedImageDrawables, as with
Bitmaps.

Change-Id: I5f6e11ee14ce4477bfedf2d1fdde8e15ed5f24d5
2019-02-26 12:03:29 -05:00
Leon Scroggins III
28f3943fd4 Make ImageDecoder.setTargetColorSpace to EXTENDED promote to F16
Bug: 117601185
Test: I5e5bc6b73d5d27ae30f00507d59896008d4cf364

ImageDecoder does not have a way to request decoding to F16 on 8 bit
images, but it does have a way to request an EXTENDED ColorSpace. Treat
that as a request to use a higher bit depth. This matches how we match
EXTENDED to F16 in other cases (createBitmap, Bitmap#copy, etc).

Change-Id: I3d31b13b56bb57a23b47ffcb2eaba11c53e0b8d9
2019-02-19 11:50:19 -05:00
Derek Sollenberger
bf3e464704 Refine ColorSpace restrictions for Bitmaps
Bug: 123377741
Bug: 120870651
Bug: 121001670
Bug: 123374456
Bug: 124052364

Test: I90adb511c8fdefe016028da4fd53b079d8367bf6

RGBA_F16 is no longer restricted to particular ColorSpaces. (Previously,
it was LINEAR_EXTENDED_SRGB when decoded, and EXTENDED_SRGB when
created.) Instead, F16 is now EXTENDED if there is an EXTENDED variant,
but is otherwise not special. It defaults to SRGB (but EXTENDED), but
can be created or decoded to other ColorSpaces.

Likewise, smaller Configs use the non-EXTENDED variant, when the
EXTENDED variant was requested.

ALPHA_8 always has a null ColorSpace.

Add TransferParameters to EXTENDED_SRGB. This seems to be a relic from a
time before Skia treated SkColorSpaces as non-bounded. Make it have the
same parameters as SRGB, so that it can be used in native code. e.g. now
we can draw to/from it.

Fix a bug getting the ColorSpace for gray image. ImageDecoder's info
previously reported that a gray image's ColorSpace is null. (Though it
correctly decoded it with the proper ColorSpace.)

Allow setColorSpace to request SRGB on an EXTENDED_SRGB F16 Bitmap. (It
has no visible effect.)

Do *not* allow setting a ColorSpace on an ALPHA_8 Bitmap (throw an
Exception). Other attempts to create a Bitmap with ALPHA_8 and a
non-null ColorSpace silently use null, for backwards compatibility.

Copying *from* an ALPHA_8 to another Config returns a Bitmap with SRGB.

Change-Id: Ied0426f6deff354df5998691703a18ddd33ccd3d
2019-02-13 13:59:37 -05:00
Leon Scroggins III
023c0fc006 Speculative fix for createBitmap crash
Bug: 112551574
Test: Infeasible

Check for a null Bitmap before attempting to dereference it.

Change-Id: I250059e87540f005017abfdd9071f2fec86c1610
2019-02-04 12:19:36 -05:00
TreeHugger Robot
fcd2ab1b02 Merge "Properly refer to Java "long" as "jlong"" 2019-01-31 20:54:11 +00:00
TreeHugger Robot
4a49d7ad96 Merge "Remove code that does nothing" 2019-01-31 20:29:28 +00:00
TreeHugger Robot
def168576a Merge "Only decode to F16 if HARDWARE supports it" 2019-01-31 19:37:54 +00:00
Leon Scroggins III
2befe1d922 Properly refer to Java "long" as "jlong"
Bug: 123684965
Test: make and open Google Play
Change-Id: Ib8dc167c5ed0866c0687d7e71b28006d1bf2a35e
2019-01-31 13:19:26 -05:00
Leon Scroggins III
a170a5a5c2 Remove code that does nothing
Test: CtsGraphicsTestCases

When the comment was written, "the default" referred to
GraphicsJNI::colorSpaceForType, which was either SRGB or null, depending
on a build flag. In If7b1c00ad889446658f98e9ad644869e2eeabcdb, we
changed it to "decodeInfo.refColorSpace", but since bitmapInfo was just
assigned decodeInfo, it already has the same SkColorSpace, so this does
nothing. Remove the code and the comment.

Change-Id: Ib661621e30a6432707bb6894ca5334fba8eca81e
2019-01-31 10:38:32 -05:00
Leon Scroggins III
ee3bfe7681 Only decode to F16 if HARDWARE supports it
Bug: 123301974
Test: Infeasible

If a Bitmap is going to be decoded to F16 and then converted to
HARDWARE, only decode to F16 if HARDWARE supports it.

Previously, if we discovered after the decode that HARDWARE did not
support F16, we had to copy back to 8888 before the upload.

Change-Id: I3ceb9d053ba134bb96cfb9d638e54ac652e5db29
2019-01-31 10:38:26 -05:00
Peiyong Lin
a0baea28b7 Merge "Replace createHardwareBitmap with wrapHardwareBuffer." 2019-01-31 15:37:56 +00:00
Peiyong Lin
9d4274005e Replace createHardwareBitmap with wrapHardwareBuffer.
The bitmap.createHardwareBitmap doesn't take a ColorSpace as input, as a result
the returned bitmap is always in SRGB color space. Given that we want to remove
the assumption of SRGB color space, we replace the usage of
createHardwareBitmap with wrapHardwareBuffer which takes an extra argument
ColorSpace. As a result, we will be able to also fix SurfaceControl and various
other places that use screenshot in follow up patches.

BUG: 120904891
Test: CtsUiRenderingTestCases
Change-Id: I57fc0c85d68df43b0e69f9a1ebac00d2ba39554d
2019-01-30 15:22:54 -08:00
Leon Scroggins III
b0aecc22d3 Use ColorLongs in Linear-, Radial-, and Sweep-Gradient
Bug: 122844033
Test: Id1809aef84eca0ccc61bafc2476ad52ed78d5f22

Add APIs that mirror the existing creation APIs, but use @ColorLongs
instead of @ColorInts. Note that call-sites that used a null array (but
not a variable "int[]" pointing to a null array) are now ambiguous. It
is unlikely that there are any such call-sites, though, since they would
throw NullPointerException.

Consolidate constructors. Those that take two color endpoints now create
two-member long-arrays and call the more general constructor, saving
lots of code. The additional cost of small arrays is not as much as it
used to be, in the early days of Android, when this class was written.

In *Gradient#copy, there is no longer any need to clone the colors
array, since the mColorLongs was created by the Gradient. Similarly,
there never was any need to clone mPositions, which was always a clone
of the user-supplied array anyway.

Clean up Shader.cpp:
 - Throw and return if the pointer is null before dereferencing it.
 - Simplify and put together matrix-related code.

Change-Id: Ib71c5e85b2a398959bf687bce33980d3429bcbc3
2019-01-30 16:01:31 -05:00
TreeHugger Robot
b391c999d8 Merge "Add Bitmap#getColor" 2019-01-30 04:19:32 +00:00
TreeHugger Robot
39594b4f18 Merge "reset path before append glyph outlines, to match old SkPaint behavior" 2019-01-29 14:52:16 +00:00
Mike Reed
bacaa1d161 reset path before append glyph outlines, to match old SkPaint behavior
Bug: 123503704
Bug: 123541872
Test: make and open Maps

Change-Id: I2fed9518e84bcd8124b9a8da1b16f3f06246c1e1
2019-01-29 14:01:23 +00:00
Leon Scroggins III
870053d44b Add Bitmap#getColor
Bug: 120904891
Test: I61ba938cdbea5154187c3a075c84436f2db81174

getColor returns a Color object in the ColorSpace of the Bitmap.
The underlying SkBitmap may contain values that are outside the
numerical range of the ColorSpace, so clamp them to fit.

Change-Id: I4174b75a83f18d6e165dbd2c724708276e80af21
2019-01-29 08:42:58 -05:00
Nick Kralevich
2d04d9870c Merge "jni: more O_CLOEXECs" am: 0bd511611e am: c37cf98395
am: db8af62777

Change-Id: I34f53d427efb89f295a2027ceffcb5ccbd149e0b
2019-01-28 22:33:27 -08:00
Derek Sollenberger
202084c9b8 Add Bitmap.setColorSpace()
Bug: 120904891
Test: CtsGraphicsTestCases
Change-Id: I30be2cd77d810210ad87b281e6bb5587863982c3
2019-01-28 17:25:29 -05:00
Nick Kralevich
4b3a08c2b7 jni: more O_CLOEXECs
Prevent FDs from leaking across an execve() boundary.

Test: compiles and boots
Change-Id: I5f91046917b55b6abead0a5c6e939f82814e6f18
2019-01-28 10:39:10 -08:00
Mike Reed
03acdb10c7 access hinting via SkFont
Test: make

Change-Id: I12f75d9bd10517528c60cd7d3362f7a8af1eb529
2019-01-26 10:17:49 -05:00
Mike Reed
0ea09a4f4a IWYU
Trying to land https://skia-review.googlesource.com/c/skia/+/185460

Test: make

Change-Id: Ia1dd2fb6911d3e562e9c68e8ad03136f96b2d7c0
2019-01-25 18:06:21 +00:00
TreeHugger Robot
d8cf9da7c2 Merge "Store SkFont in android::Paint" 2019-01-25 14:09:11 +00:00
Mike Reed
f6d86acb93 Store SkFont in android::Paint
Test: CTS

Change-Id: I974fad5a7a8cf54007f0a30f4fe4ae6eb6e01ae1
2019-01-24 17:18:43 -05:00
Derek Sollenberger
48340af06e Merge "Don't assume all FP16 bitmaps are linearly encoded." 2019-01-24 16:32:31 +00:00
Derek Sollenberger
6e35e63740 Don't assume all FP16 bitmaps are linearly encoded.
The bitmap.create() function that does not take a colorspace does
not enforce that the bitmap is linearly encoded and as such it is
possible for us to end up with FP16 bitmaps that are sRGB encoded.

Given that we want to remove that restriction (see b/120870651)
we update getColorSpace to report the actual colorSpace of the
underlying bitmap. This pulls a thread that causes a chain of
updates to various classes to ensure proper handling of the native
colorspace.

Bug: 120904891
Test: CtsUiRenderingTestCases
Change-Id: I27780aa603138b0e48f9320c2837bc53e22cdf95
2019-01-23 16:31:52 -05:00
John Reck
5cca8f250c Add continuous SKP capture test api
Bug: 122856066
Test: PictureCaptureDemo
Change-Id: Iaf3a4bc1c8a2c18c7dff635c5f1cf726b331f8bf
2019-01-22 13:13:06 -08:00
Leon Scroggins III
94ba100c50 Convert @ColorLongs in native code
Bug: 120904891
Bug: 122844033
Bug: 122514935
Test: CtsGraphicsTestCases

Only convert rgba. ColorSpace should be converted in Java, so we can
just pass the native pointer and handle potential Exceptions before
going into native code.

Requires a change to external/skia [1] to make SkHalfToFloat SK_API.

[1] https://skia-review.googlesource.com/c/skia/+/185140

Change-Id: I0b42c17159b290868a6bed7b90da096995504c4d
2019-01-18 16:19:53 -05:00
Leon Scroggins III
0e443d1633 ColorSpaces have native SkColorSpaces
Bug: 120904891
Bug: 122844033
Bug: 122514935
Test: CtsGraphicsTestCases

Create an SkColorSpace when creating an android.graphics.ColorSpace.Rgb.
This allows simplifying getNativeColorSpace, so that each time we need
it, we do not need to call back up into Java or reconstruct the
SkColorSpace.

Funnel all ColorSpace.Rgb constructors into one, so we can set a final
mNativePtr in the base constructor. Update TransferParameters to also be
final.

Use the same TransferParameters as SRGB in EXTENDED_SRGB and DISPLAY_P3.

When passing a BitmapFactory.Options to native, call getNativeInstance()
(which may throw an Exception) and pass the result to native.

Move native ColorSpace code into its own file.

Make Paint methods @CriticalNative again, now that they do not need the
JNIEnv.

Remove unused decodeBitmap.

Change-Id: I60adbb060b87ab6f92559f1217bfefc0b9ea72e1
2019-01-18 16:19:48 -05:00
Leon Scroggins III
6ee411010e Add Paint#get(ShadowLayer)ColorLong
Bug: 120904891
Test: I6de01bd94fade605643af590f8d6909f09a5831e

Store Paint's colors (both the ShadowLayerColor, and the previously
uncached color that is stored in the native SkPaint) as @ColorLongs.
When setting or retrieving the int version, convert. This allows
returning the long value that was manually set, so that we return the
color in the ColorSpace that was requested.

Since the color is already stored in Java, remove nGetAlpha, and return
the alpha from the ColorLong. When setting alpha, update the cached
value, too.

Make setShadowLayer(..., @ColorInt) and setColor(@ColorInt) call the
@ColorLong versions, so they can share single JNI entry points.

Change-Id: Ifc559893dd4db2629c59b6e53f0b2166d43e6049
2019-01-16 14:26:20 -05:00
Leon Scroggins III
8bbcd3477c Add Paint#setShadowLayer(..., @ColorLong)
Bug: 120904891
Test: I38537394bf314668cc38349c34b9492164cb0c92

Change-Id: Id1c294a2a79087cfaaf4a25fa4888f706fdb8124
2019-01-15 15:37:36 -05:00
Leon Scroggins III
aefa03dd9e Add Paint#setColor(@ColorLong)
Bug: 120904891
Test: Iba796744a9cc3652a6bc1881a9b229403ffaed31
Change-Id: Ib03212b27bc330e61b876a4be3d45c34ed551540
2019-01-15 15:37:36 -05:00