Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / third_party / angle / src / libGLESv2 / renderer / d3d / d3d9 / Fence9.cpp
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::FenceNV9 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
14 namespace rx
15 {
16
17 FenceNV9::FenceNV9(Renderer9 *renderer)
18     : FenceNVImpl(),
19       mRenderer(renderer),
20       mQuery(NULL)
21 {
22 }
23
24 FenceNV9::~FenceNV9()
25 {
26     SafeRelease(mQuery);
27 }
28
29 gl::Error FenceNV9::set()
30 {
31     if (!mQuery)
32     {
33         gl::Error error = mRenderer->allocateEventQuery(&mQuery);
34         if (error.isError())
35         {
36             return error;
37         }
38     }
39
40     HRESULT result = mQuery->Issue(D3DISSUE_END);
41     if (FAILED(result))
42     {
43         ASSERT(result == D3DERR_OUTOFVIDEOMEMORY || result == E_OUTOFMEMORY);
44         SafeRelease(mQuery);
45         return gl::Error(GL_OUT_OF_MEMORY, "Failed to end event query, result: 0x%X.", result);
46     }
47
48     return gl::Error(GL_NO_ERROR);
49 }
50
51 gl::Error FenceNV9::test(bool flushCommandBuffer, GLboolean *outFinished)
52 {
53     ASSERT(mQuery);
54
55     DWORD getDataFlags = (flushCommandBuffer ? D3DGETDATA_FLUSH : 0);
56     HRESULT result = mQuery->GetData(NULL, 0, getDataFlags);
57
58     if (d3d9::isDeviceLostError(result))
59     {
60         mRenderer->notifyDeviceLost();
61         return gl::Error(GL_OUT_OF_MEMORY, "Device was lost while querying result of an event query.");
62     }
63     else if (FAILED(result))
64     {
65         return gl::Error(GL_OUT_OF_MEMORY, "Failed to get query data, result: 0x%X.", result);
66     }
67
68     ASSERT(result == S_OK || result == S_FALSE);
69     *outFinished = ((result == S_OK) ? GL_TRUE : GL_FALSE);
70     return gl::Error(GL_NO_ERROR);
71 }
72
73 gl::Error FenceNV9::finishFence(GLboolean *outFinished)
74 {
75     ASSERT(outFinished);
76
77     while (*outFinished != GL_TRUE)
78     {
79         gl::Error error = test(true, outFinished);
80         if (error.isError())
81         {
82             return error;
83         }
84
85         Sleep(0);
86     }
87
88     return gl::Error(GL_NO_ERROR);
89 }
90
91 }