1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/gfx/angle/src/libGLESv2/renderer/Query9.cpp Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,125 @@ 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 +// Query9.cpp: Defines the rx::Query9 class which implements rx::QueryImpl. 1.12 + 1.13 + 1.14 +#include "libGLESv2/renderer/Query9.h" 1.15 +#include "libGLESv2/main.h" 1.16 +#include "libGLESv2/renderer/renderer9_utils.h" 1.17 +#include "libGLESv2/renderer/Renderer9.h" 1.18 + 1.19 +namespace rx 1.20 +{ 1.21 + 1.22 +Query9::Query9(rx::Renderer9 *renderer, GLenum type) : QueryImpl(type) 1.23 +{ 1.24 + mRenderer = renderer; 1.25 + mQuery = NULL; 1.26 +} 1.27 + 1.28 +Query9::~Query9() 1.29 +{ 1.30 + if (mQuery) 1.31 + { 1.32 + mQuery->Release(); 1.33 + mQuery = NULL; 1.34 + } 1.35 +} 1.36 + 1.37 +void Query9::begin() 1.38 +{ 1.39 + if (mQuery == NULL) 1.40 + { 1.41 + if (FAILED(mRenderer->getDevice()->CreateQuery(D3DQUERYTYPE_OCCLUSION, &mQuery))) 1.42 + { 1.43 + return gl::error(GL_OUT_OF_MEMORY); 1.44 + } 1.45 + } 1.46 + 1.47 + HRESULT result = mQuery->Issue(D3DISSUE_BEGIN); 1.48 + ASSERT(SUCCEEDED(result)); 1.49 +} 1.50 + 1.51 +void Query9::end() 1.52 +{ 1.53 + if (mQuery == NULL) 1.54 + { 1.55 + return gl::error(GL_INVALID_OPERATION); 1.56 + } 1.57 + 1.58 + HRESULT result = mQuery->Issue(D3DISSUE_END); 1.59 + ASSERT(SUCCEEDED(result)); 1.60 + 1.61 + mStatus = GL_FALSE; 1.62 + mResult = GL_FALSE; 1.63 +} 1.64 + 1.65 +GLuint Query9::getResult() 1.66 +{ 1.67 + if (mQuery != NULL) 1.68 + { 1.69 + while (!testQuery()) 1.70 + { 1.71 + Sleep(0); 1.72 + // explicitly check for device loss 1.73 + // some drivers seem to return S_FALSE even if the device is lost 1.74 + // instead of D3DERR_DEVICELOST like they should 1.75 + if (mRenderer->testDeviceLost(true)) 1.76 + { 1.77 + return gl::error(GL_OUT_OF_MEMORY, 0); 1.78 + } 1.79 + } 1.80 + } 1.81 + 1.82 + return mResult; 1.83 +} 1.84 + 1.85 +GLboolean Query9::isResultAvailable() 1.86 +{ 1.87 + if (mQuery != NULL) 1.88 + { 1.89 + testQuery(); 1.90 + } 1.91 + 1.92 + return mStatus; 1.93 +} 1.94 + 1.95 +GLboolean Query9::testQuery() 1.96 +{ 1.97 + if (mQuery != NULL && mStatus != GL_TRUE) 1.98 + { 1.99 + DWORD numPixels = 0; 1.100 + 1.101 + HRESULT hres = mQuery->GetData(&numPixels, sizeof(DWORD), D3DGETDATA_FLUSH); 1.102 + if (hres == S_OK) 1.103 + { 1.104 + mStatus = GL_TRUE; 1.105 + 1.106 + switch (getType()) 1.107 + { 1.108 + case GL_ANY_SAMPLES_PASSED_EXT: 1.109 + case GL_ANY_SAMPLES_PASSED_CONSERVATIVE_EXT: 1.110 + mResult = (numPixels > 0) ? GL_TRUE : GL_FALSE; 1.111 + break; 1.112 + default: 1.113 + ASSERT(false); 1.114 + } 1.115 + } 1.116 + else if (d3d9::isDeviceLostError(hres)) 1.117 + { 1.118 + mRenderer->notifyDeviceLost(); 1.119 + return gl::error(GL_OUT_OF_MEMORY, GL_TRUE); 1.120 + } 1.121 + 1.122 + return mStatus; 1.123 + } 1.124 + 1.125 + return GL_TRUE; // prevent blocking when query is null 1.126 +} 1.127 + 1.128 +}