tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

Context9.cpp (18677B)


      1 //
      2 // Copyright 2016 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 // Context9:
      7 //   D3D9-specific functionality associated with a GL Context.
      8 //
      9 
     10 #include "libANGLE/renderer/d3d/d3d9/Context9.h"
     11 
     12 #include "common/entry_points_enum_autogen.h"
     13 #include "common/string_utils.h"
     14 #include "libANGLE/renderer/OverlayImpl.h"
     15 #include "libANGLE/renderer/d3d/CompilerD3D.h"
     16 #include "libANGLE/renderer/d3d/ProgramD3D.h"
     17 #include "libANGLE/renderer/d3d/RenderbufferD3D.h"
     18 #include "libANGLE/renderer/d3d/SamplerD3D.h"
     19 #include "libANGLE/renderer/d3d/ShaderD3D.h"
     20 #include "libANGLE/renderer/d3d/TextureD3D.h"
     21 #include "libANGLE/renderer/d3d/d3d9/Buffer9.h"
     22 #include "libANGLE/renderer/d3d/d3d9/Fence9.h"
     23 #include "libANGLE/renderer/d3d/d3d9/Framebuffer9.h"
     24 #include "libANGLE/renderer/d3d/d3d9/Query9.h"
     25 #include "libANGLE/renderer/d3d/d3d9/Renderer9.h"
     26 #include "libANGLE/renderer/d3d/d3d9/StateManager9.h"
     27 #include "libANGLE/renderer/d3d/d3d9/VertexArray9.h"
     28 
     29 namespace rx
     30 {
     31 
     32 Context9::Context9(const gl::State &state, gl::ErrorSet *errorSet, Renderer9 *renderer)
     33    : ContextD3D(state, errorSet), mRenderer(renderer)
     34 {}
     35 
     36 Context9::~Context9() {}
     37 
     38 angle::Result Context9::initialize()
     39 {
     40    return angle::Result::Continue;
     41 }
     42 
     43 void Context9::onDestroy(const gl::Context *context)
     44 {
     45    mIncompleteTextures.onDestroy(context);
     46 }
     47 
     48 CompilerImpl *Context9::createCompiler()
     49 {
     50    return new CompilerD3D(SH_HLSL_3_0_OUTPUT);
     51 }
     52 
     53 ShaderImpl *Context9::createShader(const gl::ShaderState &data)
     54 {
     55    return new ShaderD3D(data, mRenderer);
     56 }
     57 
     58 ProgramImpl *Context9::createProgram(const gl::ProgramState &data)
     59 {
     60    return new ProgramD3D(data, mRenderer);
     61 }
     62 
     63 FramebufferImpl *Context9::createFramebuffer(const gl::FramebufferState &data)
     64 {
     65    return new Framebuffer9(data, mRenderer);
     66 }
     67 
     68 TextureImpl *Context9::createTexture(const gl::TextureState &state)
     69 {
     70    switch (state.getType())
     71    {
     72        case gl::TextureType::_2D:
     73        // GL_TEXTURE_VIDEO_IMAGE_WEBGL maps to 2D texture on Windows platform.
     74        case gl::TextureType::VideoImage:
     75            return new TextureD3D_2D(state, mRenderer);
     76        case gl::TextureType::CubeMap:
     77            return new TextureD3D_Cube(state, mRenderer);
     78        case gl::TextureType::External:
     79            return new TextureD3D_External(state, mRenderer);
     80        default:
     81            UNREACHABLE();
     82    }
     83    return nullptr;
     84 }
     85 
     86 RenderbufferImpl *Context9::createRenderbuffer(const gl::RenderbufferState &state)
     87 {
     88    return new RenderbufferD3D(state, mRenderer);
     89 }
     90 
     91 BufferImpl *Context9::createBuffer(const gl::BufferState &state)
     92 {
     93    return new Buffer9(state, mRenderer);
     94 }
     95 
     96 VertexArrayImpl *Context9::createVertexArray(const gl::VertexArrayState &data)
     97 {
     98    return new VertexArray9(data);
     99 }
    100 
    101 QueryImpl *Context9::createQuery(gl::QueryType type)
    102 {
    103    return new Query9(mRenderer, type);
    104 }
    105 
    106 FenceNVImpl *Context9::createFenceNV()
    107 {
    108    return new FenceNV9(mRenderer);
    109 }
    110 
    111 SyncImpl *Context9::createSync()
    112 {
    113    // D3D9 doesn't support ES 3.0 and its sync objects.
    114    UNREACHABLE();
    115    return nullptr;
    116 }
    117 
    118 TransformFeedbackImpl *Context9::createTransformFeedback(const gl::TransformFeedbackState &state)
    119 {
    120    UNREACHABLE();
    121    return nullptr;
    122 }
    123 
    124 SamplerImpl *Context9::createSampler(const gl::SamplerState &state)
    125 {
    126    return new SamplerD3D(state);
    127 }
    128 
    129 ProgramPipelineImpl *Context9::createProgramPipeline(const gl::ProgramPipelineState &data)
    130 {
    131    UNREACHABLE();
    132    return nullptr;
    133 }
    134 
    135 MemoryObjectImpl *Context9::createMemoryObject()
    136 {
    137    UNREACHABLE();
    138    return nullptr;
    139 }
    140 
    141 SemaphoreImpl *Context9::createSemaphore()
    142 {
    143    UNREACHABLE();
    144    return nullptr;
    145 }
    146 
    147 OverlayImpl *Context9::createOverlay(const gl::OverlayState &state)
    148 {
    149    // Not implemented.
    150    return new OverlayImpl(state);
    151 }
    152 
    153 angle::Result Context9::flush(const gl::Context *context)
    154 {
    155    return mRenderer->flush(context);
    156 }
    157 
    158 angle::Result Context9::finish(const gl::Context *context)
    159 {
    160    return mRenderer->finish(context);
    161 }
    162 
    163 angle::Result Context9::drawArrays(const gl::Context *context,
    164                                   gl::PrimitiveMode mode,
    165                                   GLint first,
    166                                   GLsizei count)
    167 {
    168    return mRenderer->genericDrawArrays(context, mode, first, count, 0);
    169 }
    170 
    171 angle::Result Context9::drawArraysInstanced(const gl::Context *context,
    172                                            gl::PrimitiveMode mode,
    173                                            GLint first,
    174                                            GLsizei count,
    175                                            GLsizei instanceCount)
    176 {
    177    return mRenderer->genericDrawArrays(context, mode, first, count, instanceCount);
    178 }
    179 
    180 angle::Result Context9::drawArraysInstancedBaseInstance(const gl::Context *context,
    181                                                        gl::PrimitiveMode mode,
    182                                                        GLint first,
    183                                                        GLsizei count,
    184                                                        GLsizei instanceCount,
    185                                                        GLuint baseInstance)
    186 {
    187    ANGLE_HR_UNREACHABLE(this);
    188    return angle::Result::Continue;
    189 }
    190 
    191 angle::Result Context9::drawElements(const gl::Context *context,
    192                                     gl::PrimitiveMode mode,
    193                                     GLsizei count,
    194                                     gl::DrawElementsType type,
    195                                     const void *indices)
    196 {
    197    return mRenderer->genericDrawElements(context, mode, count, type, indices, 0);
    198 }
    199 
    200 angle::Result Context9::drawElementsBaseVertex(const gl::Context *context,
    201                                               gl::PrimitiveMode mode,
    202                                               GLsizei count,
    203                                               gl::DrawElementsType type,
    204                                               const void *indices,
    205                                               GLint baseVertex)
    206 {
    207    ANGLE_HR_UNREACHABLE(this);
    208    return angle::Result::Continue;
    209 }
    210 
    211 angle::Result Context9::drawElementsInstanced(const gl::Context *context,
    212                                              gl::PrimitiveMode mode,
    213                                              GLsizei count,
    214                                              gl::DrawElementsType type,
    215                                              const void *indices,
    216                                              GLsizei instances)
    217 {
    218    return mRenderer->genericDrawElements(context, mode, count, type, indices, instances);
    219 }
    220 
    221 angle::Result Context9::drawElementsInstancedBaseVertex(const gl::Context *context,
    222                                                        gl::PrimitiveMode mode,
    223                                                        GLsizei count,
    224                                                        gl::DrawElementsType type,
    225                                                        const void *indices,
    226                                                        GLsizei instances,
    227                                                        GLint baseVertex)
    228 {
    229    ANGLE_HR_UNREACHABLE(this);
    230    return angle::Result::Continue;
    231 }
    232 
    233 angle::Result Context9::drawElementsInstancedBaseVertexBaseInstance(const gl::Context *context,
    234                                                                    gl::PrimitiveMode mode,
    235                                                                    GLsizei count,
    236                                                                    gl::DrawElementsType type,
    237                                                                    const void *indices,
    238                                                                    GLsizei instances,
    239                                                                    GLint baseVertex,
    240                                                                    GLuint baseInstance)
    241 {
    242    ANGLE_HR_UNREACHABLE(this);
    243    return angle::Result::Continue;
    244 }
    245 
    246 angle::Result Context9::drawRangeElements(const gl::Context *context,
    247                                          gl::PrimitiveMode mode,
    248                                          GLuint start,
    249                                          GLuint end,
    250                                          GLsizei count,
    251                                          gl::DrawElementsType type,
    252                                          const void *indices)
    253 {
    254    return mRenderer->genericDrawElements(context, mode, count, type, indices, 0);
    255 }
    256 
    257 angle::Result Context9::drawRangeElementsBaseVertex(const gl::Context *context,
    258                                                    gl::PrimitiveMode mode,
    259                                                    GLuint start,
    260                                                    GLuint end,
    261                                                    GLsizei count,
    262                                                    gl::DrawElementsType type,
    263                                                    const void *indices,
    264                                                    GLint baseVertex)
    265 {
    266    ANGLE_HR_UNREACHABLE(this);
    267    return angle::Result::Continue;
    268 }
    269 
    270 angle::Result Context9::drawArraysIndirect(const gl::Context *context,
    271                                           gl::PrimitiveMode mode,
    272                                           const void *indirect)
    273 {
    274    ANGLE_HR_UNREACHABLE(this);
    275    return angle::Result::Stop;
    276 }
    277 
    278 angle::Result Context9::drawElementsIndirect(const gl::Context *context,
    279                                             gl::PrimitiveMode mode,
    280                                             gl::DrawElementsType type,
    281                                             const void *indirect)
    282 {
    283    ANGLE_HR_UNREACHABLE(this);
    284    return angle::Result::Stop;
    285 }
    286 
    287 angle::Result Context9::multiDrawArrays(const gl::Context *context,
    288                                        gl::PrimitiveMode mode,
    289                                        const GLint *firsts,
    290                                        const GLsizei *counts,
    291                                        GLsizei drawcount)
    292 {
    293    return rx::MultiDrawArraysGeneral(this, context, mode, firsts, counts, drawcount);
    294 }
    295 
    296 angle::Result Context9::multiDrawArraysInstanced(const gl::Context *context,
    297                                                 gl::PrimitiveMode mode,
    298                                                 const GLint *firsts,
    299                                                 const GLsizei *counts,
    300                                                 const GLsizei *instanceCounts,
    301                                                 GLsizei drawcount)
    302 {
    303    return rx::MultiDrawArraysInstancedGeneral(this, context, mode, firsts, counts, instanceCounts,
    304                                               drawcount);
    305 }
    306 
    307 angle::Result Context9::multiDrawArraysIndirect(const gl::Context *context,
    308                                                gl::PrimitiveMode mode,
    309                                                const void *indirect,
    310                                                GLsizei drawcount,
    311                                                GLsizei stride)
    312 {
    313    UNREACHABLE();
    314    return angle::Result::Stop;
    315 }
    316 
    317 angle::Result Context9::multiDrawElements(const gl::Context *context,
    318                                          gl::PrimitiveMode mode,
    319                                          const GLsizei *counts,
    320                                          gl::DrawElementsType type,
    321                                          const GLvoid *const *indices,
    322                                          GLsizei drawcount)
    323 {
    324    return rx::MultiDrawElementsGeneral(this, context, mode, counts, type, indices, drawcount);
    325 }
    326 
    327 angle::Result Context9::multiDrawElementsInstanced(const gl::Context *context,
    328                                                   gl::PrimitiveMode mode,
    329                                                   const GLsizei *counts,
    330                                                   gl::DrawElementsType type,
    331                                                   const GLvoid *const *indices,
    332                                                   const GLsizei *instanceCounts,
    333                                                   GLsizei drawcount)
    334 {
    335    return rx::MultiDrawElementsInstancedGeneral(this, context, mode, counts, type, indices,
    336                                                 instanceCounts, drawcount);
    337 }
    338 
    339 angle::Result Context9::multiDrawElementsIndirect(const gl::Context *context,
    340                                                  gl::PrimitiveMode mode,
    341                                                  gl::DrawElementsType type,
    342                                                  const void *indirect,
    343                                                  GLsizei drawcount,
    344                                                  GLsizei stride)
    345 {
    346    UNREACHABLE();
    347    return angle::Result::Stop;
    348 }
    349 
    350 angle::Result Context9::multiDrawArraysInstancedBaseInstance(const gl::Context *context,
    351                                                             gl::PrimitiveMode mode,
    352                                                             const GLint *firsts,
    353                                                             const GLsizei *counts,
    354                                                             const GLsizei *instanceCounts,
    355                                                             const GLuint *baseInstances,
    356                                                             GLsizei drawcount)
    357 {
    358    ANGLE_HR_UNREACHABLE(this);
    359    return angle::Result::Stop;
    360 }
    361 
    362 angle::Result Context9::multiDrawElementsInstancedBaseVertexBaseInstance(
    363    const gl::Context *context,
    364    gl::PrimitiveMode mode,
    365    const GLsizei *counts,
    366    gl::DrawElementsType type,
    367    const GLvoid *const *indices,
    368    const GLsizei *instanceCounts,
    369    const GLint *baseVertices,
    370    const GLuint *baseInstances,
    371    GLsizei drawcount)
    372 {
    373    ANGLE_HR_UNREACHABLE(this);
    374    return angle::Result::Stop;
    375 }
    376 
    377 gl::GraphicsResetStatus Context9::getResetStatus()
    378 {
    379    return mRenderer->getResetStatus();
    380 }
    381 
    382 angle::Result Context9::insertEventMarker(GLsizei length, const char *marker)
    383 {
    384    mRenderer->getAnnotator()->setMarker(/*context=*/nullptr, marker);
    385    return angle::Result::Continue;
    386 }
    387 
    388 angle::Result Context9::pushGroupMarker(GLsizei length, const char *marker)
    389 {
    390    mRenderer->getAnnotator()->beginEvent(nullptr, angle::EntryPoint::GLPushGroupMarkerEXT, marker,
    391                                          marker);
    392    mMarkerStack.push(std::string(marker));
    393    return angle::Result::Continue;
    394 }
    395 
    396 angle::Result Context9::popGroupMarker()
    397 {
    398    const char *marker = nullptr;
    399    if (!mMarkerStack.empty())
    400    {
    401        marker = mMarkerStack.top().c_str();
    402        mMarkerStack.pop();
    403        mRenderer->getAnnotator()->endEvent(nullptr, marker,
    404                                            angle::EntryPoint::GLPopGroupMarkerEXT);
    405    }
    406    return angle::Result::Continue;
    407 }
    408 
    409 angle::Result Context9::pushDebugGroup(const gl::Context *context,
    410                                       GLenum source,
    411                                       GLuint id,
    412                                       const std::string &message)
    413 {
    414    // Fall through to the EXT_debug_marker functions
    415    return pushGroupMarker(static_cast<GLsizei>(message.size()), message.c_str());
    416 }
    417 
    418 angle::Result Context9::popDebugGroup(const gl::Context *context)
    419 {
    420    // Fall through to the EXT_debug_marker functions
    421    return popGroupMarker();
    422 }
    423 
    424 angle::Result Context9::syncState(const gl::Context *context,
    425                                  const gl::State::DirtyBits &dirtyBits,
    426                                  const gl::State::DirtyBits &bitMask,
    427                                  gl::Command command)
    428 {
    429    mRenderer->getStateManager()->syncState(mState, dirtyBits);
    430    return angle::Result::Continue;
    431 }
    432 
    433 GLint Context9::getGPUDisjoint()
    434 {
    435    return mRenderer->getGPUDisjoint();
    436 }
    437 
    438 GLint64 Context9::getTimestamp()
    439 {
    440    return mRenderer->getTimestamp();
    441 }
    442 
    443 angle::Result Context9::onMakeCurrent(const gl::Context *context)
    444 {
    445    mRenderer->getStateManager()->setAllDirtyBits();
    446    return mRenderer->ensureVertexDataManagerInitialized(context);
    447 }
    448 
    449 gl::Caps Context9::getNativeCaps() const
    450 {
    451    return mRenderer->getNativeCaps();
    452 }
    453 
    454 const gl::TextureCapsMap &Context9::getNativeTextureCaps() const
    455 {
    456    return mRenderer->getNativeTextureCaps();
    457 }
    458 
    459 const gl::Extensions &Context9::getNativeExtensions() const
    460 {
    461    return mRenderer->getNativeExtensions();
    462 }
    463 
    464 const gl::Limitations &Context9::getNativeLimitations() const
    465 {
    466    return mRenderer->getNativeLimitations();
    467 }
    468 
    469 ShPixelLocalStorageType Context9::getNativePixelLocalStorageType() const
    470 {
    471    return mRenderer->getNativePixelLocalStorageType();
    472 }
    473 
    474 angle::Result Context9::dispatchCompute(const gl::Context *context,
    475                                        GLuint numGroupsX,
    476                                        GLuint numGroupsY,
    477                                        GLuint numGroupsZ)
    478 {
    479    ANGLE_HR_UNREACHABLE(this);
    480    return angle::Result::Stop;
    481 }
    482 
    483 angle::Result Context9::dispatchComputeIndirect(const gl::Context *context, GLintptr indirect)
    484 {
    485    ANGLE_HR_UNREACHABLE(this);
    486    return angle::Result::Stop;
    487 }
    488 
    489 angle::Result Context9::memoryBarrier(const gl::Context *context, GLbitfield barriers)
    490 {
    491    ANGLE_HR_UNREACHABLE(this);
    492    return angle::Result::Stop;
    493 }
    494 
    495 angle::Result Context9::memoryBarrierByRegion(const gl::Context *context, GLbitfield barriers)
    496 {
    497    ANGLE_HR_UNREACHABLE(this);
    498    return angle::Result::Stop;
    499 }
    500 
    501 angle::Result Context9::getIncompleteTexture(const gl::Context *context,
    502                                             gl::TextureType type,
    503                                             gl::Texture **textureOut)
    504 {
    505    return mIncompleteTextures.getIncompleteTexture(context, type, gl::SamplerFormat::Float,
    506                                                    nullptr, textureOut);
    507 }
    508 
    509 void Context9::handleResult(HRESULT hr,
    510                            const char *message,
    511                            const char *file,
    512                            const char *function,
    513                            unsigned int line)
    514 {
    515    ASSERT(FAILED(hr));
    516 
    517    if (d3d9::isDeviceLostError(hr))
    518    {
    519        mRenderer->notifyDeviceLost();
    520    }
    521 
    522    GLenum glErrorCode = DefaultGLErrorCode(hr);
    523 
    524    std::stringstream errorStream;
    525    errorStream << "Internal D3D9 error: " << gl::FmtHR(hr) << ": " << message;
    526 
    527    mErrors->handleError(glErrorCode, errorStream.str().c_str(), file, function, line);
    528 }
    529 }  // namespace rx