Merge "Merge "Docs: Added instructions to launch instrumented tests in AS using CTL" into mnc-mr-docs am: 7961413 am: 88d1e91 am: 8776f89" into nyc-dev
diff --git a/core/java/android/view/DisplayListCanvas.java b/core/java/android/view/DisplayListCanvas.java
index 415c291..cb7c5a2 100644
--- a/core/java/android/view/DisplayListCanvas.java
+++ b/core/java/android/view/DisplayListCanvas.java
@@ -37,6 +37,8 @@
     // view hierarchy because display lists are generated recursively.
     private static final int POOL_LIMIT = 25;
 
+    private static final int MAX_BITMAP_SIZE = 100 * 1024 * 1024; // 100 MB
+
     private static final SynchronizedPool<DisplayListCanvas> sPool =
             new SynchronizedPool<DisplayListCanvas>(POOL_LIMIT);
 
@@ -249,4 +251,14 @@
 
     private static native void nDrawRoundRect(long renderer, long propLeft, long propTop,
             long propRight, long propBottom, long propRx, long propRy, long propPaint);
+
+    @Override
+    protected void throwIfCannotDraw(Bitmap bitmap) {
+        super.throwIfCannotDraw(bitmap);
+        int bitmapSize = bitmap.getByteCount();
+        if (bitmapSize > MAX_BITMAP_SIZE) {
+            throw new RuntimeException(
+                    "Canvas: trying to draw too large(" + bitmapSize + "bytes) bitmap.");
+        }
+    }
 }
diff --git a/graphics/java/android/graphics/Canvas.java b/graphics/java/android/graphics/Canvas.java
index af99f79..c65880b 100644
--- a/graphics/java/android/graphics/Canvas.java
+++ b/graphics/java/android/graphics/Canvas.java
@@ -1266,7 +1266,7 @@
     /**
      * @hide
      */
-    protected static void throwIfCannotDraw(Bitmap bitmap) {
+    protected void throwIfCannotDraw(Bitmap bitmap) {
         if (bitmap.isRecycled()) {
             throw new RuntimeException("Canvas: trying to use a recycled bitmap " + bitmap);
         }
diff --git a/libs/hwui/BakedOpDispatcher.cpp b/libs/hwui/BakedOpDispatcher.cpp
index 5fb8425..8251ee6 100644
--- a/libs/hwui/BakedOpDispatcher.cpp
+++ b/libs/hwui/BakedOpDispatcher.cpp
@@ -344,7 +344,8 @@
         const SkPaint& paint, int vertexBufferRenderFlags) {
     if (CC_LIKELY(vertexBuffer.getVertexCount())) {
         bool shadowInterp = vertexBufferRenderFlags & VertexBufferRenderFlags::ShadowInterp;
-        const int transformFlags = TransformFlags::OffsetByFudgeFactor;
+        const int transformFlags = vertexBufferRenderFlags & VertexBufferRenderFlags::Offset
+                ? TransformFlags::OffsetByFudgeFactor : 0;
         Glop glop;
         GlopBuilder(renderer.renderState(), renderer.caches(), &glop)
                 .setRoundRectClipState(state.roundRectClipState)
diff --git a/libs/hwui/tests/unit/BakedOpDispatcherTests.cpp b/libs/hwui/tests/unit/BakedOpDispatcherTests.cpp
index 5471486..781f88c 100644
--- a/libs/hwui/tests/unit/BakedOpDispatcherTests.cpp
+++ b/libs/hwui/tests/unit/BakedOpDispatcherTests.cpp
@@ -109,3 +109,37 @@
         EXPECT_FLOAT_EQ(128 / 255.0f, glop.fill.color.a) << "Rect quad should use op alpha";
     });
 }
+
+static int getGlopTransformFlags(renderthread::RenderThread& renderThread, RecordedOp* op) {
+    int result = 0;
+    testUnmergedGlopDispatch(renderThread, op, [&result] (const Glop& glop) {
+        result = glop.transform.transformFlags;
+    });
+    return result;
+}
+
+RENDERTHREAD_TEST(BakedOpDispatcher, offsetFlags) {
+    Rect bounds(10, 15, 20, 25);
+    SkPaint paint;
+    SkPaint aaPaint;
+    aaPaint.setAntiAlias(true);
+
+    RoundRectOp roundRectOp(bounds, Matrix4::identity(), nullptr, &paint, 0, 270);
+    EXPECT_EQ(TransformFlags::None, getGlopTransformFlags(renderThread, &roundRectOp))
+            << "Expect no offset for round rect op.";
+
+    const float points[4] = {0.5, 0.5, 1.0, 1.0};
+    PointsOp antiAliasedPointsOp(bounds, Matrix4::identity(), nullptr, &aaPaint, points, 4);
+    EXPECT_EQ(TransformFlags::None, getGlopTransformFlags(renderThread, &antiAliasedPointsOp))
+                << "Expect no offset for AA points.";
+    PointsOp pointsOp(bounds, Matrix4::identity(), nullptr, &paint, points, 4);
+    EXPECT_EQ(TransformFlags::OffsetByFudgeFactor, getGlopTransformFlags(renderThread, &pointsOp))
+            << "Expect an offset for non-AA points.";
+
+    LinesOp antiAliasedLinesOp(bounds, Matrix4::identity(), nullptr, &aaPaint, points, 4);
+    EXPECT_EQ(TransformFlags::None, getGlopTransformFlags(renderThread, &antiAliasedLinesOp))
+            << "Expect no offset for AA lines.";
+    LinesOp linesOp(bounds, Matrix4::identity(), nullptr, &paint, points, 4);
+    EXPECT_EQ(TransformFlags::OffsetByFudgeFactor, getGlopTransformFlags(renderThread, &linesOp))
+            << "Expect an offset for non-AA lines.";
+}
\ No newline at end of file