Home | History | Annotate | Download | only in canvas
      1 /*
      2  * Copyright (c) 2010, Google Inc. All rights reserved.
      3  *
      4  * Redistribution and use in source and binary forms, with or without
      5  * modification, are permitted provided that the following conditions are
      6  * met:
      7  *     * Redistributions of source code must retain the above copyright
      8  * notice, this list of conditions and the following disclaimer.
      9  *     * Redistributions in binary form must reproduce the above
     10  * copyright notice, this list of conditions and the following disclaimer
     11  * in the documentation and/or other materials provided with the
     12  * distribution.
     13  *
     14  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
     15  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
     16  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
     17  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
     18  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
     19  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
     20  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     21  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     22  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     23  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
     24  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     25  */
     26 
     27 #include "config.h"
     28 
     29 #include "core/html/canvas/WebGLContextAttributes.h"
     30 
     31 #include "core/frame/Settings.h"
     32 
     33 namespace WebCore {
     34 
     35 PassRefPtr<WebGLContextAttributes> WebGLContextAttributes::create()
     36 {
     37     return adoptRef(new WebGLContextAttributes());
     38 }
     39 
     40 WebGLContextAttributes::WebGLContextAttributes()
     41     : CanvasContextAttributes()
     42     , m_alpha(true)
     43     , m_depth(true)
     44     , m_stencil(false)
     45     , m_antialias(true)
     46     , m_premultipliedAlpha(true)
     47     , m_preserveDrawingBuffer(false)
     48     , m_failIfMajorPerformanceCaveat(false)
     49 {
     50     ScriptWrappable::init(this);
     51 }
     52 
     53 WebGLContextAttributes::WebGLContextAttributes(const WebGLContextAttributes& attrs)
     54     : CanvasContextAttributes()
     55     , m_alpha(attrs.m_alpha)
     56     , m_depth(attrs.m_depth)
     57     , m_stencil(attrs.m_stencil)
     58     , m_antialias(attrs.m_antialias)
     59     , m_premultipliedAlpha(attrs.m_premultipliedAlpha)
     60     , m_preserveDrawingBuffer(attrs.m_preserveDrawingBuffer)
     61     , m_failIfMajorPerformanceCaveat(attrs.m_failIfMajorPerformanceCaveat)
     62 {
     63     ScriptWrappable::init(this);
     64 }
     65 
     66 WebGLContextAttributes::~WebGLContextAttributes()
     67 {
     68 }
     69 
     70 PassRefPtr<WebGLContextAttributes> WebGLContextAttributes::clone() const
     71 {
     72     return adoptRef(new WebGLContextAttributes(*this));
     73 }
     74 
     75 bool WebGLContextAttributes::alpha() const
     76 {
     77     return m_alpha;
     78 }
     79 
     80 void WebGLContextAttributes::setAlpha(bool alpha)
     81 {
     82     m_alpha = alpha;
     83 }
     84 
     85 bool WebGLContextAttributes::depth() const
     86 {
     87     return m_depth;
     88 }
     89 
     90 void WebGLContextAttributes::setDepth(bool depth)
     91 {
     92     m_depth = depth;
     93 }
     94 
     95 bool WebGLContextAttributes::stencil() const
     96 {
     97     return m_stencil;
     98 }
     99 
    100 void WebGLContextAttributes::setStencil(bool stencil)
    101 {
    102     m_stencil = stencil;
    103 }
    104 
    105 bool WebGLContextAttributes::antialias() const
    106 {
    107     return m_antialias;
    108 }
    109 
    110 void WebGLContextAttributes::setAntialias(bool antialias)
    111 {
    112     m_antialias = antialias;
    113 }
    114 
    115 bool WebGLContextAttributes::premultipliedAlpha() const
    116 {
    117     return m_premultipliedAlpha;
    118 }
    119 
    120 void WebGLContextAttributes::setPremultipliedAlpha(bool premultipliedAlpha)
    121 {
    122     m_premultipliedAlpha = premultipliedAlpha;
    123 }
    124 
    125 bool WebGLContextAttributes::preserveDrawingBuffer() const
    126 {
    127     return m_preserveDrawingBuffer;
    128 }
    129 
    130 void WebGLContextAttributes::setPreserveDrawingBuffer(bool preserveDrawingBuffer)
    131 {
    132     m_preserveDrawingBuffer = preserveDrawingBuffer;
    133 }
    134 
    135 bool WebGLContextAttributes::failIfMajorPerformanceCaveat() const
    136 {
    137     return m_failIfMajorPerformanceCaveat;
    138 }
    139 
    140 void WebGLContextAttributes::setFailIfMajorPerformanceCaveat(bool failIfMajorPerformanceCaveat)
    141 {
    142     m_failIfMajorPerformanceCaveat = failIfMajorPerformanceCaveat;
    143 }
    144 
    145 blink::WebGraphicsContext3D::Attributes WebGLContextAttributes::attributes(
    146     const blink::WebString& topDocumentURL, Settings* settings) const
    147 {
    148     blink::WebGraphicsContext3D::Attributes attrs;
    149 
    150     attrs.alpha = m_alpha;
    151     attrs.depth = m_depth;
    152     attrs.stencil = m_stencil;
    153     attrs.antialias = m_antialias;
    154     if (m_antialias) {
    155         if (settings && !settings->openGLMultisamplingEnabled())
    156             attrs.antialias = false;
    157     }
    158     attrs.premultipliedAlpha = m_premultipliedAlpha;
    159     attrs.failIfMajorPerformanceCaveat = m_failIfMajorPerformanceCaveat;
    160 
    161     attrs.noExtensions = true;
    162     attrs.shareResources = false;
    163     attrs.preferDiscreteGPU = true;
    164 
    165     attrs.topDocumentURL = topDocumentURL;
    166 
    167     return attrs;
    168 }
    169 
    170 } // namespace WebCore
    171