gfx/angle/src/libGLESv2/renderer/Renderer.cpp

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

michael@0 1 #include "precompiled.h"
michael@0 2 //
michael@0 3 // Copyright (c) 2012-2013 The ANGLE Project Authors. All rights reserved.
michael@0 4 // Use of this source code is governed by a BSD-style license that can be
michael@0 5 // found in the LICENSE file.
michael@0 6 //
michael@0 7
michael@0 8 // Renderer.cpp: Implements EGL dependencies for creating and destroying Renderer instances.
michael@0 9
michael@0 10 #include <EGL/eglext.h>
michael@0 11 #include "libGLESv2/main.h"
michael@0 12 #include "libGLESv2/Program.h"
michael@0 13 #include "libGLESv2/renderer/Renderer.h"
michael@0 14 #include "libGLESv2/renderer/Renderer9.h"
michael@0 15 #include "libGLESv2/renderer/Renderer11.h"
michael@0 16 #include "libGLESv2/utilities.h"
michael@0 17
michael@0 18 #if !defined(ANGLE_ENABLE_D3D11)
michael@0 19 // Enables use of the Direct3D 11 API for a default display, when available
michael@0 20 #define ANGLE_ENABLE_D3D11 0
michael@0 21 #endif
michael@0 22
michael@0 23 #define ANGLE_PRELOADED_D3DCOMPILER_MODULE_NAMES \
michael@0 24 { \
michael@0 25 TEXT("d3dcompiler_47.dll"), \
michael@0 26 TEXT("d3dcompiler_46.dll"), \
michael@0 27 TEXT("d3dcompiler_43.dll") \
michael@0 28 }
michael@0 29
michael@0 30
michael@0 31 namespace rx
michael@0 32 {
michael@0 33
michael@0 34 Renderer::Renderer(egl::Display *display) : mDisplay(display)
michael@0 35 {
michael@0 36 mD3dCompilerModule = NULL;
michael@0 37 mD3DCompileFunc = NULL;
michael@0 38 }
michael@0 39
michael@0 40 Renderer::~Renderer()
michael@0 41 {
michael@0 42 if (mD3dCompilerModule)
michael@0 43 {
michael@0 44 FreeLibrary(mD3dCompilerModule);
michael@0 45 mD3dCompilerModule = NULL;
michael@0 46 }
michael@0 47 }
michael@0 48
michael@0 49 bool Renderer::initializeCompiler()
michael@0 50 {
michael@0 51 #if defined(ANGLE_PRELOADED_D3DCOMPILER_MODULE_NAMES)
michael@0 52 // Find a D3DCompiler module that had already been loaded based on a predefined list of versions.
michael@0 53 static TCHAR* d3dCompilerNames[] = ANGLE_PRELOADED_D3DCOMPILER_MODULE_NAMES;
michael@0 54
michael@0 55 for (size_t i = 0; i < ArraySize(d3dCompilerNames); ++i)
michael@0 56 {
michael@0 57 if (GetModuleHandleEx(0, d3dCompilerNames[i], &mD3dCompilerModule))
michael@0 58 {
michael@0 59 break;
michael@0 60 }
michael@0 61 }
michael@0 62 #else
michael@0 63 // Load the version of the D3DCompiler DLL associated with the Direct3D version ANGLE was built with.
michael@0 64 mD3dCompilerModule = LoadLibrary(D3DCOMPILER_DLL);
michael@0 65 #endif // ANGLE_PRELOADED_D3DCOMPILER_MODULE_NAMES
michael@0 66
michael@0 67 if (!mD3dCompilerModule)
michael@0 68 {
michael@0 69 ERR("No D3D compiler module found - aborting!\n");
michael@0 70 return false;
michael@0 71 }
michael@0 72
michael@0 73 mD3DCompileFunc = reinterpret_cast<pCompileFunc>(GetProcAddress(mD3dCompilerModule, "D3DCompile"));
michael@0 74 ASSERT(mD3DCompileFunc);
michael@0 75
michael@0 76 return mD3DCompileFunc != NULL;
michael@0 77 }
michael@0 78
michael@0 79 // Compiles HLSL code into executable binaries
michael@0 80 ShaderBlob *Renderer::compileToBinary(gl::InfoLog &infoLog, const char *hlsl, const char *profile, UINT optimizationFlags, bool alternateFlags)
michael@0 81 {
michael@0 82 if (!hlsl)
michael@0 83 {
michael@0 84 return NULL;
michael@0 85 }
michael@0 86
michael@0 87 HRESULT result = S_OK;
michael@0 88 UINT flags = 0;
michael@0 89 std::string sourceText;
michael@0 90 if (gl::perfActive())
michael@0 91 {
michael@0 92 flags |= D3DCOMPILE_DEBUG;
michael@0 93
michael@0 94 #ifdef NDEBUG
michael@0 95 flags |= optimizationFlags;
michael@0 96 #else
michael@0 97 flags |= D3DCOMPILE_SKIP_OPTIMIZATION;
michael@0 98 #endif
michael@0 99
michael@0 100 std::string sourcePath = getTempPath();
michael@0 101 sourceText = std::string("#line 2 \"") + sourcePath + std::string("\"\n\n") + std::string(hlsl);
michael@0 102 writeFile(sourcePath.c_str(), sourceText.c_str(), sourceText.size());
michael@0 103 }
michael@0 104 else
michael@0 105 {
michael@0 106 flags |= optimizationFlags;
michael@0 107 sourceText = hlsl;
michael@0 108 }
michael@0 109
michael@0 110 // Sometimes D3DCompile will fail with the default compilation flags for complicated shaders when it would otherwise pass with alternative options.
michael@0 111 // Try the default flags first and if compilation fails, try some alternatives.
michael@0 112 const static UINT extraFlags[] =
michael@0 113 {
michael@0 114 0,
michael@0 115 D3DCOMPILE_AVOID_FLOW_CONTROL,
michael@0 116 D3DCOMPILE_PREFER_FLOW_CONTROL
michael@0 117 };
michael@0 118
michael@0 119 const static char * const extraFlagNames[] =
michael@0 120 {
michael@0 121 "default",
michael@0 122 "avoid flow control",
michael@0 123 "prefer flow control"
michael@0 124 };
michael@0 125
michael@0 126 int attempts = alternateFlags ? ArraySize(extraFlags) : 1;
michael@0 127 pD3DCompile compileFunc = reinterpret_cast<pD3DCompile>(mD3DCompileFunc);
michael@0 128 for (int i = 0; i < attempts; ++i)
michael@0 129 {
michael@0 130 ID3DBlob *errorMessage = NULL;
michael@0 131 ID3DBlob *binary = NULL;
michael@0 132
michael@0 133 result = compileFunc(hlsl, strlen(hlsl), gl::g_fakepath, NULL, NULL,
michael@0 134 "main", profile, flags | extraFlags[i], 0, &binary, &errorMessage);
michael@0 135 if (errorMessage)
michael@0 136 {
michael@0 137 const char *message = (const char*)errorMessage->GetBufferPointer();
michael@0 138
michael@0 139 infoLog.appendSanitized(message);
michael@0 140 TRACE("\n%s", hlsl);
michael@0 141 TRACE("\n%s", message);
michael@0 142
michael@0 143 errorMessage->Release();
michael@0 144 errorMessage = NULL;
michael@0 145 }
michael@0 146
michael@0 147 if (SUCCEEDED(result))
michael@0 148 {
michael@0 149 return (ShaderBlob*)binary;
michael@0 150 }
michael@0 151 else
michael@0 152 {
michael@0 153 if (result == D3DERR_OUTOFVIDEOMEMORY || result == E_OUTOFMEMORY)
michael@0 154 {
michael@0 155 return gl::error(GL_OUT_OF_MEMORY, (ShaderBlob*) NULL);
michael@0 156 }
michael@0 157
michael@0 158 infoLog.append("Warning: D3D shader compilation failed with ");
michael@0 159 infoLog.append(extraFlagNames[i]);
michael@0 160 infoLog.append(" flags.");
michael@0 161 if (i + 1 < attempts)
michael@0 162 {
michael@0 163 infoLog.append(" Retrying with ");
michael@0 164 infoLog.append(extraFlagNames[i + 1]);
michael@0 165 infoLog.append(".\n");
michael@0 166 }
michael@0 167 }
michael@0 168 }
michael@0 169
michael@0 170 return NULL;
michael@0 171 }
michael@0 172
michael@0 173 }
michael@0 174
michael@0 175 extern "C"
michael@0 176 {
michael@0 177
michael@0 178 rx::Renderer *glCreateRenderer(egl::Display *display, HDC hDc, EGLNativeDisplayType displayId)
michael@0 179 {
michael@0 180 rx::Renderer *renderer = NULL;
michael@0 181 EGLint status = EGL_BAD_ALLOC;
michael@0 182
michael@0 183 if (ANGLE_ENABLE_D3D11 ||
michael@0 184 displayId == EGL_D3D11_ELSE_D3D9_DISPLAY_ANGLE ||
michael@0 185 displayId == EGL_D3D11_ONLY_DISPLAY_ANGLE)
michael@0 186 {
michael@0 187 renderer = new rx::Renderer11(display, hDc);
michael@0 188
michael@0 189 if (renderer)
michael@0 190 {
michael@0 191 status = renderer->initialize();
michael@0 192 }
michael@0 193
michael@0 194 if (status == EGL_SUCCESS)
michael@0 195 {
michael@0 196 return renderer;
michael@0 197 }
michael@0 198 else if (displayId == EGL_D3D11_ONLY_DISPLAY_ANGLE)
michael@0 199 {
michael@0 200 return NULL;
michael@0 201 }
michael@0 202
michael@0 203 // Failed to create a D3D11 renderer, try creating a D3D9 renderer
michael@0 204 delete renderer;
michael@0 205 }
michael@0 206
michael@0 207 bool softwareDevice = (displayId == EGL_SOFTWARE_DISPLAY_ANGLE);
michael@0 208 renderer = new rx::Renderer9(display, hDc, softwareDevice);
michael@0 209
michael@0 210 if (renderer)
michael@0 211 {
michael@0 212 status = renderer->initialize();
michael@0 213 }
michael@0 214
michael@0 215 if (status == EGL_SUCCESS)
michael@0 216 {
michael@0 217 return renderer;
michael@0 218 }
michael@0 219
michael@0 220 return NULL;
michael@0 221 }
michael@0 222
michael@0 223 void glDestroyRenderer(rx::Renderer *renderer)
michael@0 224 {
michael@0 225 delete renderer;
michael@0 226 }
michael@0 227
michael@0 228 }

mercurial