| 849 | } |
| 850 | |
| 851 | public void getBufferPixels(int[] pixels) { |
| 852 | // We get the buffer either from the used buffers or the cache, giving |
| 853 | // priority to the used buffers. Why? Because the used buffer was already |
| 854 | // transferred to the texture, so the pixels should be in sync with the |
| 855 | // texture. |
| 856 | BufferData data = null; |
| 857 | if (usedBuffers != null && 0 < usedBuffers.size()) { |
| 858 | data = usedBuffers.getLast(); |
| 859 | } else if (bufferCache != null && 0 < bufferCache.size()) { |
| 860 | data = bufferCache.getLast(); |
| 861 | } |
| 862 | if (data != null) { |
| 863 | if ((data.w != width) || (data.h != height)) { |
| 864 | init(data.w, data.h); |
| 865 | } |
| 866 | |
| 867 | data.rgbBuf.rewind(); |
| 868 | data.rgbBuf.get(pixels); |
| 869 | convertToARGB(pixels); |
| 870 | |
| 871 | // In order to avoid a cached buffer to overwrite the texture when the |
| 872 | // renderer draws the texture, and hence put the pixels put of sync, we |
| 873 | // simply empty the cache. |
| 874 | if (usedBuffers == null) { |
| 875 | usedBuffers = new LinkedList<BufferData>(); |
| 876 | } |
| 877 | while (0 < bufferCache.size()) { |
| 878 | data = bufferCache.remove(0); |
| 879 | usedBuffers.add(data); |
| 880 | } |
| 881 | } |
| 882 | } |
| 883 | |
| 884 | |
| 885 | public boolean hasBufferSource() { |