1//
2// Copyright (c) 2013 The ANGLE Project Authors. All rights reserved.
3// Use of this source code is governed by a BSD-style license that can be
4// found in the LICENSE file.
5//
6
7// Fence9.cpp: Defines the rx::Fence9 class.
8
9#include "libGLESv2/renderer/d3d/d3d9/Fence9.h"
10#include "libGLESv2/renderer/d3d/d3d9/renderer9_utils.h"
11#include "libGLESv2/renderer/d3d/d3d9/Renderer9.h"
12#include "libGLESv2/main.h"
13
14namespace rx
15{
16
17Fence9::Fence9(rx::Renderer9 *renderer)
18{
19    mRenderer = renderer;
20    mQuery = NULL;
21}
22
23Fence9::~Fence9()
24{
25    SafeRelease(mQuery);
26}
27
28bool Fence9::isSet() const
29{
30    return mQuery != NULL;
31}
32
33void Fence9::set()
34{
35    if (!mQuery)
36    {
37        mQuery = mRenderer->allocateEventQuery();
38        if (!mQuery)
39        {
40            return gl::error(GL_OUT_OF_MEMORY);
41        }
42    }
43
44    HRESULT result = mQuery->Issue(D3DISSUE_END);
45    UNUSED_ASSERTION_VARIABLE(result);
46    ASSERT(SUCCEEDED(result));
47}
48
49bool Fence9::test(bool flushCommandBuffer)
50{
51    ASSERT(mQuery);
52
53    DWORD getDataFlags = (flushCommandBuffer ? D3DGETDATA_FLUSH : 0);
54    HRESULT result = mQuery->GetData(NULL, 0, getDataFlags);
55
56    if (d3d9::isDeviceLostError(result))
57    {
58        mRenderer->notifyDeviceLost();
59        return gl::error(GL_OUT_OF_MEMORY, true);
60    }
61
62    ASSERT(result == S_OK || result == S_FALSE);
63
64    return (result == S_OK);
65}
66
67bool Fence9::hasError() const
68{
69    return mRenderer->isDeviceLost();
70}
71
72}
73