14ebf2b4fd20e973edb38668acb6f208afa51cd05bsalomon@google.com/*
26177e6999d23a4268ffd98dedfb1da00e272a89brobertphillips@google.com * Copyright 2013 Google Inc.
34ebf2b4fd20e973edb38668acb6f208afa51cd05bsalomon@google.com *
44ebf2b4fd20e973edb38668acb6f208afa51cd05bsalomon@google.com * Use of this source code is governed by a BSD-style license that can be
54ebf2b4fd20e973edb38668acb6f208afa51cd05bsalomon@google.com * found in the LICENSE file.
64ebf2b4fd20e973edb38668acb6f208afa51cd05bsalomon@google.com */
74ebf2b4fd20e973edb38668acb6f208afa51cd05bsalomon@google.com
84ebf2b4fd20e973edb38668acb6f208afa51cd05bsalomon@google.com
96177e6999d23a4268ffd98dedfb1da00e272a89brobertphillips@google.com#ifndef GrGLContext_DEFINED
106177e6999d23a4268ffd98dedfb1da00e272a89brobertphillips@google.com#define GrGLContext_DEFINED
114ebf2b4fd20e973edb38668acb6f208afa51cd05bsalomon@google.com
121744f97ea73384b9f75b0ccee0a36a213c681d3absalomon@google.com#include "gl/GrGLExtensions.h"
136bf38b59c9de1cd35cd091cf8766117f4e1f66a0tomhudson@google.com#include "gl/GrGLInterface.h"
149c1f1ac5d399c73f5f331bdf7b392ea7f0c44dafbsalomon@google.com#include "GrGLCaps.h"
1589ec61e33daa9cbac200d38f7c5bb8b88046999absalomon@google.com#include "GrGLSL.h"
169c1f1ac5d399c73f5f331bdf7b392ea7f0c44dafbsalomon@google.com#include "GrGLUtil.h"
1789ec61e33daa9cbac200d38f7c5bb8b88046999absalomon@google.com
1889ec61e33daa9cbac200d38f7c5bb8b88046999absalomon@google.com#include "SkString.h"
1989ec61e33daa9cbac200d38f7c5bb8b88046999absalomon@google.com
2089ec61e33daa9cbac200d38f7c5bb8b88046999absalomon@google.com/**
21631cdcb4a6b926b6447f328b81911a4499fb3698skia.committer@gmail.com * Encapsulates information about an OpenGL context including the OpenGL
229e90aed5de82732cc9921f01388d3063a41a053bcommit-bot@chromium.org * version, the GrGLStandard type of the context, and GLSL version.
2389ec61e33daa9cbac200d38f7c5bb8b88046999absalomon@google.com */
2489ec61e33daa9cbac200d38f7c5bb8b88046999absalomon@google.comclass GrGLContextInfo {
2589ec61e33daa9cbac200d38f7c5bb8b88046999absalomon@google.compublic:
2689ec61e33daa9cbac200d38f7c5bb8b88046999absalomon@google.com    /**
276177e6999d23a4268ffd98dedfb1da00e272a89brobertphillips@google.com     * Default constructor
2889ec61e33daa9cbac200d38f7c5bb8b88046999absalomon@google.com     */
29bcce8926524827775539874346dd424a9510dbc9bsalomon@google.com    GrGLContextInfo() {
30bcce8926524827775539874346dd424a9510dbc9bsalomon@google.com        fGLCaps.reset(SkNEW(GrGLCaps));
31bcce8926524827775539874346dd424a9510dbc9bsalomon@google.com        this->reset();
32bcce8926524827775539874346dd424a9510dbc9bsalomon@google.com    }
3389ec61e33daa9cbac200d38f7c5bb8b88046999absalomon@google.com
34b1854a85095f9924947bc00e665da47b0c0bdfb9commit-bot@chromium.org    GrGLContextInfo(const GrGLContextInfo& that) {
35b1854a85095f9924947bc00e665da47b0c0bdfb9commit-bot@chromium.org        fGLCaps.reset(SkNEW(GrGLCaps));
36b1854a85095f9924947bc00e665da47b0c0bdfb9commit-bot@chromium.org        *this = that;
37b1854a85095f9924947bc00e665da47b0c0bdfb9commit-bot@chromium.org    }
38b1854a85095f9924947bc00e665da47b0c0bdfb9commit-bot@chromium.org
39b1854a85095f9924947bc00e665da47b0c0bdfb9commit-bot@chromium.org    GrGLContextInfo& operator= (const GrGLContextInfo&);
40631cdcb4a6b926b6447f328b81911a4499fb3698skia.committer@gmail.com
4189ec61e33daa9cbac200d38f7c5bb8b88046999absalomon@google.com    /**
4289ec61e33daa9cbac200d38f7c5bb8b88046999absalomon@google.com     * Initializes a GrGLContextInfo from a GrGLInterface and the currently
4389ec61e33daa9cbac200d38f7c5bb8b88046999absalomon@google.com     * bound OpenGL context accessible by the GrGLInterface.
4489ec61e33daa9cbac200d38f7c5bb8b88046999absalomon@google.com     */
4589ec61e33daa9cbac200d38f7c5bb8b88046999absalomon@google.com    bool initialize(const GrGLInterface* interface);
4689ec61e33daa9cbac200d38f7c5bb8b88046999absalomon@google.com    bool isInitialized() const;
4789ec61e33daa9cbac200d38f7c5bb8b88046999absalomon@google.com
48b1854a85095f9924947bc00e665da47b0c0bdfb9commit-bot@chromium.org    GrGLStandard standard() const { return fInterface->fStandard; }
4989ec61e33daa9cbac200d38f7c5bb8b88046999absalomon@google.com    GrGLVersion version() const { return fGLVersion; }
5089ec61e33daa9cbac200d38f7c5bb8b88046999absalomon@google.com    GrGLSLGeneration glslGeneration() const { return fGLSLGeneration; }
510b1e481709ef9b86261f46e9fd44d8cdec7c2d8ebsalomon@google.com    GrGLVendor vendor() const { return fVendor; }
520694ea7f6a16e946972b9c625f434e80eb42bb5fcommit-bot@chromium.org    GrGLRenderer renderer() const { return fRenderer; }
53459104ceea00a08855099238563a06099340c2facommit-bot@chromium.org    /** Is this a mesa-based driver. Does not mean it is the osmesa software rasterizer. */
54459104ceea00a08855099238563a06099340c2facommit-bot@chromium.org    bool isMesa() const { return fIsMesa; }
55c9424b8e6dc204fc304c021480a04a468899aa34commit-bot@chromium.org    /** Are we running inside Chromium (using the command buffer)? We make some different tradeoffs
56c9424b8e6dc204fc304c021480a04a468899aa34commit-bot@chromium.org        about what errors to check for because queries are synchronous. We should probably expose
57c9424b8e6dc204fc304c021480a04a468899aa34commit-bot@chromium.org        this as an option for clients other than Chromium. */
58c9424b8e6dc204fc304c021480a04a468899aa34commit-bot@chromium.org    bool isChromium() const { return fIsChromium; }
59bcce8926524827775539874346dd424a9510dbc9bsalomon@google.com    const GrGLCaps* caps() const { return fGLCaps.get(); }
60bcce8926524827775539874346dd424a9510dbc9bsalomon@google.com    GrGLCaps* caps() { return fGLCaps; }
6189ec61e33daa9cbac200d38f7c5bb8b88046999absalomon@google.com    bool hasExtension(const char* ext) const {
6289ec61e33daa9cbac200d38f7c5bb8b88046999absalomon@google.com        if (!this->isInitialized()) {
6389ec61e33daa9cbac200d38f7c5bb8b88046999absalomon@google.com            return false;
6489ec61e33daa9cbac200d38f7c5bb8b88046999absalomon@google.com        }
6590313cc36a6f43a3e9d3818aca536cd6631c222bcommit-bot@chromium.org        return fInterface->hasExtension(ext);
6689ec61e33daa9cbac200d38f7c5bb8b88046999absalomon@google.com    }
6789ec61e33daa9cbac200d38f7c5bb8b88046999absalomon@google.com
68e904c09a3a9c701e8d91f2f6ee161feda7615d90bsalomon    const GrGLExtensions& extensions() const { return fInterface->fExtensions; }
69e904c09a3a9c701e8d91f2f6ee161feda7615d90bsalomon
706177e6999d23a4268ffd98dedfb1da00e272a89brobertphillips@google.com    /**
716177e6999d23a4268ffd98dedfb1da00e272a89brobertphillips@google.com     * Reset the information
726177e6999d23a4268ffd98dedfb1da00e272a89brobertphillips@google.com     */
7389ec61e33daa9cbac200d38f7c5bb8b88046999absalomon@google.com    void reset();
7489ec61e33daa9cbac200d38f7c5bb8b88046999absalomon@google.com
75b1854a85095f9924947bc00e665da47b0c0bdfb9commit-bot@chromium.orgprotected:
76b1854a85095f9924947bc00e665da47b0c0bdfb9commit-bot@chromium.org    SkAutoTUnref<const GrGLInterface>   fInterface;
77b1854a85095f9924947bc00e665da47b0c0bdfb9commit-bot@chromium.org    GrGLVersion                         fGLVersion;
78b1854a85095f9924947bc00e665da47b0c0bdfb9commit-bot@chromium.org    GrGLSLGeneration                    fGLSLGeneration;
79b1854a85095f9924947bc00e665da47b0c0bdfb9commit-bot@chromium.org    GrGLVendor                          fVendor;
80b1854a85095f9924947bc00e665da47b0c0bdfb9commit-bot@chromium.org    GrGLRenderer                        fRenderer;
81b1854a85095f9924947bc00e665da47b0c0bdfb9commit-bot@chromium.org    bool                                fIsMesa;
82b1854a85095f9924947bc00e665da47b0c0bdfb9commit-bot@chromium.org    bool                                fIsChromium;
83b1854a85095f9924947bc00e665da47b0c0bdfb9commit-bot@chromium.org    SkAutoTUnref<GrGLCaps>              fGLCaps;
8489ec61e33daa9cbac200d38f7c5bb8b88046999absalomon@google.com};
854ebf2b4fd20e973edb38668acb6f208afa51cd05bsalomon@google.com
866177e6999d23a4268ffd98dedfb1da00e272a89brobertphillips@google.com/**
87b1854a85095f9924947bc00e665da47b0c0bdfb9commit-bot@chromium.org * Extension of GrGLContextInfo that also provides access to GrGLInterface.
886177e6999d23a4268ffd98dedfb1da00e272a89brobertphillips@google.com */
89b1854a85095f9924947bc00e665da47b0c0bdfb9commit-bot@chromium.orgclass GrGLContext : public GrGLContextInfo {
906177e6999d23a4268ffd98dedfb1da00e272a89brobertphillips@google.compublic:
916177e6999d23a4268ffd98dedfb1da00e272a89brobertphillips@google.com    /**
926177e6999d23a4268ffd98dedfb1da00e272a89brobertphillips@google.com     * Creates a GrGLContext from a GrGLInterface and the currently
936177e6999d23a4268ffd98dedfb1da00e272a89brobertphillips@google.com     * bound OpenGL context accessible by the GrGLInterface.
946177e6999d23a4268ffd98dedfb1da00e272a89brobertphillips@google.com     */
95b1854a85095f9924947bc00e665da47b0c0bdfb9commit-bot@chromium.org    explicit GrGLContext(const GrGLInterface* interface) {
96b1854a85095f9924947bc00e665da47b0c0bdfb9commit-bot@chromium.org        this->initialize(interface);
97b1854a85095f9924947bc00e665da47b0c0bdfb9commit-bot@chromium.org    }
986177e6999d23a4268ffd98dedfb1da00e272a89brobertphillips@google.com
99b1854a85095f9924947bc00e665da47b0c0bdfb9commit-bot@chromium.org    GrGLContext(const GrGLContext& that) : INHERITED(that) {}
1006177e6999d23a4268ffd98dedfb1da00e272a89brobertphillips@google.com
101b1854a85095f9924947bc00e665da47b0c0bdfb9commit-bot@chromium.org    GrGLContext& operator= (const GrGLContext& that) {
102b1854a85095f9924947bc00e665da47b0c0bdfb9commit-bot@chromium.org        this->INHERITED::operator=(that);
103b1854a85095f9924947bc00e665da47b0c0bdfb9commit-bot@chromium.org        return *this;
104b1854a85095f9924947bc00e665da47b0c0bdfb9commit-bot@chromium.org    }
1056177e6999d23a4268ffd98dedfb1da00e272a89brobertphillips@google.com
106b1854a85095f9924947bc00e665da47b0c0bdfb9commit-bot@chromium.org    const GrGLInterface* interface() const { return fInterface.get(); }
1076177e6999d23a4268ffd98dedfb1da00e272a89brobertphillips@google.com
1086177e6999d23a4268ffd98dedfb1da00e272a89brobertphillips@google.comprivate:
109b1854a85095f9924947bc00e665da47b0c0bdfb9commit-bot@chromium.org    typedef GrGLContextInfo INHERITED;
1106177e6999d23a4268ffd98dedfb1da00e272a89brobertphillips@google.com};
1116177e6999d23a4268ffd98dedfb1da00e272a89brobertphillips@google.com
1124ebf2b4fd20e973edb38668acb6f208afa51cd05bsalomon@google.com#endif
113