Revert "Support downsampling in ViewResourceAdapter"

This reverts commit 2bc512d784405143447c593b80b9728b117cd516.

Reason for revert: Cause of https://crbug.com/966859

Original change's description:
> Support downsampling in ViewResourceAdapter
> 
> Bug: 965609
> Change-Id: I148d5fe8b7371a529b612ed2e9b407ced0062f82
> Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1623139
> Commit-Queue: Wei-Yin Chen (陳威尹) <wychen@chromium.org>
> Reviewed-by: David Trainor <dtrainor@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#662915}

TBR=dtrainor@chromium.org,wychen@chromium.org

Change-Id: I1f97b70d1a5432bb303b5a5daece91daf11899c4
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Bug: 965609
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1629327
Reviewed-by: Brian Sheedy <bsheedy@chromium.org>
Commit-Queue: Brian Sheedy <bsheedy@chromium.org>
Cr-Commit-Position: refs/heads/master@{#663268}
diff --git a/ui/android/java/src/org/chromium/ui/resources/ResourceManager.java b/ui/android/java/src/org/chromium/ui/resources/ResourceManager.java
index 9471e12..2e1fa08 100644
--- a/ui/android/java/src/org/chromium/ui/resources/ResourceManager.java
+++ b/ui/android/java/src/org/chromium/ui/resources/ResourceManager.java
@@ -137,7 +137,6 @@
         if (mNativeResourceManagerPtr == 0) return;
 
         nativeOnResourceReady(mNativeResourceManagerPtr, resType, resId, resource.getBitmap(),
-                resource.getBitmapSize().width(), resource.getBitmapSize().height(),
                 resource.createNativeResource());
     }
 
@@ -194,7 +193,7 @@
     }
 
     private native void nativeOnResourceReady(long nativeResourceManagerImpl, int resType,
-            int resId, Bitmap bitmap, int width, int height, long nativeResource);
+            int resId, Bitmap bitmap, long nativeResource);
     private native void nativeRemoveResource(long nativeResourceManagerImpl, int resType,
             int resId);
     private native void nativeClearTintedResourceCache(long nativeResourceManagerImpl);
diff --git a/ui/android/java/src/org/chromium/ui/resources/dynamics/ViewResourceAdapter.java b/ui/android/java/src/org/chromium/ui/resources/dynamics/ViewResourceAdapter.java
index e9561ae..6e7c9c9 100644
--- a/ui/android/java/src/org/chromium/ui/resources/dynamics/ViewResourceAdapter.java
+++ b/ui/android/java/src/org/chromium/ui/resources/dynamics/ViewResourceAdapter.java
@@ -27,8 +27,7 @@
     private final Rect mDirtyRect = new Rect();
 
     private Bitmap mBitmap;
-    private Rect mViewSize = new Rect();
-    protected float mScale = 1;
+    private Rect mBitmapSize = new Rect();
 
     /**
      * Builds a {@link ViewResourceAdapter} instance around {@code view}.
@@ -72,19 +71,7 @@
 
     @Override
     public Rect getBitmapSize() {
-        return mViewSize;
-    }
-
-    /**
-     * Set the downsampling scale. The rendered size is not affected.
-     * @param scale The scale to use. <1 means the Bitmap is smaller than the View.
-     */
-    public void setDownsamplingScale(float scale) {
-        assert scale <= 1;
-        if (mScale != scale) {
-            invalidate(null);
-        }
-        mScale = scale;
+        return mBitmapSize;
     }
 
     /**
@@ -156,10 +143,7 @@
      * @param canvas The {@link Canvas} that will be drawn to.
      */
     protected void capture(Canvas canvas) {
-        canvas.save();
-        canvas.scale(mScale, mScale);
         mView.draw(canvas);
-        canvas.restore();
     }
 
     /**
@@ -172,8 +156,8 @@
      * @return Whether |mBitmap| is corresponding to |mView| or not.
      */
     private boolean validateBitmap() {
-        int viewWidth = (int) (mView.getWidth() * mScale);
-        int viewHeight = (int) (mView.getHeight() * mScale);
+        int viewWidth = mView.getWidth();
+        int viewHeight = mView.getHeight();
         boolean isEmpty = viewWidth == 0 || viewHeight == 0;
         if (isEmpty) {
             viewWidth = 1;
@@ -188,8 +172,8 @@
         if (mBitmap == null) {
             mBitmap = Bitmap.createBitmap(viewWidth, viewHeight, Bitmap.Config.ARGB_8888);
             mBitmap.setHasAlpha(true);
-            mViewSize.set(0, 0, mView.getWidth(), mView.getHeight());
-            mDirtyRect.set(mViewSize);
+            mDirtyRect.set(0, 0, viewWidth, viewHeight);
+            mBitmapSize.set(0, 0, mBitmap.getWidth(), mBitmap.getHeight());
         }
 
         return !isEmpty;
diff --git a/ui/android/junit/src/org/chromium/ui/resources/dynamics/ViewResourceAdapterTest.java b/ui/android/junit/src/org/chromium/ui/resources/dynamics/ViewResourceAdapterTest.java
index c511853..8661287 100644
--- a/ui/android/junit/src/org/chromium/ui/resources/dynamics/ViewResourceAdapterTest.java
+++ b/ui/android/junit/src/org/chromium/ui/resources/dynamics/ViewResourceAdapterTest.java
@@ -79,19 +79,6 @@
     }
 
     @Test
-    public void testSetDownsamplingSize() {
-        float scale = 0.5f;
-        mAdapter.setDownsamplingScale(scale);
-        Bitmap bitmap = mAdapter.getBitmap();
-        assertEquals(mViewWidth * scale, bitmap.getWidth(), 1);
-        assertEquals(mViewHeight * scale, bitmap.getHeight(), 1);
-
-        Rect rect = mAdapter.getBitmapSize();
-        assertEquals(mViewWidth, rect.width());
-        assertEquals(mViewHeight, rect.height());
-    }
-
-    @Test
     public void testIsDirty() {
         assertTrue(mAdapter.isDirty());
 
@@ -113,21 +100,6 @@
     }
 
     @Test
-    public void testOnLayoutChangeDownsampled() {
-        mAdapter.setDownsamplingScale(0.5f);
-
-        mAdapter.getBitmap();
-        assertFalse(mAdapter.isDirty());
-
-        mAdapter.onLayoutChange(mView, 0, 0, 1, 2, 0, 0, mViewWidth, mViewHeight);
-        assertTrue(mAdapter.isDirty());
-
-        Rect dirtyRect = mAdapter.getDirtyRect();
-        assertEquals(1, dirtyRect.width());
-        assertEquals(2, dirtyRect.height());
-    }
-
-    @Test
     public void testInvalidate() {
         mAdapter.getBitmap();
         assertFalse(mAdapter.isDirty());
@@ -152,19 +124,6 @@
     }
 
     @Test
-    public void testInvalidateRectDownsampled() {
-        mAdapter.setDownsamplingScale(0.5f);
-
-        mAdapter.getBitmap();
-        assertFalse(mAdapter.isDirty());
-
-        Rect dirtyRect = new Rect(1, 2, 3, 4);
-        mAdapter.invalidate(dirtyRect);
-        assertTrue(mAdapter.isDirty());
-        assertEquals(dirtyRect.toString(), mAdapter.getDirtyRect().toString());
-    }
-
-    @Test
     public void testInvalidateRectUnion() {
         mAdapter.getBitmap();
         assertFalse(mAdapter.isDirty());
@@ -256,18 +215,4 @@
         assertEquals(mViewWidth, rect.width());
         assertEquals(mViewHeight, rect.height());
     }
-
-    @Test
-    public void testGetDirtyRectDownsampled() {
-        mAdapter.setDownsamplingScale(0.5f);
-
-        mAdapter.getBitmap();
-        Rect rect = mAdapter.getDirtyRect();
-        assertTrue(rect.isEmpty());
-
-        mAdapter.invalidate(null);
-        rect = mAdapter.getDirtyRect();
-        assertEquals(mViewWidth, rect.width());
-        assertEquals(mViewHeight, rect.height());
-    }
 }
diff --git a/ui/android/resources/resource_manager_impl.cc b/ui/android/resources/resource_manager_impl.cc
index bc900780..78e6e86 100644
--- a/ui/android/resources/resource_manager_impl.cc
+++ b/ui/android/resources/resource_manager_impl.cc
@@ -205,8 +205,6 @@
                                           jint res_type,
                                           jint res_id,
                                           const JavaRef<jobject>& bitmap,
-                                          jint width,
-                                          jint height,
                                           jlong native_resource) {
   DCHECK_GE(res_type, ANDROID_RESOURCE_TYPE_FIRST);
   DCHECK_LE(res_type, ANDROID_RESOURCE_TYPE_LAST);
@@ -224,7 +222,7 @@
   resource->SetUIResource(
       cc::ScopedUIResource::Create(ui_resource_manager_,
                                    cc::UIResourceBitmap(skbitmap)),
-      gfx::Size(width, height));
+      jbitmap.size());
 }
 
 void ResourceManagerImpl::RemoveResource(
diff --git a/ui/android/resources/resource_manager_impl.h b/ui/android/resources/resource_manager_impl.h
index 44a0827..9eb3998 100644
--- a/ui/android/resources/resource_manager_impl.h
+++ b/ui/android/resources/resource_manager_impl.h
@@ -49,8 +49,6 @@
                        jint res_type,
                        jint res_id,
                        const base::android::JavaRef<jobject>& bitmap,
-                       jint width,
-                       jint height,
                        jlong native_resource);
   void RemoveResource(
       JNIEnv* env,
diff --git a/ui/android/resources/resource_manager_impl_unittest.cc b/ui/android/resources/resource_manager_impl_unittest.cc
index 077a050..0d3a3f7 100644
--- a/ui/android/resources/resource_manager_impl_unittest.cc
+++ b/ui/android/resources/resource_manager_impl_unittest.cc
@@ -55,7 +55,7 @@
     small_bitmap.setImmutable();
 
     OnResourceReady(nullptr, nullptr, res_type, res_id,
-                    gfx::ConvertToJavaBitmap(&small_bitmap), 1, 1,
+                    gfx::ConvertToJavaBitmap(&small_bitmap),
                     reinterpret_cast<intptr_t>(new Resource()));
   }