EngineJob( GlideExecutor diskCacheExecutor, GlideExecutor sourceExecutor, GlideExecutor sourceUnlimitedExecutor, GlideExecutor animationExecutor, EngineJobListener listener, Pools.Pool<EngineJob<?>> pool) { this( diskCacheExecutor, sourceExecutor, sourceUnlimitedExecutor, animationExecutor, listener, pool, DEFAULT_FACTORY); }
@VisibleForTesting EngineJob( GlideExecutor diskCacheExecutor, GlideExecutor sourceExecutor, GlideExecutor sourceUnlimitedExecutor, GlideExecutor animationExecutor, EngineJobListener listener, Pools.Pool<EngineJob<?>> pool, EngineResourceFactory engineResourceFactory) { this.diskCacheExecutor = diskCacheExecutor; this.sourceExecutor = sourceExecutor; this.sourceUnlimitedExecutor = sourceUnlimitedExecutor; this.animationExecutor = animationExecutor; this.listener = listener; this.pool = pool; this.engineResourceFactory = engineResourceFactory; }
/** * Provide the implementation of the PlatformDecoder for the current platform using the * provided PoolFactory * * @param poolFactory The PoolFactory * @return The PlatformDecoder implementation */ public static PlatformDecoder buildPlatformDecoder( PoolFactory poolFactory, boolean directWebpDirectDecodingEnabled) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { int maxNumThreads = poolFactory.getFlexByteArrayPoolMaxNumThreads(); return new ArtDecoder( poolFactory.getBitmapPool(), maxNumThreads, new Pools.SynchronizedPool<>(maxNumThreads)); } else { if (directWebpDirectDecodingEnabled && Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) { return new GingerbreadPurgeableDecoder(); } else { return new KitKatPurgeableDecoder(poolFactory.getFlexByteArrayPool()); } } }
public void detach(int count) { int childCount = mViews.size(); while (childCount > 0 && count > 0) { V view = mViews.remove(childCount - 1); if (mCachePool == null) { mCachePool = new Pools.SimplePool<>(12); } // 做简单cache,如果V需要动态添加子view,则业务保证不做cache Object notCacheTag = view.getTag(R.id.qmui_view_can_not_cache_tag); if (notCacheTag == null || !(boolean) notCacheTag) { try { mCachePool.release(view); } catch (Exception e) { } } mParentView.removeView(view); childCount--; count--; } }
public void detach(int count) { int childCount = mViews.size(); while (childCount > 0 && count > 0) { V view = mViews.remove(childCount - 1); if (mCachePool == null) { mCachePool = new Pools.SimplePool<>(12); } // 做简单cache,如果V需要动态添加子view,则业务保证不做cache Object notCacheTag = view.getTag(R.id.qmui_view_can_not_cache_tag); if (notCacheTag == null || !(boolean) notCacheTag) { try { mCachePool.release(view); } catch (Exception ignored) { } } mParentView.removeView(view); childCount--; count--; } }
TaskPool(Looper mainLooper, final String name, int maxThreads, List<TaskInterceptor> interceptors) { this.name = name; TASK_POOLS.put(name, this); this.interceptors = interceptors; handler = new Handler(mainLooper, this); BlockingQueue<Runnable> workQueue = new LinkedBlockingQueue<>(128); taskRunnablePool = new Pools.SimplePool<>(maxThreads); taskQueues = new Pools.SimplePool<>(10); maxThreads = Math.max(CORE_POOL_SIZE, maxThreads); poolExecutor = new ThreadPoolExecutor(CORE_POOL_SIZE, maxThreads, 1, TimeUnit.SECONDS, workQueue, new ThreadFactory() { private final AtomicInteger mCount = new AtomicInteger(1); @Override public Thread newThread(@NonNull Runnable r) { return new Thread(r, name + " #" + mCount.incrementAndGet()); } }); if (LISTENER != null) LISTENER.onCreated(this); }
private void initEmojisPool() { final int emojiTypeCount = mEmojis.size(); if (emojiTypeCount == 0) throw new IllegalStateException("There are no emojis"); clearDirtyEmojisInPool(); final int expectedMaxEmojiCountInScreen = (int) ((1 + RELATIVE_DROP_DURATION_OFFSET) * mEmojiPer * mDropAverageDuration / ((float) mDropFrequency)); mEmojiPool = new Pools.SynchronizedPool<>(expectedMaxEmojiCountInScreen); for (int i = 0; i < expectedMaxEmojiCountInScreen; i++) { final ImageView emoji = generateEmoji(mEmojis.get(i % emojiTypeCount)); addView(emoji, 0); mEmojiPool.release(emoji); } }
EngineJob(GlideExecutor diskCacheExecutor, GlideExecutor sourceExecutor, GlideExecutor sourceUnlimitedExecutor, EngineJobListener listener, Pools.Pool<EngineJob<?>> pool, EngineResourceFactory engineResourceFactory) { this.diskCacheExecutor = diskCacheExecutor; this.sourceExecutor = sourceExecutor; this.sourceUnlimitedExecutor = sourceUnlimitedExecutor; this.listener = listener; this.pool = pool; this.engineResourceFactory = engineResourceFactory; }
@Before public void setUp() throws Exception { final Random random = new Random(); random.setSeed(RANDOM_SEED); mEncodedBytes = new byte[ENCODED_BYTES_LENGTH]; random.nextBytes(mEncodedBytes); mPooledByteBuffer = new TrivialPooledByteBuffer(mEncodedBytes); mBitmapPool = mock(BitmapPool.class); mArtDecoder = new ArtDecoder(mBitmapPool, 1, new Pools.SynchronizedPool(1)); mByteBufferRef = CloseableReference.of(mPooledByteBuffer); mEncodedImage = new EncodedImage(mByteBufferRef); mEncodedImage.setImageFormat(DefaultImageFormats.JPEG); mBitmap = MockBitmapFactory.create(); doReturn(mBitmap).when(mBitmapPool).get(MockBitmapFactory.DEFAULT_BITMAP_SIZE); mBitmapFactoryDefaultAnswer = new Answer<Bitmap>() { @Override public Bitmap answer(InvocationOnMock invocation) throws Throwable { final BitmapFactory.Options options = (BitmapFactory.Options) invocation.getArguments()[2]; options.outWidth = MockBitmapFactory.DEFAULT_BITMAP_WIDTH; options.outHeight = MockBitmapFactory.DEFAULT_BITMAP_HEIGHT; verifyBitmapFactoryOptions(options); return options.inJustDecodeBounds ? null : mBitmap; } }; whenBitmapFactoryDecodeStream().thenAnswer(mBitmapFactoryDefaultAnswer); mBitmapRegionDecoder = mock(BitmapRegionDecoder.class); whenBitmapRegionDecoderNewInstance().thenReturn(mBitmapRegionDecoder); ByteBuffer buf = mArtDecoder.mDecodeBuffers.acquire(); mTempStorage = buf.array(); mArtDecoder.mDecodeBuffers.release(buf); }
/** * @param capacityBytes Maximum capacity of the pool in bytes. * @param nodePool Shared pool to use for recycling linked list nodes, or null. */ public SparseArrayBitmapPool(int capacityBytes, Pools.Pool<Node> nodePool) { mCapacityBytes = capacityBytes; if (nodePool == null) { mNodePool = new Pools.SimplePool<Node>(32); } else { mNodePool = nodePool; } }
private LineItemPosRecord generateALineItem(FlowDragLayoutManager layoutManager) { if (rectSimplePool == null) { rectSimplePool = new Pools.SimplePool<>(layoutManager.getChildCount()); } LineItemPosRecord out = rectSimplePool.acquire(); if (out == null) { // DebugUtil.debugFormat("FlowDragLayoutManager out come from new"); out = new LineItemPosRecord(); }else { // DebugUtil.debugFormat("FlowDragLayoutManager out come from pool"); } return out; }
/** * Retriever an instance from the pool * * @param itemClass item class * @return animator holder */ public static AnimatorHolder obtain(Class<? extends AnimatorItem> itemClass){ Pools.SynchronizedPool<AnimatorHolder> pool = sPoolMap.get(itemClass); if (pool == null){ pool = new Pools.SynchronizedPool<>(MAX_POOL_SIZE); sPoolMap.put(itemClass, pool); } AnimatorHolder holder = pool.acquire(); if (holder != null && holder.mItemClass.equals(itemClass)){ holder.reset(); return holder; } else { return new AnimatorHolder(itemClass); } }
/** * destroy the pools */ public static void destroyAll(){ Set<Class> keys = sPoolMap.keySet(); for (Class key : keys) { Pools.SynchronizedPool<AnimatorHolder> pool = sPoolMap.get(key); if (pool != null){ AnimatorHolder holder = pool.acquire(); for (; holder != null; holder = pool.acquire()){ holder.destroy(); } } } sPoolMap.clear(); }
EngineJob(GlideExecutor diskCacheExecutor, GlideExecutor sourceExecutor, GlideExecutor sourceUnlimitedExecutor, EngineJobListener listener, Pools.Pool<EngineJob<?>> pool) { this(diskCacheExecutor, sourceExecutor, sourceUnlimitedExecutor, listener, pool, DEFAULT_FACTORY); }
DecodeJob(DiskCacheProvider diskCacheProvider, Pools.Pool<DecodeJob<?>> pool) { this.diskCacheProvider = diskCacheProvider; this.pool = pool; }
/** * Put current object into the pool */ public void recycle(){ Pools.SynchronizedPool<AnimatorHolder> pool = sPoolMap.get(mItemClass); pool.release(this); }