Chromium Code Reviews| OLD | NEW |
|---|---|
| 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; |
| 11 import android.util.SparseArray; | 11 import android.util.SparseArray; |
| 12 | 12 |
| 13 import org.chromium.base.annotations.CalledByNative; | 13 import org.chromium.base.annotations.CalledByNative; |
| 14 import org.chromium.base.annotations.JNINamespace; | 14 import org.chromium.base.annotations.JNINamespace; |
| 15 import org.chromium.base.annotations.MainDex; | 15 import org.chromium.base.annotations.MainDex; |
| 16 import org.chromium.ui.base.WindowAndroid; | |
| 17 import org.chromium.ui.gfx.DeviceDisplayInfo; | |
| 16 import org.chromium.ui.resources.ResourceLoader.ResourceLoaderCallback; | 18 import org.chromium.ui.resources.ResourceLoader.ResourceLoaderCallback; |
| 17 import org.chromium.ui.resources.dynamics.DynamicResource; | 19 import org.chromium.ui.resources.dynamics.DynamicResource; |
| 18 import org.chromium.ui.resources.dynamics.DynamicResourceLoader; | 20 import org.chromium.ui.resources.dynamics.DynamicResourceLoader; |
| 19 import org.chromium.ui.resources.sprites.CrushedSpriteResource; | 21 import org.chromium.ui.resources.sprites.CrushedSpriteResource; |
| 20 import org.chromium.ui.resources.sprites.CrushedSpriteResourceLoader; | 22 import org.chromium.ui.resources.sprites.CrushedSpriteResourceLoader; |
| 21 import org.chromium.ui.resources.statics.StaticResourceLoader; | 23 import org.chromium.ui.resources.statics.StaticResourceLoader; |
| 22 import org.chromium.ui.resources.system.SystemResourceLoader; | 24 import org.chromium.ui.resources.system.SystemResourceLoader; |
| 23 | 25 |
| 24 /** | 26 /** |
| 25 * The Java component of a manager for all static resources to be loaded and use d by CC layers. | 27 * The Java component of a manager for all static resources to be loaded and use d by CC layers. |
| 26 * This class does not hold any resource state, but passes it directly to native as they are loaded. | 28 * This class does not hold any resource state, but passes it directly to native as they are loaded. |
| 27 */ | 29 */ |
| 28 @JNINamespace("ui") | 30 @JNINamespace("ui") |
| 29 @MainDex | 31 @MainDex |
| 30 public class ResourceManager implements ResourceLoaderCallback { | 32 public class ResourceManager implements ResourceLoaderCallback { |
| 31 private final SparseArray<ResourceLoader> mResourceLoaders = new SparseArray <ResourceLoader>(); | 33 private final SparseArray<ResourceLoader> mResourceLoaders = new SparseArray <ResourceLoader>(); |
| 32 private final SparseArray<SparseArray<LayoutResource>> mLoadedResources = | 34 private final SparseArray<SparseArray<LayoutResource>> mLoadedResources = |
| 33 new SparseArray<SparseArray<LayoutResource>>(); | 35 new SparseArray<SparseArray<LayoutResource>>(); |
| 34 private final CrushedSpriteResourceLoader mCrushedSpriteResourceLoader; | 36 private final CrushedSpriteResourceLoader mCrushedSpriteResourceLoader; |
| 35 | 37 |
| 36 private final float mPxToDp; | 38 private final float mPxToDp; |
| 37 | 39 |
| 38 private long mNativeResourceManagerPtr; | 40 private long mNativeResourceManagerPtr; |
| 39 | 41 |
| 40 private ResourceManager(Context context, long staticResourceManagerPtr) { | 42 private ResourceManager( |
| 41 Resources resources = context.getResources(); | 43 Resources resources, int minScreenSideLength, long staticResourceMan agerPtr) { |
| 42 mPxToDp = 1.f / resources.getDisplayMetrics().density; | 44 mPxToDp = 1.f / resources.getDisplayMetrics().density; |
| 43 | 45 |
| 44 // Register ResourceLoaders | |
| 45 registerResourceLoader(new StaticResourceLoader( | 46 registerResourceLoader(new StaticResourceLoader( |
| 46 AndroidResourceType.STATIC, this, resources)); | 47 AndroidResourceType.STATIC, this, resources)); |
| 47 registerResourceLoader(new DynamicResourceLoader( | 48 registerResourceLoader(new DynamicResourceLoader( |
| 48 AndroidResourceType.DYNAMIC, this)); | 49 AndroidResourceType.DYNAMIC, this)); |
| 49 registerResourceLoader(new DynamicResourceLoader( | 50 registerResourceLoader(new DynamicResourceLoader( |
| 50 AndroidResourceType.DYNAMIC_BITMAP, this)); | 51 AndroidResourceType.DYNAMIC_BITMAP, this)); |
| 51 registerResourceLoader(new SystemResourceLoader( | 52 registerResourceLoader( |
| 52 AndroidResourceType.SYSTEM, this, context)); | 53 new SystemResourceLoader(AndroidResourceType.SYSTEM, this, minSc reenSideLength)); |
| 53 mCrushedSpriteResourceLoader = new CrushedSpriteResourceLoader(this, res ources); | 54 mCrushedSpriteResourceLoader = new CrushedSpriteResourceLoader(this, res ources); |
| 54 | 55 |
| 55 mNativeResourceManagerPtr = staticResourceManagerPtr; | 56 mNativeResourceManagerPtr = staticResourceManagerPtr; |
| 56 } | 57 } |
| 57 | 58 |
| 58 /** | 59 /** |
| 59 * Creates an instance of a {@link ResourceManager}. This will | 60 * Creates an instance of a {@link ResourceManager}. |
| 60 * @param context A {@link Context} instance to grab {@link Resources} from. | 61 * @param WindowAndroid A {@link WindowAndroid} instance to fetch a {@link Context} |
| 62 * and thus grab {@link Resources} from. | |
| 61 * @param staticResourceManagerPtr A pointer to the native component of this class. | 63 * @param staticResourceManagerPtr A pointer to the native component of this class. |
| 62 * @return A new instance of a {@link ResourceManage r}. | 64 * @return A new instance of a {@link ResourceManage r}. |
| 63 */ | 65 */ |
| 64 @CalledByNative | 66 @CalledByNative |
| 65 private static ResourceManager create(Context context, long staticResourceMa nagerPtr) { | 67 private static ResourceManager create( |
| 66 return new ResourceManager(context, staticResourceManagerPtr); | 68 WindowAndroid windowAndroid, long staticResourceManagerPtr) { |
| 69 Context context = windowAndroid.getContext().get(); | |
| 70 // This call should happen early enough (i.e. during construction) that this context should | |
| 71 // not yet have been released. | |
| 72 if (context == null) return null; | |
|
Ted C
2015/11/16 16:51:54
from my brief glance, it doesn't look like native
gsennton
2015/11/16 19:53:58
Done.
| |
| 73 | |
| 74 DeviceDisplayInfo displayInfo = DeviceDisplayInfo.create(context); | |
| 75 int screenWidth = displayInfo.getPhysicalDisplayWidth() != 0 | |
| 76 ? displayInfo.getPhysicalDisplayWidth() | |
| 77 : displayInfo.getDisplayWidth(); | |
| 78 int screenHeight = displayInfo.getPhysicalDisplayHeight() != 0 | |
| 79 ? displayInfo.getPhysicalDisplayHeight() | |
| 80 : displayInfo.getDisplayHeight(); | |
| 81 int minScreenSideLength = Math.min(screenWidth, screenHeight); | |
| 82 | |
| 83 Resources resources = context.getResources(); | |
| 84 return new ResourceManager(resources, minScreenSideLength, staticResourc eManagerPtr); | |
| 67 } | 85 } |
| 68 | 86 |
| 69 /** | 87 /** |
| 70 * @return A reference to the {@link DynamicResourceLoader} that provides | 88 * @return A reference to the {@link DynamicResourceLoader} that provides |
| 71 * {@link DynamicResource} objects to this class. | 89 * {@link DynamicResource} objects to this class. |
| 72 */ | 90 */ |
| 73 public DynamicResourceLoader getDynamicResourceLoader() { | 91 public DynamicResourceLoader getDynamicResourceLoader() { |
| 74 return (DynamicResourceLoader) mResourceLoaders.get( | 92 return (DynamicResourceLoader) mResourceLoaders.get( |
| 75 AndroidResourceType.DYNAMIC); | 93 AndroidResourceType.DYNAMIC); |
| 76 } | 94 } |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 201 int resId, Bitmap bitmap, int paddingLeft, int paddingTop, int paddi ngRight, | 219 int resId, Bitmap bitmap, int paddingLeft, int paddingTop, int paddi ngRight, |
| 202 int paddingBottom, int apertureLeft, int apertureTop, int apertureRi ght, | 220 int paddingBottom, int apertureLeft, int apertureTop, int apertureRi ght, |
| 203 int apertureBottom); | 221 int apertureBottom); |
| 204 private native void nativeOnCrushedSpriteResourceReady(long nativeResourceMa nagerImpl, | 222 private native void nativeOnCrushedSpriteResourceReady(long nativeResourceMa nagerImpl, |
| 205 int bitmapResId, Bitmap bitmap, int[][] frameRects, int unscaledSpri teWidth, | 223 int bitmapResId, Bitmap bitmap, int[][] frameRects, int unscaledSpri teWidth, |
| 206 int unscaledSpriteHeight, float scaledSpriteWidth, float scaledSprit eHeight); | 224 int unscaledSpriteHeight, float scaledSpriteWidth, float scaledSprit eHeight); |
| 207 private native void nativeOnCrushedSpriteResourceReloaded(long nativeResourc eManagerImpl, | 225 private native void nativeOnCrushedSpriteResourceReloaded(long nativeResourc eManagerImpl, |
| 208 int bitmapResId, Bitmap bitmap); | 226 int bitmapResId, Bitmap bitmap); |
| 209 | 227 |
| 210 } | 228 } |
| OLD | NEW |