Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(459)

Side by Side Diff: ui/android/java/src/org/chromium/ui/resources/ResourceManager.java

Issue 2746483003: ui/android: Fix Resource meta-data sharing with ResourceManager. (Closed)
Patch Set: address comments Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 package org.chromium.ui.resources; 5 package org.chromium.ui.resources;
6 6
7 import android.content.Context; 7 import android.content.Context;
8 import android.content.res.Resources; 8 import android.content.res.Resources;
9 import android.graphics.Bitmap; 9 import android.graphics.Bitmap;
10 import android.graphics.Rect; 10 import android.graphics.Rect;
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
79 : displayAndroid.getDisplayWidth(); 79 : displayAndroid.getDisplayWidth();
80 int screenHeight = displayAndroid.getPhysicalDisplayHeight() != 0 80 int screenHeight = displayAndroid.getPhysicalDisplayHeight() != 0
81 ? displayAndroid.getPhysicalDisplayHeight() 81 ? displayAndroid.getPhysicalDisplayHeight()
82 : displayAndroid.getDisplayHeight(); 82 : displayAndroid.getDisplayHeight();
83 int minScreenSideLength = Math.min(screenWidth, screenHeight); 83 int minScreenSideLength = Math.min(screenWidth, screenHeight);
84 84
85 Resources resources = context.getResources(); 85 Resources resources = context.getResources();
86 return new ResourceManager(resources, minScreenSideLength, staticResourc eManagerPtr); 86 return new ResourceManager(resources, minScreenSideLength, staticResourc eManagerPtr);
87 } 87 }
88 88
89 public static long createBitmapResource() {
David Trainor- moved to gerrit 2017/03/14 18:31:52 Maybe these should live on the resources. I admit
Khushal 2017/03/15 01:50:06 Actually, how about just making NinePatchData publ
Khushal 2017/03/16 19:01:44 I moved it to a separate class. Cleaner.
90 return nativeCreateBitmapResource();
91 }
92
93 public static long createNinePatchBitmapResource(Rect padding, Rect aperture ) {
94 return nativeCreateNinePatchBitmapResource(padding.left, padding.top, pa dding.right,
95 padding.bottom, aperture.left, aperture.top, aperture.right, ape rture.bottom);
96 }
97
89 /** 98 /**
90 * @return A reference to the {@link DynamicResourceLoader} that provides 99 * @return A reference to the {@link DynamicResourceLoader} that provides
91 * {@link DynamicResource} objects to this class. 100 * {@link DynamicResource} objects to this class.
92 */ 101 */
93 public DynamicResourceLoader getDynamicResourceLoader() { 102 public DynamicResourceLoader getDynamicResourceLoader() {
94 return (DynamicResourceLoader) mResourceLoaders.get( 103 return (DynamicResourceLoader) mResourceLoaders.get(
95 AndroidResourceType.DYNAMIC); 104 AndroidResourceType.DYNAMIC);
96 } 105 }
97 106
98 /** 107 /**
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
152 nativeOnCrushedSpriteResourceReady(mNativeResourceManagerPtr, re sId, 161 nativeOnCrushedSpriteResourceReady(mNativeResourceManagerPtr, re sId,
153 crushedResource.getBitmap(), crushedResource.getFrameRec tangles(), 162 crushedResource.getBitmap(), crushedResource.getFrameRec tangles(),
154 crushedResource.getUnscaledSpriteWidth(), 163 crushedResource.getUnscaledSpriteWidth(),
155 crushedResource.getUnscaledSpriteHeight(), 164 crushedResource.getUnscaledSpriteHeight(),
156 crushedResource.getScaledSpriteWidth(), 165 crushedResource.getScaledSpriteWidth(),
157 crushedResource.getScaledSpriteHeight()); 166 crushedResource.getScaledSpriteHeight());
158 } 167 }
159 return; 168 return;
160 } 169 }
161 170
162 Rect padding = resource.getPadding();
163 Rect aperture = resource.getAperture();
164
165 nativeOnResourceReady(mNativeResourceManagerPtr, resType, resId, resourc e.getBitmap(), 171 nativeOnResourceReady(mNativeResourceManagerPtr, resType, resId, resourc e.getBitmap(),
166 padding.left, padding.top, padding.right, padding.bottom, 172 resource.createNativeResource());
167 aperture.left, aperture.top, aperture.right, aperture.bottom);
168 } 173 }
169 174
170 @Override 175 @Override
171 public void onResourceUnregistered(int resType, int resId) { 176 public void onResourceUnregistered(int resType, int resId) {
172 // Only remove dynamic bitmaps that were unregistered. 177 // Only remove dynamic bitmaps that were unregistered.
173 if (resType != AndroidResourceType.DYNAMIC_BITMAP) return; 178 if (resType != AndroidResourceType.DYNAMIC_BITMAP) return;
174 179
175 nativeRemoveResource(mNativeResourceManagerPtr, resType, resId); 180 nativeRemoveResource(mNativeResourceManagerPtr, resType, resId);
176 } 181 }
177 182
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
227 @CalledByNative 232 @CalledByNative
228 private long getNativePtr() { 233 private long getNativePtr() {
229 return mNativeResourceManagerPtr; 234 return mNativeResourceManagerPtr;
230 } 235 }
231 236
232 private void registerResourceLoader(ResourceLoader loader) { 237 private void registerResourceLoader(ResourceLoader loader) {
233 mResourceLoaders.put(loader.getResourceType(), loader); 238 mResourceLoaders.put(loader.getResourceType(), loader);
234 } 239 }
235 240
236 private native void nativeOnResourceReady(long nativeResourceManagerImpl, in t resType, 241 private native void nativeOnResourceReady(long nativeResourceManagerImpl, in t resType,
237 int resId, Bitmap bitmap, int paddingLeft, int paddingTop, int paddi ngRight, 242 int resId, Bitmap bitmap, long nativeResource);
238 int paddingBottom, int apertureLeft, int apertureTop, int apertureRi ght,
239 int apertureBottom);
240 private native void nativeOnCrushedSpriteResourceReady(long nativeResourceMa nagerImpl, 243 private native void nativeOnCrushedSpriteResourceReady(long nativeResourceMa nagerImpl,
241 int bitmapResId, Bitmap bitmap, int[][] frameRects, int unscaledSpri teWidth, 244 int bitmapResId, Bitmap bitmap, int[][] frameRects, int unscaledSpri teWidth,
242 int unscaledSpriteHeight, float scaledSpriteWidth, float scaledSprit eHeight); 245 int unscaledSpriteHeight, float scaledSpriteWidth, float scaledSprit eHeight);
243 private native void nativeOnCrushedSpriteResourceReloaded(long nativeResourc eManagerImpl, 246 private native void nativeOnCrushedSpriteResourceReloaded(long nativeResourc eManagerImpl,
244 int bitmapResId, Bitmap bitmap); 247 int bitmapResId, Bitmap bitmap);
245 private native void nativeRemoveResource(long nativeResourceManagerImpl, int resType, 248 private native void nativeRemoveResource(long nativeResourceManagerImpl, int resType,
246 int resId); 249 int resId);
247 private native void nativeClearTintedResourceCache(long nativeResourceManage rImpl); 250 private native void nativeClearTintedResourceCache(long nativeResourceManage rImpl);
248 251
252 private static native long nativeCreateBitmapResource();
253 private static native long nativeCreateNinePatchBitmapResource(int paddingLe ft, int paddingTop,
254 int paddingRight, int paddingBottom, int apertureLeft, int apertureT op,
255 int apertureRight, int apertureBottom);
249 } 256 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698