gfx/angle/src/libGLESv2/renderer/Fence9.cpp

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/gfx/angle/src/libGLESv2/renderer/Fence9.cpp	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,135 @@
     1.4 +#include "precompiled.h"
     1.5 +//
     1.6 +// Copyright (c) 2013 The ANGLE Project Authors. All rights reserved.
     1.7 +// Use of this source code is governed by a BSD-style license that can be
     1.8 +// found in the LICENSE file.
     1.9 +//
    1.10 +
    1.11 +// Fence9.cpp: Defines the rx::Fence9 class.
    1.12 +
    1.13 +#include "libGLESv2/renderer/Fence9.h"
    1.14 +#include "libGLESv2/main.h"
    1.15 +#include "libGLESv2/renderer/renderer9_utils.h"
    1.16 +#include "libGLESv2/renderer/Renderer9.h"
    1.17 +
    1.18 +namespace rx
    1.19 +{
    1.20 +
    1.21 +Fence9::Fence9(rx::Renderer9 *renderer)
    1.22 +{
    1.23 +    mRenderer = renderer;
    1.24 +    mQuery = NULL;
    1.25 +}
    1.26 +
    1.27 +Fence9::~Fence9()
    1.28 +{
    1.29 +    if (mQuery)
    1.30 +    {
    1.31 +        mRenderer->freeEventQuery(mQuery);
    1.32 +        mQuery = NULL;
    1.33 +    }
    1.34 +}
    1.35 +
    1.36 +GLboolean Fence9::isFence()
    1.37 +{
    1.38 +    // GL_NV_fence spec:
    1.39 +    // A name returned by GenFencesNV, but not yet set via SetFenceNV, is not the name of an existing fence.
    1.40 +    return mQuery != NULL;
    1.41 +}
    1.42 +
    1.43 +void Fence9::setFence(GLenum condition)
    1.44 +{
    1.45 +    if (!mQuery)
    1.46 +    {
    1.47 +        mQuery = mRenderer->allocateEventQuery();
    1.48 +        if (!mQuery)
    1.49 +        {
    1.50 +            return gl::error(GL_OUT_OF_MEMORY);
    1.51 +        }
    1.52 +    }
    1.53 +
    1.54 +    HRESULT result = mQuery->Issue(D3DISSUE_END);
    1.55 +    ASSERT(SUCCEEDED(result));
    1.56 +
    1.57 +    setCondition(condition);
    1.58 +    setStatus(GL_FALSE);
    1.59 +}
    1.60 +
    1.61 +GLboolean Fence9::testFence()
    1.62 +{
    1.63 +    if (mQuery == NULL)
    1.64 +    {
    1.65 +        return gl::error(GL_INVALID_OPERATION, GL_TRUE);
    1.66 +    }
    1.67 +
    1.68 +    HRESULT result = mQuery->GetData(NULL, 0, D3DGETDATA_FLUSH);
    1.69 +
    1.70 +    if (d3d9::isDeviceLostError(result))
    1.71 +    {
    1.72 +        mRenderer->notifyDeviceLost();
    1.73 +        return gl::error(GL_OUT_OF_MEMORY, GL_TRUE);
    1.74 +    }
    1.75 +
    1.76 +    ASSERT(result == S_OK || result == S_FALSE);
    1.77 +    setStatus(result == S_OK);
    1.78 +    return getStatus();
    1.79 +}
    1.80 +
    1.81 +void Fence9::finishFence()
    1.82 +{
    1.83 +    if (mQuery == NULL)
    1.84 +    {
    1.85 +        return gl::error(GL_INVALID_OPERATION);
    1.86 +    }
    1.87 +
    1.88 +    while (!testFence())
    1.89 +    {
    1.90 +        Sleep(0);
    1.91 +    }
    1.92 +}
    1.93 +
    1.94 +void Fence9::getFenceiv(GLenum pname, GLint *params)
    1.95 +{
    1.96 +    if (mQuery == NULL)
    1.97 +    {
    1.98 +        return gl::error(GL_INVALID_OPERATION);
    1.99 +    }
   1.100 +
   1.101 +    switch (pname)
   1.102 +    {
   1.103 +        case GL_FENCE_STATUS_NV:
   1.104 +        {
   1.105 +            // GL_NV_fence spec:
   1.106 +            // Once the status of a fence has been finished (via FinishFenceNV) or tested and the returned status is TRUE (via either TestFenceNV
   1.107 +            // or GetFenceivNV querying the FENCE_STATUS_NV), the status remains TRUE until the next SetFenceNV of the fence.
   1.108 +            if (getStatus())
   1.109 +            {
   1.110 +                params[0] = GL_TRUE;
   1.111 +                return;
   1.112 +            }
   1.113 +            
   1.114 +            HRESULT result = mQuery->GetData(NULL, 0, 0);
   1.115 +
   1.116 +            if (d3d9::isDeviceLostError(result))
   1.117 +            {
   1.118 +                params[0] = GL_TRUE;
   1.119 +                mRenderer->notifyDeviceLost();
   1.120 +                return gl::error(GL_OUT_OF_MEMORY);
   1.121 +            }
   1.122 +
   1.123 +            ASSERT(result == S_OK || result == S_FALSE);
   1.124 +            setStatus(result == S_OK);
   1.125 +            params[0] = getStatus();
   1.126 +
   1.127 +            break;
   1.128 +        }
   1.129 +        case GL_FENCE_CONDITION_NV:
   1.130 +            params[0] = getCondition();
   1.131 +            break;
   1.132 +        default:
   1.133 +            return gl::error(GL_INVALID_ENUM);
   1.134 +            break;
   1.135 +    }
   1.136 +}
   1.137 +
   1.138 +}

mercurial