void HTMLPlugInImageElement::updateWidgetIfNecessary()
{
    document()->updateStyleIfNeeded();

    if (!needsWidgetUpdate() || useFallbackContent() || isImageType())
        return;

    if (!renderEmbeddedObject() || renderEmbeddedObject()->showsUnavailablePluginIndicator())
        return;

    updateWidget(CreateOnlyNonNetscapePlugins);
}
void HTMLPlugInImageElement::updateWidgetIfNecessary()
{
    document()->updateStyleIfNeeded();

    if (!needsWidgetUpdate() || useFallbackContent() || isImageType())
        return;

    if (!renderEmbeddedObject() || renderEmbeddedObject()->pluginCrashedOrWasMissing())
        return;

    updateWidget(CreateOnlyNonNetscapePlugins);
}
RenderObject* HTMLPlugInImageElement::createRenderer(RenderArena* arena, RenderStyle* style)
{
    // Fallback content breaks the DOM->Renderer class relationship of this
    // class and all superclasses because createObject won't necessarily
    // return a RenderEmbeddedObject, RenderPart or even RenderWidget.
    if (useFallbackContent())
        return RenderObject::createObject(this, style);
    if (isImageType()) {
        RenderImage* image = new (arena) RenderImage(this);
        image->setImageResource(RenderImageResource::create());
        return image;
    }
    return new (arena) RenderEmbeddedObject(this);
}
void HTMLPlugInImageElement::attach()
{
    bool isImage = isImageType();
    
    if (!isImage)
        queuePostAttachCallback(&HTMLPlugInImageElement::updateWidgetCallback, this);

    HTMLPlugInElement::attach();

    if (isImage && renderer() && !useFallbackContent()) {
        if (!m_imageLoader)
            m_imageLoader = adoptPtr(new HTMLImageLoader(this));
        m_imageLoader->updateFromElement();
    }
}
Example #5
0
    ProgramInstance::ProgramInstance( ProgramSharedPtr const& program )
      : m_program( program )
    {
      GLint programID = program->getGLId();

      m_shaderStorageBuffers.resize( program->getShaderStorageBlocks().size() );
#if !defined(NDEBUG)
      for ( size_t i=0 ; i<m_shaderStorageBuffers.size() ; i++ )
      {
        m_unsetShaderStorageBlocks.insert( i );
      }
#endif

      std::vector<Program::Uniform> const& uniforms = program->getActiveUniforms();
      for ( size_t i=0 ; i<uniforms.size() ; i++ )
      {
        if ( isImageType( uniforms[i].type ) )
        {
          m_imageUniforms.insert( std::make_pair( i, ImageUniformData() ) );
        }
        else if ( isSamplerType( uniforms[i].type ) )
        {
          m_samplerUniforms.insert( std::make_pair( i, SamplerUniformData() ) );
        }
        else if ( uniforms[i].location != -1 )
        {
          std::map<size_t,std::vector<char>>::iterator it = m_uniforms.insert( std::make_pair( i, std::vector<char>() ) ).first;
          it->second.resize( sizeOfType( uniforms[i].type ) );
        }

#if !defined(NDEBUG)
        m_unsetUniforms.insert( i );
#endif
      }

      std::vector<Program::Block> const& blocks = program->getActiveUniformBlocks();
      m_uniformBuffers.resize( blocks.size() );
      for ( size_t i=0 ; i<m_uniformBuffers.size() ; i++ )
      {
        m_uniformBuffers[i] = dp::gl::Buffer::create( Buffer::CORE, GL_DYNAMIC_DRAW, GL_UNIFORM_BUFFER );
        m_uniformBuffers[i]->setSize( blocks[i].dataSize );
      }
    }
Example #6
0
void HTMLPlugInElement::attach(const AttachContext& context)
{
    HTMLFrameOwnerElement::attach(context);

    if (!renderer() || useFallbackContent())
        return;

    if (isImageType()) {
        if (!m_imageLoader)
            m_imageLoader = HTMLImageLoader::create(this);
        m_imageLoader->updateFromElement();
    } else if (needsWidgetUpdate()
        && renderEmbeddedObject()
        && !renderEmbeddedObject()->showsUnavailablePluginIndicator()
        && !wouldLoadAsNetscapePlugin(m_url, m_serviceType)
        && !m_isDelayingLoadEvent) {
        m_isDelayingLoadEvent = true;
        document().incrementLoadEventDelayCount();
        document().loadPluginsSoon();
    }
}
RenderObject* HTMLPlugInImageElement::createRenderer(RenderArena* arena, RenderStyle* style)
{
    // Once a PlugIn Element creates its renderer, it needs to be told when the Document goes
    // inactive or reactivates so it can clear the renderer before going into the page cache.
    if (!m_needsDocumentActivationCallbacks) {
        m_needsDocumentActivationCallbacks = true;
        document()->registerForPageCacheSuspensionCallbacks(this);
    }

    // Fallback content breaks the DOM->Renderer class relationship of this
    // class and all superclasses because createObject won't necessarily
    // return a RenderEmbeddedObject, RenderPart or even RenderWidget.
    if (useFallbackContent())
        return RenderObject::createObject(this, style);
    if (isImageType()) {
        RenderImage* image = new (arena) RenderImage(this);
        image->setImageResource(RenderImageResource::create());
        return image;
    }
    return new (arena) RenderEmbeddedObject(this);
}
Example #8
0
void HTMLObjectElement::renderFallbackContent()
{
    if (useFallbackContent())
        return;
    
    if (!inDocument())
        return;

    // Before we give up and use fallback content, check to see if this is a MIME type issue.
    if (m_imageLoader && m_imageLoader->image() && m_imageLoader->image()->status() != CachedResource::LoadError) {
        m_serviceType = m_imageLoader->image()->response().mimeType();
        if (!isImageType()) {
            // If we don't think we have an image type anymore, then clear the image from the loader.
            m_imageLoader->setImage(0);
            Style::reattachRenderTree(*this);
            return;
        }
    }

    m_useFallbackContent = true;

    // FIXME: Style gets recalculated which is suboptimal.
    Style::reattachRenderTree(*this);
}
void Shader::ShaderProgram::addActiveUniformsFromProgram() {
    // Length of the longest variable name
    GLint maxLength;

    // Number of uniform variables
    GLint uniformCount;
    // Get the number of uniforms, and the length of the longest name.
    glGetProgramiv(glShaderProgramObject(), GL_ACTIVE_UNIFORM_MAX_LENGTH, &maxLength);
    glGetProgramiv(glShaderProgramObject(), GL_ACTIVE_UNIFORMS, &uniformCount);
    GLchar* name = (GLchar *) malloc(maxLength * sizeof(GLchar));
    
    // Get the sizes, types and names
    int lastTextureUnit = -1;
    int lastImageUnit = -1;
    // Loop over glGetActiveUniform and store the results away.
    for (int i = 0; i < uniformCount; ++i) {
        const GLuint uniformIndex = i;
        GLuint programObject = glShaderProgramObject();

        GLint elementNum;
        GLenum type;
        glGetActiveUniform(programObject, uniformIndex, maxLength, NULL, &elementNum, &type, name);
        UniformDeclaration& d = uniformDeclarationTable.getCreate(name);
        d.name = name;
        d.location = glGetUniformLocation(glShaderProgramObject(), name);
        d.type = type;
        d.elementNum = elementNum;

        bool isGLBuiltIn = (d.location == -1) || 
            ((strlen(name) > 3) && beginsWith(String(name), "gl_"));

        d.dummy = isGLBuiltIn;
        d.index = -1;
        if (! isGLBuiltIn) {
            if (isSamplerType(d.type)) {
                ++lastTextureUnit;
                d.glUnit = lastTextureUnit;           
            } else if (isImageType(d.type)) {
                ++lastImageUnit;
                d.glUnit = lastImageUnit;
            } else if (d.elementNum == 1) { 
                // Not array
                d.glUnit = -1;
            } else { 
                // Is an array, remove from uniform declaration table, and add it's elements
                GLint type      = d.type;
                int arraySize   = (int)d.elementNum;
                int glUnit = -1;
                uniformDeclarationTable.remove(name);
                
                // Get rid of [0] if it exists (depends on driver)
                String arrayName = name;
                if (arrayName[arrayName.length()-1] == ']') {
                    size_t bracketLoc = arrayName.rfind('[');
                    // TODO: error handle if "[" doesn't exist
                    arrayName = arrayName.substr(0, bracketLoc);
                }
                
                
                for (int i = 0; i < arraySize; ++i) {
                    const String appendedName = format("%s[%d]", arrayName.c_str(), i);
                    UniformDeclaration& elementDeclaration = uniformDeclarationTable.getCreate(appendedName);
                    GLint location = glGetUniformLocation(glShaderProgramObject(), appendedName.c_str());
                    debugAssertGLOk();
		            bool dummy = (location == -1);
                    elementDeclaration.setAllFields(appendedName, i, type, location, dummy, glUnit);
                }
            }
        }
    }

    free(name);
}
Example #10
0
    Program::Program( std::vector<SmartShader> const& shaders, Parameters const& parameters )
      : m_activeAttributesCount(0)
      , m_activeAttributesMask(0)
      , m_shaders( shaders )
    {
#if !defined(NDEBUG)
      std::set<GLenum> types;
      for ( std::vector<SmartShader>::const_iterator it = m_shaders.begin() ; it != m_shaders.end() ; ++it )
      {
        DP_ASSERT( *it && types.insert( (*it)->getType() ).second );
      }
#endif

      GLuint id = glCreateProgram();
      setGLId( id );

      DP_ASSERT( glIsProgram( id ) && "failed to create program" );

      glProgramParameteri( id, GL_PROGRAM_BINARY_RETRIEVABLE_HINT, parameters.m_binaryRetrievableHint );
      glProgramParameteri( id, GL_PROGRAM_SEPARABLE, parameters.m_separable );

      for ( std::vector<SmartShader>::const_iterator it = m_shaders.begin() ; it != m_shaders.end() ; ++it )
      {
        glAttachShader( id, (*it)->getGLId() );
      }
      glLinkProgram( id );

      GLint result;
      glGetProgramiv( id, GL_LINK_STATUS, &result );
      if ( !result )
      {
        GLint errorLen;
        glGetProgramiv( id, GL_INFO_LOG_LENGTH, &errorLen );

        std::string buffer;
        buffer.resize( errorLen, 0 );
        glGetProgramInfoLog( id, errorLen, NULL, &buffer[0] );

        std::ostringstream error;
        error << "failed to link program: " << std::endl << buffer << std::endl;
        throw std::runtime_error(error.str().c_str());
      }

      GLint activeUniformMaxLength = 0;
      glGetProgramiv( id, GL_ACTIVE_UNIFORM_MAX_LENGTH, &activeUniformMaxLength );
      std::vector<char> name( activeUniformMaxLength );

      GLint activeUniformsCount = 0;
      glGetProgramiv( id, GL_ACTIVE_UNIFORMS, &activeUniformsCount );
      m_uniforms.resize( activeUniformsCount );

      glUseProgram( id );
      for ( GLint i=0 ; i<activeUniformsCount ; i++ )
      {
        glGetActiveUniform( id, i, activeUniformMaxLength, nullptr, &m_uniforms[i].size, &m_uniforms[i].type, name.data() );
        m_uniforms[i].name = name.data();
        m_uniforms[i].location = glGetUniformLocation( id, m_uniforms[i].name.data() );

        if ( isSamplerType( m_uniforms[i].type ) )
        {
          DP_ASSERT( m_uniforms[i].size == 1 );
          glUniform1i( m_uniforms[i].location, dp::util::checked_cast<GLint>(m_samplerUniforms.size() ) );
          m_samplerUniforms.push_back( i );
        }
        else if ( isImageType( m_uniforms[i].type ) )
        {
          DP_ASSERT( m_uniforms[i].size == 1 );
          glUniform1i( m_uniforms[i].location, dp::util::checked_cast<GLint>(m_imageUniforms.size()) );
          m_imageUniforms.push_back( ImageData() );
          m_imageUniforms.back().index = i;
        }
      }
      glUseProgram( 0 );

      // build mask of active vertex attributes
      GLint activeAttributeMaxLength;
      glGetProgramiv( id, GL_ACTIVE_ATTRIBUTE_MAX_LENGTH, &activeAttributeMaxLength );
      name.resize( activeAttributeMaxLength );

      GLint activeAttributesCount;
      glGetProgramiv( id, GL_ACTIVE_ATTRIBUTES, &activeAttributesCount );

      // the driver reports 1 attribute while activeAttributeMaxLength is 0.
      // since attributes always have names? something strange is going on.
      if ( activeAttributeMaxLength == 0 )
      {
        //DP_ASSERT( false );
        activeAttributesCount = 0;
      }

      m_activeAttributesCount = activeAttributesCount;
      for ( GLint i=0 ; i<activeAttributesCount ; i++ )
      {
        GLint size;
        GLenum type;
        glGetActiveAttrib( id, i, activeAttributeMaxLength, nullptr, &size, &type, &name[0] );
        m_activeAttributesMask |= 1 << glGetAttribLocation( id, &name[0] );
      }
    }
Example #11
0
void HTMLPlugInElement::willRecalcStyle(StyleRecalcChange)
{
    // FIXME: Why is this necessary? Manual re-attach is almost always wrong.
    if (!useFallbackContent() && needsWidgetUpdate() && renderer() && !isImageType())
        reattach();
}