JOGL v2.6.0-rc-20250706
JOGL, High-Performance Graphics Binding for Java™ (public API).
SurfaceSize.java
Go to the documentation of this file.
1/**
2 * Copyright 2010 JogAmp Community. All rights reserved.
3 * Copyright (c) 2010 JogAmp Community. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without modification, are
6 * permitted provided that the following conditions are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright notice, this list of
9 * conditions and the following disclaimer.
10 *
11 * 2. Redistributions in binary form must reproduce the above copyright notice, this list
12 * of conditions and the following disclaimer in the documentation and/or other materials
13 * provided with the distribution.
14 *
15 * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED
16 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
17 * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR
18 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
19 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
20 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
21 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
22 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
23 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 *
25 * The views and conclusions contained in the software and documentation are those of the
26 * authors and should not be interpreted as representing official policies, either expressed
27 * or implied, of JogAmp Community.
28 */
29
30package com.jogamp.nativewindow.util;
31
32/**
33 * Immutable SurfaceSize Class, consisting of it's read only components:<br>
34 * <ul>
35 * <li>{@link com.jogamp.nativewindow.util.DimensionImmutable size in pixels}</li>
36 * <li><code>bits per pixel</code></li>
37 * </ul>
38 */
39public class SurfaceSize implements Comparable<SurfaceSize> {
40 final DimensionImmutable resolution;
41 final int bitsPerPixel;
42
43 public SurfaceSize(final DimensionImmutable resolution, final int bitsPerPixel) {
44 if(null==resolution || bitsPerPixel<=0) {
45 throw new IllegalArgumentException("resolution must be set and bitsPerPixel greater 0");
46 }
47 this.resolution=resolution;
48 this.bitsPerPixel=bitsPerPixel;
49 }
50
51 /** Returns the resolution in pixel units */
53 return resolution;
54 }
55
56 public final int getBitsPerPixel() {
57 return bitsPerPixel;
58 }
59
60 @Override
61 public final String toString() {
62 return "[ "+resolution+" pixels x "+bitsPerPixel+" bpp ]";
63 }
64
65 /**
66 * <p>
67 * Compares {@link DimensionImmutable#compareTo(DimensionImmutable) resolution} 1st, if equal the bitsPerPixel.
68 * </p>
69 * {@inheritDoc}
70 */
71 @Override
72 public int compareTo(final SurfaceSize ssz) {
73 final int rres = resolution.compareTo(ssz.getResolution());
74 if( 0 != rres ) {
75 return rres;
76 }
77 final int xbpp = ssz.getBitsPerPixel();
78 if(bitsPerPixel > xbpp) {
79 return 1;
80 } else if(bitsPerPixel < xbpp) {
81 return -1;
82 }
83 return 0;
84 }
85
86 /**
87 * Checks whether two size objects are equal. Two instances
88 * of <code>SurfaceSize</code> are equal if the two components
89 * <code>resolution</code> and <code>bitsPerPixel</code>
90 * are equal.
91 * @return <code>true</code> if the two dimensions are equal;
92 * otherwise <code>false</code>.
93 */
94 @Override
95 public final boolean equals(final Object obj) {
96 if(this == obj) { return true; }
97 if (obj instanceof SurfaceSize) {
98 final SurfaceSize p = (SurfaceSize)obj;
99 return getResolution().equals(p.getResolution()) &&
101 }
102 return false;
103 }
104
105 @Override
106 public final int hashCode() {
107 // 31 * x == (x << 5) - x
108 int hash = getResolution().hashCode();
109 hash = ((hash << 5) - hash) + getBitsPerPixel();
110 return hash;
111 }
112}
113
Immutable SurfaceSize Class, consisting of it's read only components:
final boolean equals(final Object obj)
Checks whether two size objects are equal.
final DimensionImmutable getResolution()
Returns the resolution in pixel units.
SurfaceSize(final DimensionImmutable resolution, final int bitsPerPixel)
int compareTo(final SurfaceSize ssz)
Immutable Dimension Interface, consisting of it's read only components:
boolean equals(Object obj)
Checks whether two dimensions objects are equal.
int compareTo(final DimensionImmutable d)