1 |
// (c) Tuomas J. Lukka |
// (c) Tuomas J. Lukka |
2 |
|
|
3 |
package gzz.mem; |
package gzz.mem; |
4 |
|
import gzz.Obs; |
5 |
|
|
6 |
/** An object representing an entity which would like |
/** An object representing an entity which would like |
7 |
* to consume a significant amount of memory (large image or such). |
* to consume a significant amount of memory (large image or such). |
8 |
* Memoryconsumers <b>must</b> work as hash keys. |
* Memoryconsumers <b>must</b> work as hash keys. |
9 |
|
* <p> |
10 |
|
* Quality is an important variable whose semantics are not defined in this interface |
11 |
|
* beyond that |
12 |
|
* <ul> |
13 |
|
* <li> It is a float |
14 |
|
* <li> Larger quality = more bytes |
15 |
|
* <li> May be interpolated: a quality between any two qualities that have been |
16 |
|
* given to the MemoryPartitioner API may be given. |
17 |
|
* </ul> |
18 |
|
* an example of quality would be DPI (dots per inch) for images. |
19 |
*/ |
*/ |
20 |
public interface MemoryConsumer { |
public interface MemoryConsumer { |
21 |
/** Whether this object can make use of byte amounts less |
/** Whether this object can make use of byte amounts less |
23 |
*/ |
*/ |
24 |
boolean getScalable(); |
boolean getScalable(); |
25 |
/** The maximum number of bytes this object would like to consume. |
/** The maximum number of bytes this object would like to consume. |
26 |
|
* @param quality The quality at which the maximum bytes are requested. |
27 |
*/ |
*/ |
28 |
int getMaxBytes(); |
int getMaxBytes(float quality); |
29 |
/** Set the amount of memory this object is allowed to consume. |
/** Set the amount of memory this object is allowed to consume. |
30 |
* Once it's done, Obs will be called from an unspecified thread. |
* Once it's done, Obs will be called from an unspecified thread. |
31 |
* If setReservation is called again before the Obs for a previous |
* If setReservation is called again before the Obs for a previous |
33 |
* the previous Obs will be called at all. The size, when the later Obs |
* the previous Obs will be called at all. The size, when the later Obs |
34 |
* is called, is the new one. |
* is called, is the new one. |
35 |
* @param bytes The maximum amount of bytes this object should reserve. |
* @param bytes The maximum amount of bytes this object should reserve. |
36 |
* @param o Observer to call when size has been adjusted |
* @param quality Maximum quality that should be loaded (if quality is |
37 |
|
* adjusted in discrete steps, the class may round upwards). |
38 |
|
* @param o Observer to call (if non-null) when size has been adjusted |
39 |
*/ |
*/ |
40 |
void setReservation(int bytes, Obs o); |
void setReservation(int bytes, float quality, Obs o); |
41 |
/** Get the number of bytes currently used. |
/** Get the number of bytes currently used. |
42 |
*/ |
*/ |
43 |
int getReservation(); |
int getReservation(); |