• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #include "precompiled.h"
2 //
3 // Copyright (c) 2013 The ANGLE Project Authors. All rights reserved.
4 // Use of this source code is governed by a BSD-style license that can be
5 // found in the LICENSE file.
6 //
7 
8 // Query9.cpp: Defines the rx::Query9 class which implements rx::QueryImpl.
9 
10 
11 #include "libGLESv2/renderer/Query9.h"
12 #include "libGLESv2/main.h"
13 #include "libGLESv2/renderer/renderer9_utils.h"
14 #include "libGLESv2/renderer/Renderer9.h"
15 
16 namespace rx
17 {
18 
Query9(rx::Renderer9 * renderer,GLenum type)19 Query9::Query9(rx::Renderer9 *renderer, GLenum type) : QueryImpl(type)
20 {
21     mRenderer = renderer;
22     mQuery = NULL;
23 }
24 
~Query9()25 Query9::~Query9()
26 {
27     if (mQuery)
28     {
29         mQuery->Release();
30         mQuery = NULL;
31     }
32 }
33 
begin()34 void Query9::begin()
35 {
36     if (mQuery == NULL)
37     {
38         if (FAILED(mRenderer->getDevice()->CreateQuery(D3DQUERYTYPE_OCCLUSION, &mQuery)))
39         {
40             return gl::error(GL_OUT_OF_MEMORY);
41         }
42     }
43 
44     HRESULT result = mQuery->Issue(D3DISSUE_BEGIN);
45     ASSERT(SUCCEEDED(result));
46 }
47 
end()48 void Query9::end()
49 {
50     if (mQuery == NULL)
51     {
52         return gl::error(GL_INVALID_OPERATION);
53     }
54 
55     HRESULT result = mQuery->Issue(D3DISSUE_END);
56     ASSERT(SUCCEEDED(result));
57 
58     mStatus = GL_FALSE;
59     mResult = GL_FALSE;
60 }
61 
getResult()62 GLuint Query9::getResult()
63 {
64     if (mQuery != NULL)
65     {
66         while (!testQuery())
67         {
68             Sleep(0);
69             // explicitly check for device loss
70             // some drivers seem to return S_FALSE even if the device is lost
71             // instead of D3DERR_DEVICELOST like they should
72             if (mRenderer->testDeviceLost(true))
73             {
74                 return gl::error(GL_OUT_OF_MEMORY, 0);
75             }
76         }
77     }
78 
79     return mResult;
80 }
81 
isResultAvailable()82 GLboolean Query9::isResultAvailable()
83 {
84     if (mQuery != NULL)
85     {
86         testQuery();
87     }
88 
89     return mStatus;
90 }
91 
testQuery()92 GLboolean Query9::testQuery()
93 {
94     if (mQuery != NULL && mStatus != GL_TRUE)
95     {
96         DWORD numPixels = 0;
97 
98         HRESULT hres = mQuery->GetData(&numPixels, sizeof(DWORD), D3DGETDATA_FLUSH);
99         if (hres == S_OK)
100         {
101             mStatus =  GL_TRUE;
102 
103             switch (getType())
104             {
105               case GL_ANY_SAMPLES_PASSED_EXT:
106               case GL_ANY_SAMPLES_PASSED_CONSERVATIVE_EXT:
107                 mResult = (numPixels > 0) ? GL_TRUE : GL_FALSE;
108                 break;
109               default:
110                 ASSERT(false);
111             }
112         }
113         else if (d3d9::isDeviceLostError(hres))
114         {
115             mRenderer->notifyDeviceLost();
116             return gl::error(GL_OUT_OF_MEMORY, GL_TRUE);
117         }
118 
119         return mStatus;
120     }
121 
122     return GL_TRUE; // prevent blocking when query is null
123 }
124 
125 }
126