gfx/skia/trunk/src/gpu/gl/GrGLIRect.h

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     1 /*
     2  * Copyright 2011 Google Inc.
     3  *
     4  * Use of this source code is governed by a BSD-style license that can be
     5  * found in the LICENSE file.
     6  */
    10 #ifndef GrGLIRect_DEFINED
    11 #define GrGLIRect_DEFINED
    13 #include "gl/GrGLInterface.h"
    14 #include "GrGLUtil.h"
    16 /**
    17  * Helper struct for dealing with the fact that Ganesh and GL use different
    18  * window coordinate systems (top-down vs bottom-up)
    19  */
    20 struct GrGLIRect {
    21     GrGLint   fLeft;
    22     GrGLint   fBottom;
    23     GrGLsizei fWidth;
    24     GrGLsizei fHeight;
    26     void pushToGLViewport(const GrGLInterface* gl) const {
    27         GR_GL_CALL(gl, Viewport(fLeft, fBottom, fWidth, fHeight));
    28     }
    30     void pushToGLScissor(const GrGLInterface* gl) const {
    31         GR_GL_CALL(gl, Scissor(fLeft, fBottom, fWidth, fHeight));
    32     }
    34     void setFromGLViewport(const GrGLInterface* gl) {
    35         GR_STATIC_ASSERT(sizeof(GrGLIRect) == 4*sizeof(GrGLint));
    36         GR_GL_GetIntegerv(gl, GR_GL_VIEWPORT, (GrGLint*) this);
    37     }
    39     // sometimes we have a SkIRect from the client that we
    40     // want to simultaneously make relative to GL's viewport
    41     // and (optionally) convert from top-down to bottom-up.
    42     void setRelativeTo(const GrGLIRect& glRect,
    43                        int leftOffset,
    44                        int topOffset,
    45                        int width,
    46                        int height,
    47                        GrSurfaceOrigin origin) {
    48         fLeft = glRect.fLeft + leftOffset;
    49         fWidth = width;
    50         if (kBottomLeft_GrSurfaceOrigin == origin) {
    51             fBottom = glRect.fBottom + (glRect.fHeight - topOffset - height);
    52         } else {
    53             fBottom = glRect.fBottom + topOffset;
    54         }
    55         fHeight = height;
    57         SkASSERT(fLeft >= 0);
    58         SkASSERT(fWidth >= 0);
    59         SkASSERT(fBottom >= 0);
    60         SkASSERT(fHeight >= 0);
    61     }
    63     bool contains(const GrGLIRect& glRect) const {
    64         return fLeft <= glRect.fLeft &&
    65                fBottom <= glRect.fBottom &&
    66                fLeft + fWidth >=  glRect.fLeft + glRect.fWidth &&
    67                fBottom + fHeight >=  glRect.fBottom + glRect.fHeight;
    68     }
    70     void invalidate() {fLeft = fWidth = fBottom = fHeight = -1;}
    72     bool operator ==(const GrGLIRect& glRect) const {
    73         return 0 == memcmp(this, &glRect, sizeof(GrGLIRect));
    74     }
    76     bool operator !=(const GrGLIRect& glRect) const {return !(*this == glRect);}
    77 };
    79 #endif

mercurial