1/*
2 * Copyright (c) 2007, 2013, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.  Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26package sun.java2d.pipe.hw;
27
28
29/**
30 * Represents a set of capabilities of a BufferedContext and associated
31 * AccelGraphicsConfig.
32 *
33 * @see AccelGraphicsConfig
34 */
35public class ContextCapabilities {
36    /** Indicates that the context has no capabilities. */
37    public static final int CAPS_EMPTY             = (0 << 0);
38    /** Indicates that the context supports RT surfaces with alpha channel. */
39    public static final int CAPS_RT_PLAIN_ALPHA    = (1 << 1);
40    /** Indicates that the context supports RT textures with alpha channel. */
41    public static final int CAPS_RT_TEXTURE_ALPHA  = (1 << 2);
42    /** Indicates that the context supports opaque RT textures. */
43    public static final int CAPS_RT_TEXTURE_OPAQUE = (1 << 3);
44    /** Indicates that the context supports multitexturing. */
45    public static final int CAPS_MULTITEXTURE      = (1 << 4);
46    /** Indicates that the context supports non-pow2 texture dimensions. */
47    public static final int CAPS_TEXNONPOW2        = (1 << 5);
48    /** Indicates that the context supports non-square textures. */
49    public static final int CAPS_TEXNONSQUARE      = (1 << 6);
50    /** Indicates that the context supports pixel shader 2.0 or better. */
51    public static final int CAPS_PS20              = (1 << 7);
52    /** Indicates that the context supports pixel shader 3.0 or better. */
53    public static final int CAPS_PS30              = (1 << 8);
54    /*
55     *  Pipeline contexts should use this for defining pipeline-specific
56     *  capabilities, for example:
57     *    int CAPS_D3D_1 = (FIRST_PRIVATE_CAP << 0);
58     *    int CAPS_D3D_2 = (FIRST_PRIVATE_CAP << 1);
59     */
60    protected static final int FIRST_PRIVATE_CAP   = (1 << 16);
61
62    protected final int caps;
63    protected final String adapterId;
64
65    /**
66     * Constructs a {@code ContextCapabilities} object.
67     * @param caps an {@code int} representing the capabilities
68     * @param adapterId {@code String} representing the name of the adapter, or null,
69     * in which case the adapterId will be set to "unknown adapter".
70     */
71    protected ContextCapabilities(int caps, String adapterId) {
72        this.caps = caps;
73        this.adapterId = adapterId != null ? adapterId : "unknown adapter";
74    }
75
76    /**
77     * Returns a string representing the name of the graphics adapter if such
78     * could be determined. It is guaranteed to never return {@code null}.
79     * @return string representing adapter id
80     */
81    public String getAdapterId() {
82        return adapterId;
83    }
84
85    /**
86     * Returns an {@code int} with capabilities (OR-ed constants defined in
87     * this class and its pipeline-specific subclasses).
88     * @return capabilities as {@code int}
89     */
90    public int getCaps() {
91        return caps;
92    }
93
94    @Override
95    public String toString() {
96        StringBuilder sb =
97            new StringBuilder("ContextCapabilities: adapter=" +
98                             adapterId+", caps=");
99        if (caps == CAPS_EMPTY) {
100            sb.append("CAPS_EMPTY");
101        } else {
102            if ((caps & CAPS_RT_PLAIN_ALPHA) != 0) {
103                sb.append("CAPS_RT_PLAIN_ALPHA|");
104            }
105            if ((caps & CAPS_RT_TEXTURE_ALPHA) != 0) {
106                sb.append("CAPS_RT_TEXTURE_ALPHA|");
107            }
108            if ((caps & CAPS_RT_TEXTURE_OPAQUE) != 0) {
109                sb.append("CAPS_RT_TEXTURE_OPAQUE|");
110            }
111            if ((caps & CAPS_MULTITEXTURE) != 0) {
112                sb.append("CAPS_MULTITEXTURE|");
113            }
114            if ((caps & CAPS_TEXNONPOW2) != 0) {
115                sb.append("CAPS_TEXNONPOW2|");
116            }
117            if ((caps & CAPS_TEXNONSQUARE) != 0) {
118                sb.append("CAPS_TEXNONSQUARE|");
119            }
120            if ((caps & CAPS_PS20) != 0) {
121                sb.append("CAPS_PS20|");
122            }
123            if ((caps & CAPS_PS30) != 0) {
124                sb.append("CAPS_PS30|");
125            }
126        }
127        return sb.toString();
128    }
129}
130