1 /* 2 * Copyright (C) 2018 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package android.util.imagepool; 18 19 import com.android.tools.layoutlib.annotations.NotNull; 20 import com.android.tools.layoutlib.annotations.VisibleForTesting; 21 22 class ImagePoolStatsProdImpl implements ImagePoolStats { 23 24 static int ESTIMATED_PIXEL_BYTES = 4; 25 26 // Used for determining how many buckets can be created. 27 @VisibleForTesting long mAllocateTotalBytes = 0; 28 @VisibleForTesting int mTooBigForPoolCount = 0; 29 30 /** Used for policy */ 31 @Override recordBucketCreation(int widthBucket, int heightBucket)32 public void recordBucketCreation(int widthBucket, int heightBucket) { 33 mAllocateTotalBytes += (widthBucket * heightBucket * ESTIMATED_PIXEL_BYTES); 34 } 35 36 @Override fitsMaxCacheSize(int width, int height, long maxCacheSize)37 public boolean fitsMaxCacheSize(int width, int height, long maxCacheSize) { 38 long newTotal = mAllocateTotalBytes + (width * height * ESTIMATED_PIXEL_BYTES); 39 return newTotal <= maxCacheSize; 40 } 41 42 @Override tooBigForCache()43 public void tooBigForCache() { 44 mTooBigForPoolCount++; 45 } 46 47 @Override clear()48 public void clear() { 49 mAllocateTotalBytes = 0; 50 } 51 52 @Override recordBucketRequest(int w, int h)53 public void recordBucketRequest(int w, int h) { } 54 55 @Override recordAllocOutsidePool(int width, int height)56 public void recordAllocOutsidePool(int width, int height) { } 57 58 @Override acquiredImage(@otNull Integer imageHash)59 public void acquiredImage(@NotNull Integer imageHash) { } 60 61 @Override disposeImage(@otNull Integer imageHash)62 public void disposeImage(@NotNull Integer imageHash) { } 63 64 @Override start()65 public void start() { } 66 67 @Override getStatistic()68 public String getStatistic() { return ""; } 69 } 70