WebGLObjectModel.h (1828B)
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 2 /* This Source Code Form is subject to the terms of the Mozilla Public 3 * License, v. 2.0. If a copy of the MPL was not distributed with this 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 5 6 #ifndef WEBGLOBJECTMODEL_H_ 7 #define WEBGLOBJECTMODEL_H_ 8 9 #include "WebGLTypes.h" 10 #include "mozilla/WeakPtr.h" 11 12 namespace mozilla { 13 14 class WebGLContext; 15 16 //// 17 18 // This class is a mixin for objects that are tied to a specific 19 // context (which is to say, all of them). They provide initialization 20 // as well as comparison with the current context. 21 class WebGLContextBoundObject : public VRefCounted { 22 public: 23 const WeakPtr<WebGLContext> mContext; 24 25 explicit WebGLContextBoundObject(WebGLContext* webgl); 26 27 private: 28 friend class HostWebGLContext; 29 }; 30 31 //// 32 33 // this class is a mixin for GL objects that have dimensions 34 // that we need to track. 35 class WebGLRectangleObject { 36 public: 37 WebGLRectangleObject() : mWidth(0), mHeight(0) {} 38 39 WebGLRectangleObject(GLsizei width, GLsizei height) 40 : mWidth(width), mHeight(height) {} 41 42 GLsizei Width() const { return mWidth; } 43 void width(GLsizei value) { mWidth = value; } 44 45 GLsizei Height() const { return mHeight; } 46 void height(GLsizei value) { mHeight = value; } 47 48 void setDimensions(GLsizei width, GLsizei height) { 49 mWidth = width; 50 mHeight = height; 51 } 52 53 void setDimensions(WebGLRectangleObject* rect) { 54 if (rect) { 55 mWidth = rect->Width(); 56 mHeight = rect->Height(); 57 } else { 58 mWidth = 0; 59 mHeight = 0; 60 } 61 } 62 63 bool HasSameDimensionsAs(const WebGLRectangleObject& other) const { 64 return Width() == other.Width() && Height() == other.Height(); 65 } 66 67 protected: 68 GLsizei mWidth; 69 GLsizei mHeight; 70 }; 71 72 } // namespace mozilla 73 74 #endif