(Rect r, int encoding,
ModifiablePixelBuffer pb)
| 78 | } |
| 79 | |
| 80 | public void decodeRect(Rect r, int encoding, |
| 81 | ModifiablePixelBuffer pb) |
| 82 | { |
| 83 | Decoder decoder; |
| 84 | MemOutStream bufferStream; |
| 85 | |
| 86 | QueueEntry entry; |
| 87 | |
| 88 | assert(pb != null); |
| 89 | |
| 90 | if (!Decoder.supported(encoding)) { |
| 91 | vlog.error("Unknown encoding " + encoding); |
| 92 | throw new Exception("Unknown encoding"); |
| 93 | } |
| 94 | |
| 95 | if (decoders[encoding] == null) { |
| 96 | decoders[encoding] = Decoder.createDecoder(encoding); |
| 97 | if (decoders[encoding] == null) { |
| 98 | vlog.error("Unknown encoding " + encoding); |
| 99 | throw new Exception("Unknown encoding"); |
| 100 | } |
| 101 | } |
| 102 | |
| 103 | decoder = decoders[encoding]; |
| 104 | |
| 105 | // Fast path for single CPU machines to avoid the context |
| 106 | // switching overhead |
| 107 | if (threads.size() == 1) { |
| 108 | bufferStream = freeBuffers.getFirst(); |
| 109 | bufferStream.clear(); |
| 110 | decoder.readRect(r, conn.getInStream(), conn.server, bufferStream); |
| 111 | decoder.decodeRect(r, (Object)bufferStream.data(), bufferStream.length(), |
| 112 | conn.server, pb); |
| 113 | return; |
| 114 | } |
| 115 | |
| 116 | // Wait for an available memory buffer |
| 117 | queueMutex.lock(); |
| 118 | |
| 119 | try { |
| 120 | while (freeBuffers.isEmpty()) |
| 121 | try { |
| 122 | producerCond.await(); |
| 123 | } catch (InterruptedException e) { } |
| 124 | |
| 125 | // Don't pop the buffer in case we throw an exception |
| 126 | // whilst reading |
| 127 | bufferStream = freeBuffers.getFirst(); |
| 128 | } finally { |
| 129 | queueMutex.unlock(); |
| 130 | } |
| 131 | |
| 132 | // First check if any thread has encountered a problem |
| 133 | throwThreadException(); |
| 134 | |
| 135 | // Read the rect |
| 136 | bufferStream.clear(); |
| 137 | decoder.readRect(r, conn.getInStream(), conn.server, bufferStream); |
no test coverage detected