diff options
33 files changed, 371 insertions, 188 deletions
diff --git a/core/java/android/hardware/camera2/legacy/SurfaceTextureRenderer.java b/core/java/android/hardware/camera2/legacy/SurfaceTextureRenderer.java index e0d3905ea942..a05a8ec00e79 100644 --- a/core/java/android/hardware/camera2/legacy/SurfaceTextureRenderer.java +++ b/core/java/android/hardware/camera2/legacy/SurfaceTextureRenderer.java @@ -248,7 +248,8 @@ public class SurfaceTextureRenderer { return program; } - private void drawFrame(SurfaceTexture st, int width, int height, int flipType) { + private void drawFrame(SurfaceTexture st, int width, int height, int flipType) + throws LegacyExceptionUtils.BufferQueueAbandonedException { checkGlError("onDrawFrame start"); st.getTransformMatrix(mSTMatrix); @@ -343,7 +344,7 @@ public class SurfaceTextureRenderer { /*offset*/ 0); GLES20.glDrawArrays(GLES20.GL_TRIANGLE_STRIP, /*offset*/ 0, /*count*/ 4); - checkGlError("glDrawArrays"); + checkGlDrawError("glDrawArrays"); } /** @@ -548,7 +549,29 @@ public class SurfaceTextureRenderer { private void checkGlError(String msg) { int error; while ((error = GLES20.glGetError()) != GLES20.GL_NO_ERROR) { - throw new IllegalStateException(msg + ": GLES20 error: 0x" + Integer.toHexString(error)); + throw new IllegalStateException( + msg + ": GLES20 error: 0x" + Integer.toHexString(error)); + } + } + + private void checkGlDrawError(String msg) + throws LegacyExceptionUtils.BufferQueueAbandonedException { + int error; + boolean surfaceAbandoned = false; + boolean glError = false; + while ((error = GLES20.glGetError()) != GLES20.GL_NO_ERROR) { + if (error == GLES20.GL_OUT_OF_MEMORY) { + surfaceAbandoned = true; + } else { + glError = true; + } + } + if (glError) { + throw new IllegalStateException( + msg + ": GLES20 error: 0x" + Integer.toHexString(error)); + } + if (surfaceAbandoned) { + throw new LegacyExceptionUtils.BufferQueueAbandonedException(); } } @@ -759,9 +782,14 @@ public class SurfaceTextureRenderer { if (LegacyCameraDevice.containsSurfaceId(holder.surface, targetSurfaceIds)) { makeCurrent(holder.eglSurface); // glReadPixels reads from the bottom of the buffer, so add an extra vertical flip - drawFrame(mSurfaceTexture, holder.width, holder.height, - (mFacing == CameraCharacteristics.LENS_FACING_FRONT) ? - FLIP_TYPE_BOTH : FLIP_TYPE_VERTICAL); + try { + drawFrame(mSurfaceTexture, holder.width, holder.height, + (mFacing == CameraCharacteristics.LENS_FACING_FRONT) ? + FLIP_TYPE_BOTH : FLIP_TYPE_VERTICAL); + } catch (LegacyExceptionUtils.BufferQueueAbandonedException e) { + // Should never hit this. + throw new IllegalStateException("Surface abandoned, skipping drawFrame...", e); + } mPBufferPixels.clear(); GLES20.glReadPixels(/*x*/ 0, /*y*/ 0, holder.width, holder.height, GLES20.GL_RGBA, GLES20.GL_UNSIGNED_BYTE, mPBufferPixels); diff --git a/core/java/android/provider/Settings.java b/core/java/android/provider/Settings.java index 875b9aff421e..ceb632bd8b70 100755 --- a/core/java/android/provider/Settings.java +++ b/core/java/android/provider/Settings.java @@ -6933,6 +6933,12 @@ public final class Settings { public static final String DOCK_SOUNDS_ENABLED = "dock_sounds_enabled"; /** + * Whether to play a sound for dock events, only when an accessibility service is on. + * @hide + */ + public static final String DOCK_SOUNDS_ENABLED_WHEN_ACCESSIBILITY = "dock_sounds_enabled_when_accessbility"; + + /** * URI for the "device locked" (keyguard shown) sound. * @hide */ diff --git a/core/java/android/widget/TextView.java b/core/java/android/widget/TextView.java index f1c307934906..2f9c97b38afa 100644 --- a/core/java/android/widget/TextView.java +++ b/core/java/android/widget/TextView.java @@ -3685,18 +3685,23 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener } /** - * Makes the TextView at least this many lines tall. + * Sets the height of the TextView to be at least {@code minLines} tall. + * <p> + * This value is used for height calculation if LayoutParams does not force TextView to have an + * exact height. Setting this value overrides other previous minimum height configurations such + * as {@link #setMinHeight(int)} or {@link #setHeight(int)}. {@link #setSingleLine()} will set + * this value to 1. * - * Setting this value overrides any other (minimum) height setting. A single line TextView will - * set this value to 1. + * @param minLines the minimum height of TextView in terms of number of lines * * @see #getMinLines() + * @see #setLines(int) * * @attr ref android.R.styleable#TextView_minLines */ @android.view.RemotableViewMethod - public void setMinLines(int minlines) { - mMinimum = minlines; + public void setMinLines(int minLines) { + mMinimum = minLines; mMinMode = LINES; requestLayout(); @@ -3704,10 +3709,14 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener } /** - * @return the minimum number of lines displayed in this TextView, or -1 if the minimum - * height was set in pixels instead using {@link #setMinHeight(int) or #setHeight(int)}. + * Returns the minimum height of TextView in terms of number of lines or -1 if the minimum + * height was set using {@link #setMinHeight(int)} or {@link #setHeight(int)}. + * + * @return the minimum height of TextView in terms of number of lines or -1 if the minimum + * height is not defined in lines * * @see #setMinLines(int) + * @see #setLines(int) * * @attr ref android.R.styleable#TextView_minLines */ @@ -3716,15 +3725,26 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener } /** - * Makes the TextView at least this many pixels tall. + * Sets the height of the TextView to be at least {@code minPixels} tall. + * <p> + * This value is used for height calculation if LayoutParams does not force TextView to have an + * exact height. Setting this value overrides previous minimum height configurations such as + * {@link #setMinLines(int)} or {@link #setLines(int)}. + * <p> + * The value given here is different than {@link #setMinimumHeight(int)}. Between + * {@code minHeight} and the value set in {@link #setMinimumHeight(int)}, the greater one is + * used to decide the final height. + * + * @param minPixels the minimum height of TextView in terms of pixels * - * Setting this value overrides any other (minimum) number of lines setting. + * @see #getMinHeight() + * @see #setHeight(int) * * @attr ref android.R.styleable#TextView_minHeight */ @android.view.RemotableViewMethod - public void setMinHeight(int minHeight) { - mMinimum = minHeight; + public void setMinHeight(int minPixels) { + mMinimum = minPixels; mMinMode = PIXELS; requestLayout(); @@ -3732,10 +3752,14 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener } /** - * @return the minimum height of this TextView expressed in pixels, or -1 if the minimum - * height was set in number of lines instead using {@link #setMinLines(int) or #setLines(int)}. + * Returns the minimum height of TextView in terms of pixels or -1 if the minimum height was + * set using {@link #setMinLines(int)} or {@link #setLines(int)}. + * + * @return the minimum height of TextView in terms of pixels or -1 if the minimum height is not + * defined in pixels * * @see #setMinHeight(int) + * @see #setHeight(int) * * @attr ref android.R.styleable#TextView_minHeight */ @@ -3744,15 +3768,22 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener } /** - * Makes the TextView at most this many lines tall. + * Sets the height of the TextView to be at most {@code maxLines} tall. + * <p> + * This value is used for height calculation if LayoutParams does not force TextView to have an + * exact height. Setting this value overrides previous maximum height configurations such as + * {@link #setMaxHeight(int)} or {@link #setLines(int)}. * - * Setting this value overrides any other (maximum) height setting. + * @param maxLines the maximum height of TextView in terms of number of lines + * + * @see #getMaxLines() + * @see #setLines(int) * * @attr ref android.R.styleable#TextView_maxLines */ @android.view.RemotableViewMethod - public void setMaxLines(int maxlines) { - mMaximum = maxlines; + public void setMaxLines(int maxLines) { + mMaximum = maxLines; mMaxMode = LINES; requestLayout(); @@ -3760,10 +3791,14 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener } /** - * @return the maximum number of lines displayed in this TextView, or -1 if the maximum - * height was set in pixels instead using {@link #setMaxHeight(int) or #setHeight(int)}. + * Returns the maximum height of TextView in terms of number of lines or -1 if the + * maximum height was set using {@link #setMaxHeight(int)} or {@link #setHeight(int)}. + * + * @return the maximum height of TextView in terms of number of lines. -1 if the maximum height + * is not defined in lines. * * @see #setMaxLines(int) + * @see #setLines(int) * * @attr ref android.R.styleable#TextView_maxLines */ @@ -3772,16 +3807,22 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener } /** - * Makes the TextView at most this many pixels tall. This option is mutually exclusive with the - * {@link #setMaxLines(int)} method. + * Sets the height of the TextView to be at most {@code maxPixels} tall. + * <p> + * This value is used for height calculation if LayoutParams does not force TextView to have an + * exact height. Setting this value overrides previous maximum height configurations such as + * {@link #setMaxLines(int)} or {@link #setLines(int)}. + * + * @param maxPixels the maximum height of TextView in terms of pixels * - * Setting this value overrides any other (maximum) number of lines setting. + * @see #getMaxHeight() + * @see #setHeight(int) * * @attr ref android.R.styleable#TextView_maxHeight */ @android.view.RemotableViewMethod - public void setMaxHeight(int maxHeight) { - mMaximum = maxHeight; + public void setMaxHeight(int maxPixels) { + mMaximum = maxPixels; mMaxMode = PIXELS; requestLayout(); @@ -3789,10 +3830,14 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener } /** - * @return the maximum height of this TextView expressed in pixels, or -1 if the maximum - * height was set in number of lines instead using {@link #setMaxLines(int) or #setLines(int)}. + * Returns the maximum height of TextView in terms of pixels or -1 if the maximum height was + * set using {@link #setMaxLines(int)} or {@link #setLines(int)}. + * + * @return the maximum height of TextView in terms of pixels or -1 if the maximum height + * is not defined in pixels * * @see #setMaxHeight(int) + * @see #setHeight(int) * * @attr ref android.R.styleable#TextView_maxHeight */ @@ -3801,10 +3846,16 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener } /** - * Makes the TextView exactly this many lines tall. + * Sets the height of the TextView to be exactly {@code lines} tall. + * <p> + * This value is used for height calculation if LayoutParams does not force TextView to have an + * exact height. Setting this value overrides previous minimum/maximum height configurations + * such as {@link #setMinLines(int)} or {@link #setMaxLines(int)}. {@link #setSingleLine()} will + * set this value to 1. * - * Note that setting this value overrides any other (minimum / maximum) number of lines or - * height setting. A single line TextView will set this value to 1. + * @param lines the exact height of the TextView in terms of lines + * + * @see #setHeight(int) * * @attr ref android.R.styleable#TextView_lines */ @@ -3818,12 +3869,15 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener } /** - * Makes the TextView exactly this many pixels tall. - * You could do the same thing by specifying this number in the - * LayoutParams. + * Sets the height of the TextView to be exactly <code>pixels</code> tall. + * <p> + * This value is used for height calculation if LayoutParams does not force TextView to have an + * exact height. Setting this value overrides previous minimum/maximum height configurations + * such as {@link #setMinHeight(int)} or {@link #setMaxHeight(int)}. * - * Note that setting this value overrides any other (minimum / maximum) number of lines or - * height setting. + * @param pixels the exact height of the TextView in terms of pixels + * + * @see #setLines(int) * * @attr ref android.R.styleable#TextView_height */ @@ -3837,13 +3891,22 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener } /** - * Makes the TextView at least this many ems wide + * Sets the width of the TextView to be at least {@code minEms} wide. + * <p> + * This value is used for width calculation if LayoutParams does not force TextView to have an + * exact width. Setting this value overrides previous minimum width configurations such as + * {@link #setMinWidth(int)} or {@link #setWidth(int)}. + * + * @param minEms the minimum width of TextView in terms of ems + * + * @see #getMinEms() + * @see #setEms(int) * * @attr ref android.R.styleable#TextView_minEms */ @android.view.RemotableViewMethod - public void setMinEms(int minems) { - mMinWidth = minems; + public void setMinEms(int minEms) { + mMinWidth = minEms; mMinWidthMode = EMS; requestLayout(); @@ -3851,8 +3914,11 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener } /** - * @return the minimum width of the TextView, expressed in ems or -1 if the minimum width - * was set in pixels instead (using {@link #setMinWidth(int)} or {@link #setWidth(int)}). + * Returns the minimum width of TextView in terms of ems or -1 if the minimum width was set + * using {@link #setMinWidth(int)} or {@link #setWidth(int)}. + * + * @return the minimum width of TextView in terms of ems. -1 if the minimum width is not + * defined in ems * * @see #setMinEms(int) * @see #setEms(int) @@ -3864,13 +3930,26 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener } /** - * Makes the TextView at least this many pixels wide + * Sets the width of the TextView to be at least {@code minPixels} wide. + * <p> + * This value is used for width calculation if LayoutParams does not force TextView to have an + * exact width. Setting this value overrides previous minimum width configurations such as + * {@link #setMinEms(int)} or {@link #setEms(int)}. + * <p> + * The value given here is different than {@link #setMinimumWidth(int)}. Between + * {@code minWidth} and the value set in {@link #setMinimumWidth(int)}, the greater one is used + * to decide the final width. + * + * @param minPixels the minimum width of TextView in terms of pixels + * + * @see #getMinWidth() + * @see #setWidth(int) * * @attr ref android.R.styleable#TextView_minWidth */ @android.view.RemotableViewMethod - public void setMinWidth(int minpixels) { - mMinWidth = minpixels; + public void setMinWidth(int minPixels) { + mMinWidth = minPixels; mMinWidthMode = PIXELS; requestLayout(); @@ -3878,8 +3957,11 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener } /** - * @return the minimum width of the TextView, in pixels or -1 if the minimum width - * was set in ems instead (using {@link #setMinEms(int)} or {@link #setEms(int)}). + * Returns the minimum width of TextView in terms of pixels or -1 if the minimum width was set + * using {@link #setMinEms(int)} or {@link #setEms(int)}. + * + * @return the minimum width of TextView in terms of pixels or -1 if the minimum width is not + * defined in pixels * * @see #setMinWidth(int) * @see #setWidth(int) @@ -3891,13 +3973,22 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener } /** - * Makes the TextView at most this many ems wide + * Sets the width of the TextView to be at most {@code maxEms} wide. + * <p> + * This value is used for width calculation if LayoutParams does not force TextView to have an + * exact width. Setting this value overrides previous maximum width configurations such as + * {@link #setMaxWidth(int)} or {@link #setWidth(int)}. + * + * @param maxEms the maximum width of TextView in terms of ems + * + * @see #getMaxEms() + * @see #setEms(int) * * @attr ref android.R.styleable#TextView_maxEms */ @android.view.RemotableViewMethod - public void setMaxEms(int maxems) { - mMaxWidth = maxems; + public void setMaxEms(int maxEms) { + mMaxWidth = maxEms; mMaxWidthMode = EMS; requestLayout(); @@ -3905,8 +3996,11 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener } /** - * @return the maximum width of the TextView, expressed in ems or -1 if the maximum width - * was set in pixels instead (using {@link #setMaxWidth(int)} or {@link #setWidth(int)}). + * Returns the maximum width of TextView in terms of ems or -1 if the maximum width was set + * using {@link #setMaxWidth(int)} or {@link #setWidth(int)}. + * + * @return the maximum width of TextView in terms of ems or -1 if the maximum width is not + * defined in ems * * @see #setMaxEms(int) * @see #setEms(int) @@ -3918,13 +4012,22 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener } /** - * Makes the TextView at most this many pixels wide + * Sets the width of the TextView to be at most {@code maxPixels} wide. + * <p> + * This value is used for width calculation if LayoutParams does not force TextView to have an + * exact width. Setting this value overrides previous maximum width configurations such as + * {@link #setMaxEms(int)} or {@link #setEms(int)}. + * + * @param maxPixels the maximum width of TextView in terms of pixels + * + * @see #getMaxWidth() + * @see #setWidth(int) * * @attr ref android.R.styleable#TextView_maxWidth */ @android.view.RemotableViewMethod - public void setMaxWidth(int maxpixels) { - mMaxWidth = maxpixels; + public void setMaxWidth(int maxPixels) { + mMaxWidth = maxPixels; mMaxWidthMode = PIXELS; requestLayout(); @@ -3932,8 +4035,11 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener } /** - * @return the maximum width of the TextView, in pixels or -1 if the maximum width - * was set in ems instead (using {@link #setMaxEms(int)} or {@link #setEms(int)}). + * Returns the maximum width of TextView in terms of pixels or -1 if the maximum width was set + * using {@link #setMaxEms(int)} or {@link #setEms(int)}. + * + * @return the maximum width of TextView in terms of pixels. -1 if the maximum width is not + * defined in pixels * * @see #setMaxWidth(int) * @see #setWidth(int) @@ -3945,12 +4051,15 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener } /** - * Makes the TextView exactly this many ems wide + * Sets the width of the TextView to be exactly {@code ems} wide. * - * @see #setMaxEms(int) - * @see #setMinEms(int) - * @see #getMinEms() - * @see #getMaxEms() + * This value is used for width calculation if LayoutParams does not force TextView to have an + * exact width. Setting this value overrides previous minimum/maximum configurations such as + * {@link #setMinEms(int)} or {@link #setMaxEms(int)}. + * + * @param ems the exact width of the TextView in terms of ems + * + * @see #setWidth(int) * * @attr ref android.R.styleable#TextView_ems */ @@ -3964,14 +4073,15 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener } /** - * Makes the TextView exactly this many pixels wide. - * You could do the same thing by specifying this number in the - * LayoutParams. + * Sets the width of the TextView to be exactly {@code pixels} wide. + * <p> + * This value is used for width calculation if LayoutParams does not force TextView to have an + * exact width. Setting this value overrides previous minimum/maximum width configurations + * such as {@link #setMinWidth(int)} or {@link #setMaxWidth(int)}. * - * @see #setMaxWidth(int) - * @see #setMinWidth(int) - * @see #getMinWidth() - * @see #getMaxWidth() + * @param pixels the exact width of the TextView in terms of pixels + * + * @see #setEms(int) * * @attr ref android.R.styleable#TextView_width */ diff --git a/core/jni/android/graphics/Bitmap.cpp b/core/jni/android/graphics/Bitmap.cpp index adfc98ec2f84..467ec37fca46 100755 --- a/core/jni/android/graphics/Bitmap.cpp +++ b/core/jni/android/graphics/Bitmap.cpp @@ -212,6 +212,12 @@ Bitmap& toBitmap(JNIEnv* env, jobject bitmap) { return localBitmap->bitmap(); } +Bitmap& toBitmap(JNIEnv* env, jlong bitmapHandle) { + SkASSERT(env); + LocalScopedBitmap localBitmap(bitmapHandle); + return localBitmap->bitmap(); +} + } // namespace bitmap } // namespace android @@ -1199,9 +1205,7 @@ static jlong Bitmap_refPixelRef(JNIEnv* env, jobject, jlong bitmapHandle) { static void Bitmap_prepareToDraw(JNIEnv* env, jobject, jlong bitmapPtr) { LocalScopedBitmap bitmapHandle(bitmapPtr); if (!bitmapHandle.valid()) return; - SkBitmap bitmap; - bitmapHandle->getSkBitmap(&bitmap); - android::uirenderer::renderthread::RenderProxy::prepareToDraw(bitmap); + android::uirenderer::renderthread::RenderProxy::prepareToDraw(bitmapHandle->bitmap()); } static jint Bitmap_getAllocationByteCount(JNIEnv* env, jobject, jlong bitmapPtr) { diff --git a/core/jni/android/graphics/Bitmap.h b/core/jni/android/graphics/Bitmap.h index ece7083664a5..387a1285ba12 100644 --- a/core/jni/android/graphics/Bitmap.h +++ b/core/jni/android/graphics/Bitmap.h @@ -42,6 +42,7 @@ jobject createBitmap(JNIEnv* env, Bitmap* bitmap, void toSkBitmap(jlong bitmapHandle, SkBitmap* outBitmap); Bitmap& toBitmap(JNIEnv* env, jobject bitmap); +Bitmap& toBitmap(JNIEnv* env, jlong bitmapHandle); /** Reinitialize a bitmap. bitmap must already have its SkAlphaType set in sync with isPremultiplied diff --git a/core/jni/android_graphics_Canvas.cpp b/core/jni/android_graphics_Canvas.cpp index d79325a46416..04a754307267 100644 --- a/core/jni/android_graphics_Canvas.cpp +++ b/core/jni/android_graphics_Canvas.cpp @@ -341,13 +341,12 @@ static void drawNinePatch(JNIEnv* env, jobject, jlong canvasHandle, jlong bitmap jlong paintHandle, jint dstDensity, jint srcDensity) { Canvas* canvas = get_canvas(canvasHandle); - SkBitmap skiaBitmap; - bitmap::toSkBitmap(bitmapHandle, &skiaBitmap); + Bitmap& bitmap = android::bitmap::toBitmap(env, bitmapHandle); const android::Res_png_9patch* chunk = reinterpret_cast<android::Res_png_9patch*>(chunkHandle); const Paint* paint = reinterpret_cast<Paint*>(paintHandle); if (CC_LIKELY(dstDensity == srcDensity || dstDensity == 0 || srcDensity == 0)) { - canvas->drawNinePatch(skiaBitmap, *chunk, left, top, right, bottom, paint); + canvas->drawNinePatch(bitmap, *chunk, left, top, right, bottom, paint); } else { canvas->save(SaveFlags::MatrixClip); @@ -361,7 +360,7 @@ static void drawNinePatch(JNIEnv* env, jobject, jlong canvasHandle, jlong bitmap } filteredPaint.setFilterQuality(kLow_SkFilterQuality); - canvas->drawNinePatch(skiaBitmap, *chunk, 0, 0, (right-left)/scale, (bottom-top)/scale, + canvas->drawNinePatch(bitmap, *chunk, 0, 0, (right-left)/scale, (bottom-top)/scale, &filteredPaint); canvas->restore(); @@ -464,8 +463,7 @@ static void drawBitmapMesh(JNIEnv* env, jobject, jlong canvasHandle, jobject jbi AutoJavaIntArray colorA(env, jcolors, colorIndex + ptCount); const Paint* paint = reinterpret_cast<Paint*>(paintHandle); - SkBitmap bitmap; - GraphicsJNI::getSkBitmap(env, jbitmap, &bitmap); + Bitmap& bitmap = android::bitmap::toBitmap(env, jbitmap); get_canvas(canvasHandle)->drawBitmapMesh(bitmap, meshWidth, meshHeight, vertA.ptr(), colorA.ptr(), paint); } diff --git a/core/res/res/layout-round-watch/alert_dialog_title_material.xml b/core/res/res/layout-round-watch/alert_dialog_title_material.xml index e543c9b69390..aefe28f7f359 100644 --- a/core/res/res/layout-round-watch/alert_dialog_title_material.xml +++ b/core/res/res/layout-round-watch/alert_dialog_title_material.xml @@ -14,25 +14,31 @@ ~ See the License for the specific language governing permissions and ~ limitations under the License --> -<FrameLayout +<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="wrap_content" - android:gravity="top|center_horizontal" - android:minHeight="@dimen/alert_dialog_title_height"> - <ImageView android:id="@+id/icon" + android:orientation="vertical" + android:gravity="top|center_horizontal"> + <FrameLayout android:adjustViewBounds="true" - android:maxHeight="24dp" - android:maxWidth="24dp" - android:layout_marginTop="12dp" - android:layout_gravity="center_horizontal" - android:layout_width="wrap_content" + android:layout_width="match_parent" android:layout_height="wrap_content" - android:src="@null" /> + android:minHeight="@dimen/screen_percentage_15"> + <ImageView android:id="@+id/icon" + android:adjustViewBounds="true" + android:maxHeight="24dp" + android:maxWidth="24dp" + android:layout_marginTop="@dimen/screen_percentage_10" + android:layout_marginBottom="8dp" + android:layout_gravity="center_horizontal" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:src="@null" /> + </FrameLayout> <TextView android:id="@+id/alertTitle" style="?android:attr/windowTitleStyle" - android:layout_marginTop="36dp" android:layout_marginBottom="8dp" android:layout_width="match_parent" android:layout_height="wrap_content" /> -</FrameLayout> +</LinearLayout> diff --git a/libs/hwui/BakedOpDispatcher.cpp b/libs/hwui/BakedOpDispatcher.cpp index 840c79dcc108..6079d5def1f8 100644 --- a/libs/hwui/BakedOpDispatcher.cpp +++ b/libs/hwui/BakedOpDispatcher.cpp @@ -46,7 +46,7 @@ void BakedOpDispatcher::onMergedBitmapOps(BakedOpRenderer& renderer, const MergedBakedOpList& opList) { const BakedOpState& firstState = *(opList.states[0]); - const SkBitmap* bitmap = (static_cast<const BitmapOp*>(opList.states[0]->op))->bitmap; + Bitmap* bitmap = (static_cast<const BitmapOp*>(opList.states[0]->op))->bitmap; Texture* texture = renderer.caches().textureCache.get(bitmap); if (!texture) return; diff --git a/libs/hwui/BakedOpRenderer.cpp b/libs/hwui/BakedOpRenderer.cpp index ac7a600af85f..e8972aab9f8f 100644 --- a/libs/hwui/BakedOpRenderer.cpp +++ b/libs/hwui/BakedOpRenderer.cpp @@ -181,7 +181,7 @@ void BakedOpRenderer::clearColorBuffer(const Rect& rect) { if (!mRenderTarget.frameBufferId) mHasDrawn = true; } -Texture* BakedOpRenderer::getTexture(const SkBitmap* bitmap) { +Texture* BakedOpRenderer::getTexture(Bitmap* bitmap) { return mCaches.textureCache.get(bitmap); } diff --git a/libs/hwui/BakedOpRenderer.h b/libs/hwui/BakedOpRenderer.h index 62bc564a4a2a..4d76a3df7a62 100644 --- a/libs/hwui/BakedOpRenderer.h +++ b/libs/hwui/BakedOpRenderer.h @@ -74,7 +74,7 @@ public: void endLayer(); WARN_UNUSED_RESULT OffscreenBuffer* copyToLayer(const Rect& area); - Texture* getTexture(const SkBitmap* bitmap); + Texture* getTexture(Bitmap* bitmap); const LightInfo& getLightInfo() const { return mLightInfo; } void renderGlop(const BakedOpState& state, const Glop& glop) { diff --git a/libs/hwui/DisplayList.cpp b/libs/hwui/DisplayList.cpp index 6e7d11fa0f02..5213d4857e5b 100644 --- a/libs/hwui/DisplayList.cpp +++ b/libs/hwui/DisplayList.cpp @@ -106,9 +106,9 @@ void DisplayList::updateChildren(std::function<void(RenderNode*)> updateFn) { bool DisplayList::prepareListAndChildren(TreeInfo& info, bool functorsNeedLayer, std::function<void(RenderNode*, TreeInfo&, bool)> childFn) { TextureCache& cache = Caches::getInstance().textureCache; - for (auto&& bitmapResource : bitmapResources) { + for (auto& bitmapResource : bitmapResources) { void* ownerToken = &info.canvasContext; - info.prepareTextures = cache.prefetchAndMarkInUse(ownerToken, bitmapResource); + info.prepareTextures = cache.prefetchAndMarkInUse(ownerToken, bitmapResource.get()); } for (auto&& op : children) { RenderNode* childNode = op->renderNode; diff --git a/libs/hwui/DisplayList.h b/libs/hwui/DisplayList.h index 06b08919732f..cab092ffc34c 100644 --- a/libs/hwui/DisplayList.h +++ b/libs/hwui/DisplayList.h @@ -38,6 +38,7 @@ #include "Matrix.h" #include "RenderProperties.h" #include "TreeInfo.h" +#include "hwui/Bitmap.h" #include <vector> @@ -101,7 +102,7 @@ public: const LsaVector<NodeOpType*>& getChildren() const { return children; } - const LsaVector<const SkBitmap*>& getBitmapResources() const { return bitmapResources; } + const LsaVector<sk_sp<Bitmap>>& getBitmapResources() const { return bitmapResources; } size_t addChild(NodeOpType* childOp); @@ -140,7 +141,7 @@ private: LsaVector<NodeOpType*> children; // Resources - Skia objects + 9 patches referred to by this DisplayList - LsaVector<const SkBitmap*> bitmapResources; + LsaVector<sk_sp<Bitmap>> bitmapResources; LsaVector<const SkPath*> pathResources; LsaVector<const Res_png_9patch*> patchResources; LsaVector<std::unique_ptr<const SkPaint>> paints; diff --git a/libs/hwui/FrameBuilder.cpp b/libs/hwui/FrameBuilder.cpp index f2ae847b1952..245db1dcec97 100644 --- a/libs/hwui/FrameBuilder.cpp +++ b/libs/hwui/FrameBuilder.cpp @@ -631,15 +631,13 @@ void FrameBuilder::deferBitmapRectOp(const BitmapRectOp& op) { } void FrameBuilder::deferVectorDrawableOp(const VectorDrawableOp& op) { - SkBitmap bitmap; - op.vectorDrawable->getBitmapUpdateIfDirty().getSkBitmap(&bitmap); - SkBitmap* localBitmap = mAllocator.create<SkBitmap>(bitmap); + Bitmap& bitmap = op.vectorDrawable->getBitmapUpdateIfDirty(); SkPaint* paint = op.vectorDrawable->getPaint(); const BitmapRectOp* resolvedOp = mAllocator.create_trivial<BitmapRectOp>(op.unmappedBounds, op.localMatrix, op.localClip, paint, - localBitmap, + &bitmap, Rect(bitmap.width(), bitmap.height())); deferBitmapRectOp(*resolvedOp); } diff --git a/libs/hwui/RecordedOp.h b/libs/hwui/RecordedOp.h index 3b1caa58ab04..f9a7c36f2786 100644 --- a/libs/hwui/RecordedOp.h +++ b/libs/hwui/RecordedOp.h @@ -211,14 +211,14 @@ struct ArcOp : RecordedOp { }; struct BitmapOp : RecordedOp { - BitmapOp(BASE_PARAMS, const SkBitmap* bitmap) + BitmapOp(BASE_PARAMS, Bitmap* bitmap) : SUPER(BitmapOp) , bitmap(bitmap) {} - const SkBitmap* bitmap; + Bitmap* bitmap; }; struct BitmapMeshOp : RecordedOp { - BitmapMeshOp(BASE_PARAMS, const SkBitmap* bitmap, int meshWidth, int meshHeight, + BitmapMeshOp(BASE_PARAMS, Bitmap* bitmap, int meshWidth, int meshHeight, const float* vertices, const int* colors) : SUPER(BitmapMeshOp) , bitmap(bitmap) @@ -226,7 +226,7 @@ struct BitmapMeshOp : RecordedOp { , meshHeight(meshHeight) , vertices(vertices) , colors(colors) {} - const SkBitmap* bitmap; + Bitmap* bitmap; const int meshWidth; const int meshHeight; const float* vertices; @@ -234,11 +234,11 @@ struct BitmapMeshOp : RecordedOp { }; struct BitmapRectOp : RecordedOp { - BitmapRectOp(BASE_PARAMS, const SkBitmap* bitmap, const Rect& src) + BitmapRectOp(BASE_PARAMS, Bitmap* bitmap, const Rect& src) : SUPER(BitmapRectOp) , bitmap(bitmap) , src(src) {} - const SkBitmap* bitmap; + Bitmap* bitmap; const Rect src; }; @@ -288,11 +288,11 @@ struct OvalOp : RecordedOp { }; struct PatchOp : RecordedOp { - PatchOp(BASE_PARAMS, const SkBitmap* bitmap, const Res_png_9patch* patch) + PatchOp(BASE_PARAMS, Bitmap* bitmap, const Res_png_9patch* patch) : SUPER(PatchOp) , bitmap(bitmap) , patch(patch) {} - const SkBitmap* bitmap; + Bitmap* bitmap; const Res_png_9patch* patch; }; diff --git a/libs/hwui/RecordingCanvas.cpp b/libs/hwui/RecordingCanvas.cpp index d25202690c19..f5bcba284e2b 100644 --- a/libs/hwui/RecordingCanvas.cpp +++ b/libs/hwui/RecordingCanvas.cpp @@ -21,7 +21,6 @@ #include "RenderNode.h" #include "VectorDrawable.h" #include "hwui/MinikinUtils.h" -#include "hwui/Bitmap.h" namespace android { namespace uirenderer { @@ -470,20 +469,16 @@ void RecordingCanvas::drawVectorDrawable(VectorDrawableRoot* tree) { // Bitmap-based void RecordingCanvas::drawBitmap(Bitmap& bitmap, float left, float top, const SkPaint* paint) { - SkBitmap skBitmap; - bitmap.getSkBitmap(&skBitmap); save(SaveFlags::Matrix); translate(left, top); - drawBitmap(&skBitmap, paint); + drawBitmap(bitmap, paint); restore(); } -void RecordingCanvas::drawBitmap(Bitmap& hwuiBitmap, const SkMatrix& matrix, +void RecordingCanvas::drawBitmap(Bitmap& bitmap, const SkMatrix& matrix, const SkPaint* paint) { - SkBitmap bitmap; - hwuiBitmap.getSkBitmap(&bitmap); if (matrix.isIdentity()) { - drawBitmap(&bitmap, paint); + drawBitmap(bitmap, paint); } else if (!(matrix.getType() & ~(SkMatrix::kScale_Mask | SkMatrix::kTranslate_Mask)) && MathUtils::isPositive(matrix.getScaleX()) && MathUtils::isPositive(matrix.getScaleY())) { @@ -492,21 +487,19 @@ void RecordingCanvas::drawBitmap(Bitmap& hwuiBitmap, const SkMatrix& matrix, SkRect dst; bitmap.getBounds(&src); matrix.mapRect(&dst, src); - drawBitmap(hwuiBitmap, src.fLeft, src.fTop, src.fRight, src.fBottom, + drawBitmap(bitmap, src.fLeft, src.fTop, src.fRight, src.fBottom, dst.fLeft, dst.fTop, dst.fRight, dst.fBottom, paint); } else { save(SaveFlags::Matrix); concat(matrix); - drawBitmap(&bitmap, paint); + drawBitmap(bitmap, paint); restore(); } } -void RecordingCanvas::drawBitmap(Bitmap& hwuiBitmap, float srcLeft, float srcTop, +void RecordingCanvas::drawBitmap(Bitmap& bitmap, float srcLeft, float srcTop, float srcRight, float srcBottom, float dstLeft, float dstTop, float dstRight, float dstBottom, const SkPaint* paint) { - SkBitmap bitmap; - hwuiBitmap.getSkBitmap(&bitmap); if (srcLeft == 0 && srcTop == 0 && srcRight == bitmap.width() && srcBottom == bitmap.height() @@ -515,7 +508,7 @@ void RecordingCanvas::drawBitmap(Bitmap& hwuiBitmap, float srcLeft, float srcTop // transform simple rect to rect drawing case into position bitmap ops, since they merge save(SaveFlags::Matrix); translate(dstLeft, dstTop); - drawBitmap(&bitmap, paint); + drawBitmap(bitmap, paint); restore(); } else { addOp(alloc().create_trivial<BitmapRectOp>( @@ -527,7 +520,7 @@ void RecordingCanvas::drawBitmap(Bitmap& hwuiBitmap, float srcLeft, float srcTop } } -void RecordingCanvas::drawBitmapMesh(const SkBitmap& bitmap, int meshWidth, int meshHeight, +void RecordingCanvas::drawBitmapMesh(Bitmap& bitmap, int meshWidth, int meshHeight, const float* vertices, const int* colors, const SkPaint* paint) { int vertexCount = (meshWidth + 1) * (meshHeight + 1); addOp(alloc().create_trivial<BitmapMeshOp>( @@ -539,7 +532,7 @@ void RecordingCanvas::drawBitmapMesh(const SkBitmap& bitmap, int meshWidth, int refBuffer<int>(colors, vertexCount))); // 1 color per vertex } -void RecordingCanvas::drawNinePatch(const SkBitmap& bitmap, const android::Res_png_9patch& patch, +void RecordingCanvas::drawNinePatch(Bitmap& bitmap, const android::Res_png_9patch& patch, float dstLeft, float dstTop, float dstRight, float dstBottom, const SkPaint* paint) { addOp(alloc().create_trivial<PatchOp>( @@ -582,12 +575,12 @@ void RecordingCanvas::drawLayoutOnPath(const minikin::Layout& layout, float hOff } } -void RecordingCanvas::drawBitmap(const SkBitmap* bitmap, const SkPaint* paint) { +void RecordingCanvas::drawBitmap(Bitmap& bitmap, const SkPaint* paint) { addOp(alloc().create_trivial<BitmapOp>( - Rect(bitmap->width(), bitmap->height()), + Rect(bitmap.width(), bitmap.height()), *(mState.currentSnapshot()->transform), getRecordedClip(), - refPaint(paint), refBitmap(*bitmap))); + refPaint(paint), refBitmap(bitmap))); } void RecordingCanvas::drawRenderNode(RenderNode* renderNode) { @@ -673,7 +666,9 @@ void RecordingCanvas::refBitmapsInShader(const SkShader* shader) { SkBitmap bitmap; SkShader::TileMode xy[2]; if (shader->isABitmap(&bitmap, nullptr, xy)) { - refBitmap(bitmap); + // TODO: create hwui-owned BitmapShader. + Bitmap* hwuiBitmap = static_cast<Bitmap*>(bitmap.pixelRef()); + refBitmap(*hwuiBitmap); return; } SkShader::ComposeRec rec; diff --git a/libs/hwui/RecordingCanvas.h b/libs/hwui/RecordingCanvas.h index cdb8dfc2002d..a8fcfeba8e04 100644 --- a/libs/hwui/RecordingCanvas.h +++ b/libs/hwui/RecordingCanvas.h @@ -22,6 +22,7 @@ #include "ResourceCache.h" #include "SkiaCanvasProxy.h" #include "Snapshot.h" +#include "hwui/Bitmap.h" #include "hwui/Canvas.h" #include "utils/LinearAllocator.h" #include "utils/Macros.h" @@ -181,9 +182,9 @@ public: virtual void drawBitmap(Bitmap& bitmap, float srcLeft, float srcTop, float srcRight, float srcBottom, float dstLeft, float dstTop, float dstRight, float dstBottom, const SkPaint* paint) override; - virtual void drawBitmapMesh(const SkBitmap& bitmap, int meshWidth, int meshHeight, + virtual void drawBitmapMesh(Bitmap& bitmap, int meshWidth, int meshHeight, const float* vertices, const int* colors, const SkPaint* paint) override; - virtual void drawNinePatch(const SkBitmap& bitmap, const android::Res_png_9patch& chunk, + virtual void drawNinePatch(Bitmap& bitmap, const android::Res_png_9patch& chunk, float dstLeft, float dstTop, float dstRight, float dstBottom, const SkPaint* paint) override; @@ -203,7 +204,7 @@ private: return mState.writableSnapshot()->mutateClipArea().serializeClip(alloc()); } - void drawBitmap(const SkBitmap* bitmap, const SkPaint* paint); + void drawBitmap(Bitmap& bitmap, const SkPaint* paint); void drawSimpleRects(const float* rects, int vertexCount, const SkPaint* paint); @@ -285,14 +286,17 @@ private: return cachedRegion; } - inline const SkBitmap* refBitmap(const SkBitmap& bitmap) { + inline Bitmap* refBitmap(Bitmap& bitmap) { // Note that this assumes the bitmap is immutable. There are cases this won't handle // correctly, such as creating the bitmap from scratch, drawing with it, changing its // contents, and drawing again. The only fix would be to always copy it the first time, // which doesn't seem worth the extra cycles for this unlikely case. - SkBitmap* localBitmap = alloc().create<SkBitmap>(bitmap); - mDisplayList->bitmapResources.push_back(localBitmap); - return localBitmap; + + // this is required because sk_sp's ctor adopts the pointer, + // but does not increment the refcount, + bitmap.ref(); + mDisplayList->bitmapResources.emplace_back(&bitmap); + return &bitmap; } inline const Res_png_9patch* refPatch(const Res_png_9patch* patch) { diff --git a/libs/hwui/SkiaCanvas.cpp b/libs/hwui/SkiaCanvas.cpp index ab899f9f831c..50c9a57eaca7 100644 --- a/libs/hwui/SkiaCanvas.cpp +++ b/libs/hwui/SkiaCanvas.cpp @@ -515,9 +515,10 @@ void SkiaCanvas::drawBitmap(Bitmap& hwuiBitmap, float srcLeft, float srcTop, mCanvas->drawBitmapRect(bitmap, srcRect, dstRect, paint); } -void SkiaCanvas::drawBitmapMesh(const SkBitmap& bitmap, int meshWidth, int meshHeight, +void SkiaCanvas::drawBitmapMesh(Bitmap& hwuiBitmap, int meshWidth, int meshHeight, const float* vertices, const int* colors, const SkPaint* paint) { - + SkBitmap bitmap; + hwuiBitmap.getSkBitmap(&bitmap); const int ptCount = (meshWidth + 1) * (meshHeight + 1); const int indexCount = meshWidth * meshHeight * 6; @@ -615,8 +616,10 @@ void SkiaCanvas::drawBitmapMesh(const SkBitmap& bitmap, int meshWidth, int meshH indexCount, tmpPaint); } -void SkiaCanvas::drawNinePatch(const SkBitmap& bitmap, const Res_png_9patch& chunk, +void SkiaCanvas::drawNinePatch(Bitmap& hwuiBitmap, const Res_png_9patch& chunk, float dstLeft, float dstTop, float dstRight, float dstBottom, const SkPaint* paint) { + SkBitmap bitmap; + hwuiBitmap.getSkBitmap(&bitmap); SkRect bounds = SkRect::MakeLTRB(dstLeft, dstTop, dstRight, dstBottom); NinePatch::Draw(mCanvas.get(), bounds, bitmap, chunk, paint, nullptr); } diff --git a/libs/hwui/SkiaCanvas.h b/libs/hwui/SkiaCanvas.h index 49aea8e5e35a..40772dd354f1 100644 --- a/libs/hwui/SkiaCanvas.h +++ b/libs/hwui/SkiaCanvas.h @@ -129,9 +129,9 @@ public: virtual void drawBitmap(Bitmap& bitmap, float srcLeft, float srcTop, float srcRight, float srcBottom, float dstLeft, float dstTop, float dstRight, float dstBottom, const SkPaint* paint) override; - virtual void drawBitmapMesh(const SkBitmap& bitmap, int meshWidth, int meshHeight, + virtual void drawBitmapMesh(Bitmap& bitmap, int meshWidth, int meshHeight, const float* vertices, const int* colors, const SkPaint* paint) override; - virtual void drawNinePatch(const SkBitmap& bitmap, const android::Res_png_9patch& chunk, + virtual void drawNinePatch(Bitmap& bitmap, const android::Res_png_9patch& chunk, float dstLeft, float dstTop, float dstRight, float dstBottom, const SkPaint* paint) override; diff --git a/libs/hwui/SkiaShader.cpp b/libs/hwui/SkiaShader.cpp index 5d9e5c035283..489a306c13d1 100644 --- a/libs/hwui/SkiaShader.cpp +++ b/libs/hwui/SkiaShader.cpp @@ -21,6 +21,7 @@ #include "Layer.h" #include "Matrix.h" #include "Texture.h" +#include "hwui/Bitmap.h" #include <SkMatrix.h> #include <utils/Log.h> @@ -206,7 +207,9 @@ bool tryStoreBitmap(Caches& caches, const SkShader& shader, const Matrix4& model return false; } - outData->bitmapTexture = caches.textureCache.get(&bitmap); + // TODO: create hwui-owned BitmapShader. + Bitmap* hwuiBitmap = static_cast<Bitmap*>(bitmap.pixelRef()); + outData->bitmapTexture = caches.textureCache.get(hwuiBitmap); if (!outData->bitmapTexture) return false; outData->bitmapSampler = (*textureUnit)++; diff --git a/libs/hwui/TextureCache.cpp b/libs/hwui/TextureCache.cpp index 5ccdbda67e74..08641b7234dd 100644 --- a/libs/hwui/TextureCache.cpp +++ b/libs/hwui/TextureCache.cpp @@ -23,6 +23,7 @@ #include "TextureCache.h" #include "Properties.h" #include "utils/TraceUtils.h" +#include "hwui/Bitmap.h" namespace android { namespace uirenderer { @@ -91,7 +92,7 @@ void TextureCache::resetMarkInUse(void* ownerToken) { } } -bool TextureCache::canMakeTextureFromBitmap(const SkBitmap* bitmap) { +bool TextureCache::canMakeTextureFromBitmap(Bitmap* bitmap) { if (bitmap->width() > mMaxTextureSize || bitmap->height() > mMaxTextureSize) { ALOGW("Bitmap too large to be uploaded into a texture (%dx%d, max=%dx%d)", bitmap->width(), bitmap->height(), mMaxTextureSize, mMaxTextureSize); @@ -102,8 +103,8 @@ bool TextureCache::canMakeTextureFromBitmap(const SkBitmap* bitmap) { // Returns a prepared Texture* that either is already in the cache or can fit // in the cache (and is thus added to the cache) -Texture* TextureCache::getCachedTexture(const SkBitmap* bitmap) { - Texture* texture = mCache.get(bitmap->pixelRef()->getStableID()); +Texture* TextureCache::getCachedTexture(Bitmap* bitmap) { + Texture* texture = mCache.get(bitmap->getStableID()); if (!texture) { if (!canMakeTextureFromBitmap(bitmap)) { @@ -126,7 +127,9 @@ Texture* TextureCache::getCachedTexture(const SkBitmap* bitmap) { texture = new Texture(Caches::getInstance()); texture->bitmapSize = size; texture->generation = bitmap->getGenerationID(); - texture->upload(*bitmap); + SkBitmap skBitmap; + bitmap->getSkBitmap(&skBitmap); + texture->upload(skBitmap); mSize += size; TEXTURE_LOGD("TextureCache::get: create texture(%p): name, size, mSize = %d, %d, %d", @@ -134,19 +137,21 @@ Texture* TextureCache::getCachedTexture(const SkBitmap* bitmap) { if (mDebugEnabled) { ALOGD("Texture created, size = %d", size); } - mCache.put(bitmap->pixelRef()->getStableID(), texture); + mCache.put(bitmap->getStableID(), texture); } } else if (!texture->isInUse && bitmap->getGenerationID() != texture->generation) { // Texture was in the cache but is dirty, re-upload // TODO: Re-adjust the cache size if the bitmap's dimensions have changed - texture->upload(*bitmap); + SkBitmap skBitmap; + bitmap->getSkBitmap(&skBitmap); + texture->upload(skBitmap); texture->generation = bitmap->getGenerationID(); } return texture; } -bool TextureCache::prefetchAndMarkInUse(void* ownerToken, const SkBitmap* bitmap) { +bool TextureCache::prefetchAndMarkInUse(void* ownerToken, Bitmap* bitmap) { Texture* texture = getCachedTexture(bitmap); if (texture) { texture->isInUse = ownerToken; @@ -154,11 +159,11 @@ bool TextureCache::prefetchAndMarkInUse(void* ownerToken, const SkBitmap* bitmap return texture; } -bool TextureCache::prefetch(const SkBitmap* bitmap) { +bool TextureCache::prefetch(Bitmap* bitmap) { return getCachedTexture(bitmap); } -Texture* TextureCache::get(const SkBitmap* bitmap) { +Texture* TextureCache::get(Bitmap* bitmap) { Texture* texture = getCachedTexture(bitmap); if (!texture) { @@ -169,7 +174,9 @@ Texture* TextureCache::get(const SkBitmap* bitmap) { const uint32_t size = bitmap->rowBytes() * bitmap->height(); texture = new Texture(Caches::getInstance()); texture->bitmapSize = size; - texture->upload(*bitmap); + SkBitmap skBitmap; + bitmap->getSkBitmap(&skBitmap); + texture->upload(skBitmap); texture->generation = bitmap->getGenerationID(); texture->cleanup = true; } diff --git a/libs/hwui/TextureCache.h b/libs/hwui/TextureCache.h index 88ef7711e844..68a548bdb1ff 100644 --- a/libs/hwui/TextureCache.h +++ b/libs/hwui/TextureCache.h @@ -28,6 +28,9 @@ #include <unordered_map> namespace android { + +class Bitmap; + namespace uirenderer { class Texture; @@ -73,20 +76,20 @@ public: * acquired for the bitmap, false otherwise. If a Texture was acquired it is * marked as in use. */ - bool prefetchAndMarkInUse(void* ownerToken, const SkBitmap* bitmap); + bool prefetchAndMarkInUse(void* ownerToken, Bitmap* bitmap); /** * Attempts to precache the SkBitmap. Returns true if a Texture was successfully * acquired for the bitmap, false otherwise. Does not mark the Texture * as in use and won't update currently in-use Textures. */ - bool prefetch(const SkBitmap* bitmap); + bool prefetch(Bitmap* bitmap); /** * Returns the texture associated with the specified bitmap from within the cache. * If the texture cannot be found in the cache, a new texture is generated. */ - Texture* get(const SkBitmap* bitmap); + Texture* get(Bitmap* bitmap); /** * Removes the texture associated with the specified pixelRef. This is meant @@ -119,9 +122,9 @@ public: void flush(); private: - bool canMakeTextureFromBitmap(const SkBitmap* bitmap); + bool canMakeTextureFromBitmap(Bitmap* bitmap); - Texture* getCachedTexture(const SkBitmap* bitmap); + Texture* getCachedTexture(Bitmap* bitmap); LruCache<uint32_t, Texture*> mCache; diff --git a/libs/hwui/hwui/Bitmap.cpp b/libs/hwui/hwui/Bitmap.cpp index d9534f2c4fec..31fbe68078c0 100644 --- a/libs/hwui/hwui/Bitmap.cpp +++ b/libs/hwui/hwui/Bitmap.cpp @@ -269,4 +269,9 @@ void Bitmap::getSkBitmap(SkBitmap* outBitmap) { outBitmap->setHasHardwareMipMap(mHasHardwareMipMap); } +void Bitmap::getBounds(SkRect* bounds) const { + SkASSERT(bounds); + bounds->set(0, 0, SkIntToScalar(info().width()), SkIntToScalar(info().height())); +} + } // namespace android
\ No newline at end of file diff --git a/libs/hwui/hwui/Bitmap.h b/libs/hwui/hwui/Bitmap.h index 029d80d6279f..e86ac11673c5 100644 --- a/libs/hwui/hwui/Bitmap.h +++ b/libs/hwui/hwui/Bitmap.h @@ -69,6 +69,10 @@ public: void setHasHardwareMipMap(bool hasMipMap); bool hasHardwareMipMap() const; + bool isOpaque() const {return info().isOpaque(); } + SkColorType colorType() const { return info().colorType(); } + void getBounds(SkRect* bounds) const; + protected: virtual bool onNewLockPixels(LockRec* rec) override; virtual void onUnlockPixels() override { }; diff --git a/libs/hwui/hwui/Canvas.h b/libs/hwui/hwui/Canvas.h index baee8fdabf90..f275ce1e9210 100644 --- a/libs/hwui/hwui/Canvas.h +++ b/libs/hwui/hwui/Canvas.h @@ -225,9 +225,9 @@ public: virtual void drawBitmap(Bitmap& bitmap, float srcLeft, float srcTop, float srcRight, float srcBottom, float dstLeft, float dstTop, float dstRight, float dstBottom, const SkPaint* paint) = 0; - virtual void drawBitmapMesh(const SkBitmap& bitmap, int meshWidth, int meshHeight, + virtual void drawBitmapMesh(Bitmap& bitmap, int meshWidth, int meshHeight, const float* vertices, const int* colors, const SkPaint* paint) = 0; - virtual void drawNinePatch(const SkBitmap& bitmap, const android::Res_png_9patch& chunk, + virtual void drawNinePatch(Bitmap& bitmap, const android::Res_png_9patch& chunk, float dstLeft, float dstTop, float dstRight, float dstBottom, const SkPaint* paint) = 0; diff --git a/libs/hwui/renderthread/RenderProxy.cpp b/libs/hwui/renderthread/RenderProxy.cpp index c2ed8643c0ad..42da293021b9 100644 --- a/libs/hwui/renderthread/RenderProxy.cpp +++ b/libs/hwui/renderthread/RenderProxy.cpp @@ -617,17 +617,17 @@ int RenderProxy::copySurfaceInto(sp<Surface>& surface, int left, int top, reinterpret_cast<intptr_t>( staticPostAndWait(task) )); } -CREATE_BRIDGE2(prepareToDraw, RenderThread* thread, SkBitmap* bitmap) { +CREATE_BRIDGE2(prepareToDraw, RenderThread* thread, Bitmap* bitmap) { if (Caches::hasInstance() && args->thread->eglManager().hasEglContext()) { ATRACE_NAME("Bitmap#prepareToDraw task"); Caches::getInstance().textureCache.prefetch(args->bitmap); } - delete args->bitmap; + args->bitmap->unref(); args->bitmap = nullptr; return nullptr; } -void RenderProxy::prepareToDraw(const SkBitmap& bitmap) { +void RenderProxy::prepareToDraw(Bitmap& bitmap) { // If we haven't spun up a hardware accelerated window yet, there's no // point in precaching these bitmaps as it can't impact jank. // We also don't know if we even will spin up a hardware-accelerated @@ -636,7 +636,8 @@ void RenderProxy::prepareToDraw(const SkBitmap& bitmap) { RenderThread* renderThread = &RenderThread::getInstance(); SETUP_TASK(prepareToDraw); args->thread = renderThread; - args->bitmap = new SkBitmap(bitmap); + bitmap.ref(); + args->bitmap = &bitmap; nsecs_t lastVsync = renderThread->timeLord().latestVsync(); nsecs_t estimatedNextVsync = lastVsync + renderThread->timeLord().frameIntervalNanos(); nsecs_t timeToNextVsync = estimatedNextVsync - systemTime(CLOCK_MONOTONIC); diff --git a/libs/hwui/renderthread/RenderProxy.h b/libs/hwui/renderthread/RenderProxy.h index 50a6f64fe5ca..ae9330ddccf2 100644 --- a/libs/hwui/renderthread/RenderProxy.h +++ b/libs/hwui/renderthread/RenderProxy.h @@ -128,7 +128,7 @@ public: ANDROID_API static int copySurfaceInto(sp<Surface>& surface, int left, int top, int right, int bottom, SkBitmap* bitmap); - ANDROID_API static void prepareToDraw(const SkBitmap& bitmap); + ANDROID_API static void prepareToDraw(Bitmap& bitmap); private: RenderThread& mRenderThread; diff --git a/libs/hwui/tests/common/TestUtils.h b/libs/hwui/tests/common/TestUtils.h index b8dfb011ff13..cdaa705ed387 100644 --- a/libs/hwui/tests/common/TestUtils.h +++ b/libs/hwui/tests/common/TestUtils.h @@ -134,17 +134,6 @@ public: return Bitmap::allocateHeapBitmap(outBitmap, nullptr); } - static SkBitmap createSkBitmap(int width, int height, - SkColorType colorType = kN32_SkColorType) { - SkBitmap bitmap; - sk_sp<SkColorSpace> colorSpace = SkColorSpace::NewNamed(SkColorSpace::kSRGB_Named); - SkImageInfo info = SkImageInfo::Make(width, height, - colorType, kPremul_SkAlphaType, colorSpace); - bitmap.setInfo(info); - Bitmap::allocateHeapBitmap(&bitmap, nullptr); - return bitmap; - } - static sp<DeferredLayerUpdater> createTextureLayerUpdater( renderthread::RenderThread& renderThread, uint32_t width, uint32_t height, const SkMatrix& transform); diff --git a/libs/hwui/tests/unit/FrameBuilderTests.cpp b/libs/hwui/tests/unit/FrameBuilderTests.cpp index fb6067d889fb..01046e1ecad9 100644 --- a/libs/hwui/tests/unit/FrameBuilderTests.cpp +++ b/libs/hwui/tests/unit/FrameBuilderTests.cpp @@ -403,10 +403,10 @@ RENDERTHREAD_TEST(FrameBuilder, avoidOverdraw_bitmaps) { void onBitmapOp(const BitmapOp& op, const BakedOpState& state) override { switch(mIndex++) { case 0: - EXPECT_EQ(opaqueBitmap.get(), op.bitmap->pixelRef()); + EXPECT_EQ(opaqueBitmap.get(), op.bitmap); break; case 1: - EXPECT_EQ(transpBitmap.get(), op.bitmap->pixelRef()); + EXPECT_EQ(transpBitmap.get(), op.bitmap); break; default: ADD_FAILURE() << "Only two ops expected."; diff --git a/libs/hwui/tests/unit/RecordingCanvasTests.cpp b/libs/hwui/tests/unit/RecordingCanvasTests.cpp index 3bfbf12f2003..134497c63eaa 100644 --- a/libs/hwui/tests/unit/RecordingCanvasTests.cpp +++ b/libs/hwui/tests/unit/RecordingCanvasTests.cpp @@ -736,10 +736,12 @@ TEST(RecordingCanvas, refBitmap) { } TEST(RecordingCanvas, refBitmapInShader_bitmapShader) { - SkBitmap bitmap = TestUtils::createSkBitmap(100, 100); + sk_sp<Bitmap> bitmap = TestUtils::createBitmap(100, 100); auto dl = TestUtils::createDisplayList<RecordingCanvas>(100, 100, [&bitmap](RecordingCanvas& canvas) { SkPaint paint; - sk_sp<SkShader> shader = SkMakeBitmapShader(bitmap, + SkBitmap skBitmap; + bitmap->getSkBitmap(&skBitmap); + sk_sp<SkShader> shader = SkMakeBitmapShader(skBitmap, SkShader::TileMode::kClamp_TileMode, SkShader::TileMode::kClamp_TileMode, nullptr, @@ -753,10 +755,12 @@ TEST(RecordingCanvas, refBitmapInShader_bitmapShader) { } TEST(RecordingCanvas, refBitmapInShader_composeShader) { - SkBitmap bitmap = TestUtils::createSkBitmap(100, 100); + sk_sp<Bitmap> bitmap = TestUtils::createBitmap(100, 100); auto dl = TestUtils::createDisplayList<RecordingCanvas>(100, 100, [&bitmap](RecordingCanvas& canvas) { SkPaint paint; - sk_sp<SkShader> shader1 = SkMakeBitmapShader(bitmap, + SkBitmap skBitmap; + bitmap->getSkBitmap(&skBitmap); + sk_sp<SkShader> shader1 = SkMakeBitmapShader(skBitmap, SkShader::TileMode::kClamp_TileMode, SkShader::TileMode::kClamp_TileMode, nullptr, diff --git a/packages/SettingsProvider/res/values/defaults.xml b/packages/SettingsProvider/res/values/defaults.xml index 977ac18df8ac..bb85de2a32a6 100644 --- a/packages/SettingsProvider/res/values/defaults.xml +++ b/packages/SettingsProvider/res/values/defaults.xml @@ -69,6 +69,7 @@ <integer name="def_power_sounds_enabled">1</integer> <string name="def_low_battery_sound" translatable="false">/system/media/audio/ui/LowBattery.ogg</string> <integer name="def_dock_sounds_enabled">0</integer> + <integer name="def_dock_sounds_enabled_when_accessibility">0</integer> <string name="def_desk_dock_sound" translatable="false">/system/media/audio/ui/Dock.ogg</string> <string name="def_desk_undock_sound" translatable="false">/system/media/audio/ui/Undock.ogg</string> <string name="def_car_dock_sound" translatable="false">/system/media/audio/ui/Dock.ogg</string> diff --git a/packages/SettingsProvider/src/com/android/providers/settings/DatabaseHelper.java b/packages/SettingsProvider/src/com/android/providers/settings/DatabaseHelper.java index c1a1f844f6d9..d55bb4f44aa5 100644 --- a/packages/SettingsProvider/src/com/android/providers/settings/DatabaseHelper.java +++ b/packages/SettingsProvider/src/com/android/providers/settings/DatabaseHelper.java @@ -2662,6 +2662,8 @@ class DatabaseHelper extends SQLiteOpenHelper { R.string.def_low_battery_sound); loadIntegerSetting(stmt, Settings.Global.DOCK_SOUNDS_ENABLED, R.integer.def_dock_sounds_enabled); + loadIntegerSetting(stmt, Settings.Global.DOCK_SOUNDS_ENABLED_WHEN_ACCESSIBILITY, + R.integer.def_dock_sounds_enabled_when_accessibility); loadStringSetting(stmt, Settings.Global.DESK_DOCK_SOUND, R.string.def_desk_dock_sound); loadStringSetting(stmt, Settings.Global.DESK_UNDOCK_SOUND, diff --git a/services/core/java/com/android/server/DockObserver.java b/services/core/java/com/android/server/DockObserver.java index 07aa565642c6..122074ba4dac 100644 --- a/services/core/java/com/android/server/DockObserver.java +++ b/services/core/java/com/android/server/DockObserver.java @@ -167,10 +167,17 @@ final class DockObserver extends SystemService { intent.addFlags(Intent.FLAG_RECEIVER_REPLACE_PENDING); intent.putExtra(Intent.EXTRA_DOCK_STATE, mReportedDockState); + boolean dockSoundsEnabled = Settings.Global.getInt(cr, + Settings.Global.DOCK_SOUNDS_ENABLED, 1) == 1; + boolean dockSoundsEnabledWhenAccessibility = Settings.Global.getInt(cr, + Settings.Global.DOCK_SOUNDS_ENABLED_WHEN_ACCESSIBILITY, 1) == 1; + boolean accessibilityEnabled = Settings.Secure.getInt(cr, + Settings.Secure.ACCESSIBILITY_ENABLED, 0) == 1; + // Play a sound to provide feedback to confirm dock connection. // Particularly useful for flaky contact pins... - if (Settings.Global.getInt(cr, - Settings.Global.DOCK_SOUNDS_ENABLED, 1) == 1) { + if ((dockSoundsEnabled) || + (accessibilityEnabled && dockSoundsEnabledWhenAccessibility)) { String whichSound = null; if (mReportedDockState == Intent.EXTRA_DOCK_STATE_UNDOCKED) { if ((previousDockState == Intent.EXTRA_DOCK_STATE_DESK) || diff --git a/tools/bit/main.cpp b/tools/bit/main.cpp index 04836adf2288..4974a447be91 100644 --- a/tools/bit/main.cpp +++ b/tools/bit/main.cpp @@ -518,14 +518,17 @@ get_out_dir() // makes all the filenames long when being pretty printed. return "out"; } else { - char* pwd = get_current_dir_name(); + char pwd[PATH_MAX]; + if (getcwd(pwd, PATH_MAX) == NULL) { + fprintf(stderr, "Your pwd is too long.\n"); + exit(1); + } const char* slash = strrchr(pwd, '/'); if (slash == NULL) { slash = ""; } string result(common_base); result += slash; - free(pwd); return result; } } |