• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //
2 // Copyright 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::FenceNV9 class.
8 
9 #include "libANGLE/renderer/d3d/d3d9/Fence9.h"
10 
11 #include "libANGLE/Context.h"
12 #include "libANGLE/renderer/d3d/d3d9/Context9.h"
13 #include "libANGLE/renderer/d3d/d3d9/Renderer9.h"
14 #include "libANGLE/renderer/d3d/d3d9/renderer9_utils.h"
15 
16 namespace rx
17 {
18 
FenceNV9(Renderer9 * renderer)19 FenceNV9::FenceNV9(Renderer9 *renderer) : FenceNVImpl(), mRenderer(renderer), mQuery(nullptr) {}
20 
~FenceNV9()21 FenceNV9::~FenceNV9()
22 {
23     SafeRelease(mQuery);
24 }
25 
set(const gl::Context * context,GLenum condition)26 angle::Result FenceNV9::set(const gl::Context *context, GLenum condition)
27 {
28     if (!mQuery)
29     {
30         ANGLE_TRY(mRenderer->allocateEventQuery(context, &mQuery));
31     }
32 
33     HRESULT result = mQuery->Issue(D3DISSUE_END);
34     if (FAILED(result))
35     {
36         SafeRelease(mQuery);
37     }
38     ANGLE_TRY_HR(GetImplAs<Context9>(context), result, "Failed to end event query");
39     return angle::Result::Continue;
40 }
41 
test(const gl::Context * context,GLboolean * outFinished)42 angle::Result FenceNV9::test(const gl::Context *context, GLboolean *outFinished)
43 {
44     return testHelper(GetImplAs<Context9>(context), true, outFinished);
45 }
46 
finish(const gl::Context * context)47 angle::Result FenceNV9::finish(const gl::Context *context)
48 {
49     GLboolean finished = GL_FALSE;
50     while (finished != GL_TRUE)
51     {
52         ANGLE_TRY(testHelper(GetImplAs<Context9>(context), true, &finished));
53         Sleep(0);
54     }
55 
56     return angle::Result::Continue;
57 }
58 
testHelper(Context9 * context9,bool flushCommandBuffer,GLboolean * outFinished)59 angle::Result FenceNV9::testHelper(Context9 *context9,
60                                    bool flushCommandBuffer,
61                                    GLboolean *outFinished)
62 {
63     ASSERT(mQuery);
64 
65     DWORD getDataFlags = (flushCommandBuffer ? D3DGETDATA_FLUSH : 0);
66     HRESULT result     = mQuery->GetData(nullptr, 0, getDataFlags);
67     ANGLE_TRY_HR(context9, result, "Failed to get query data");
68     ASSERT(result == S_OK || result == S_FALSE);
69     *outFinished = ((result == S_OK) ? GL_TRUE : GL_FALSE);
70     return angle::Result::Continue;
71 }
72 
73 }  // namespace rx
74