Patrick Dubroy | f890fab | 2010-12-19 16:47:17 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2010 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.view; |
| 18 | |
Patrick Dubroy | f890fab | 2010-12-19 16:47:17 -0800 | [diff] [blame] | 19 | import android.graphics.Rect; |
Svetoslav Ganov | abae2a1 | 2012-11-27 16:59:37 -0800 | [diff] [blame] | 20 | import android.util.Pools.SynchronizedPool; |
Patrick Dubroy | f890fab | 2010-12-19 16:47:17 -0800 | [diff] [blame] | 21 | |
| 22 | /** |
| 23 | * An implementation of a GL canvas that records drawing operations. |
| 24 | * This is intended for use with a DisplayList. This class keeps a list of all the Paint and |
| 25 | * Bitmap objects that it draws, preventing the backing memory of Bitmaps from being freed while |
| 26 | * the DisplayList is still holding a native reference to the memory. |
| 27 | */ |
Svetoslav Ganov | abae2a1 | 2012-11-27 16:59:37 -0800 | [diff] [blame] | 28 | class GLES20RecordingCanvas extends GLES20Canvas { |
Jeff Brown | 162a021 | 2011-07-21 17:02:54 -0700 | [diff] [blame] | 29 | // The recording canvas pool should be large enough to handle a deeply nested |
| 30 | // view hierarchy because display lists are generated recursively. |
Romain Guy | 6d7475d | 2011-07-27 16:28:21 -0700 | [diff] [blame] | 31 | private static final int POOL_LIMIT = 25; |
Patrick Dubroy | f890fab | 2010-12-19 16:47:17 -0800 | [diff] [blame] | 32 | |
Svetoslav Ganov | abae2a1 | 2012-11-27 16:59:37 -0800 | [diff] [blame] | 33 | private static final SynchronizedPool<GLES20RecordingCanvas> sPool = |
| 34 | new SynchronizedPool<GLES20RecordingCanvas>(POOL_LIMIT); |
Jeff Brown | 162a021 | 2011-07-21 17:02:54 -0700 | [diff] [blame] | 35 | |
| 36 | private GLES20DisplayList mDisplayList; |
| 37 | |
| 38 | private GLES20RecordingCanvas() { |
Romain Guy | ef35927 | 2013-01-31 19:07:29 -0800 | [diff] [blame] | 39 | super(true, true); |
Jeff Brown | 162a021 | 2011-07-21 17:02:54 -0700 | [diff] [blame] | 40 | } |
| 41 | |
| 42 | static GLES20RecordingCanvas obtain(GLES20DisplayList displayList) { |
| 43 | GLES20RecordingCanvas canvas = sPool.acquire(); |
Svetoslav Ganov | abae2a1 | 2012-11-27 16:59:37 -0800 | [diff] [blame] | 44 | if (canvas == null) { |
| 45 | canvas = new GLES20RecordingCanvas(); |
| 46 | } |
Jeff Brown | 162a021 | 2011-07-21 17:02:54 -0700 | [diff] [blame] | 47 | canvas.mDisplayList = displayList; |
| 48 | return canvas; |
| 49 | } |
| 50 | |
| 51 | void recycle() { |
| 52 | mDisplayList = null; |
| 53 | resetDisplayListRenderer(); |
| 54 | sPool.release(this); |
| 55 | } |
| 56 | |
| 57 | void start() { |
Romain Guy | 3b748a4 | 2013-04-17 18:54:38 -0700 | [diff] [blame] | 58 | mDisplayList.clearReferences(); |
Jeff Brown | 162a021 | 2011-07-21 17:02:54 -0700 | [diff] [blame] | 59 | } |
| 60 | |
Ashok Bhat | a039843 | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 61 | long end(long nativeDisplayList) { |
Jeff Brown | 162a021 | 2011-07-21 17:02:54 -0700 | [diff] [blame] | 62 | return getDisplayList(nativeDisplayList); |
Patrick Dubroy | f890fab | 2010-12-19 16:47:17 -0800 | [diff] [blame] | 63 | } |
| 64 | |
Patrick Dubroy | f890fab | 2010-12-19 16:47:17 -0800 | [diff] [blame] | 65 | @Override |
Chet Haase | ca479d4 | 2012-08-30 17:20:08 -0700 | [diff] [blame] | 66 | public int drawDisplayList(DisplayList displayList, Rect dirty, int flags) { |
| 67 | int status = super.drawDisplayList(displayList, dirty, flags); |
Romain Guy | 16c0318 | 2013-06-17 11:21:58 -0700 | [diff] [blame] | 68 | mDisplayList.getChildDisplayLists().add(displayList); |
Chet Haase | ca479d4 | 2012-08-30 17:20:08 -0700 | [diff] [blame] | 69 | return status; |
| 70 | } |
Patrick Dubroy | f890fab | 2010-12-19 16:47:17 -0800 | [diff] [blame] | 71 | } |