Changeset 49420 in webkit


Ignore:
Timestamp:
Oct 10, 2009 2:16:58 PM (15 years ago)
Author:
oliver@apple.com
Message:

Implement getActiveAttrib and getActiveUniform
https://bugs.webkit.org/show_bug.cgi?id=30276

Reviewed by Eric Carlson.

Implements the getActiveAttrib and getActiveUniform APIs.
Rather simple patch, adds CanvasActiveInfo definition and implementation
and adds forwarding to the GraphicsContext3D.

Test: fast/canvas/webgl/getActiveTest.html

Location:
trunk
Files:
8 added
10 edited
2 copied

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r49414 r49420  
     12009-10-10  Oliver Hunt  <oliver@apple.com>
     2
     3        Reviewed by Eric Carlson.
     4
     5        Implement getActiveAttrib and getActiveUniform
     6        https://bugs.webkit.org/show_bug.cgi?id=30276
     7
     8        Adds test for getActiveAttrib and getActiveUniform.  Additionally
     9        adds a basic shader pair, and a utility library to do the more
     10        mechanical work needed to set up a WebGL context for testing.
     11
     12        * fast/canvas/webgl/getActiveTest-expected.txt: Added.
     13        * fast/canvas/webgl/getActiveTest.html: Added.
     14        * fast/canvas/webgl/resources/fragmentShader.frag: Added.
     15        * fast/canvas/webgl/resources/shader-test.js: Added.
     16        (getShaderSource):
     17        (create3DContext):
     18        (loadStandardProgram):
     19        * fast/canvas/webgl/resources/vertexShader.vert: Added.
     20        * fast/canvas/webgl/script-tests/getActiveTest.js: Added.
     21
    1222009-10-09  Ryosuke Niwa  <rniwa@webkit.org>
    223
  • trunk/WebCore/ChangeLog

    r49419 r49420  
     12009-10-10  Oliver Hunt  <oliver@apple.com>
     2
     3        Reviewed by Eric Carlson.
     4
     5        Implement getActiveAttrib and getActiveUniform
     6        https://bugs.webkit.org/show_bug.cgi?id=30276
     7
     8        Implements the getActiveAttrib and getActiveUniform APIs.
     9        Rather simple patch, adds CanvasActiveInfo definition and implementation
     10        and adds forwarding to the GraphicsContext3D.
     11
     12        Test: fast/canvas/webgl/getActiveTest.html
     13
     14        * DerivedSources.make:
     15        * WebCore.xcodeproj/project.pbxproj:
     16        * html/canvas/CanvasActiveInfo.h: Added.
     17        (WebCore::CanvasActiveInfo::create):
     18        (WebCore::CanvasActiveInfo::name):
     19        (WebCore::CanvasActiveInfo::type):
     20        (WebCore::CanvasActiveInfo::size):
     21        (WebCore::CanvasActiveInfo::CanvasActiveInfo):
     22        * html/canvas/CanvasActiveInfo.idl: Added.
     23        * html/canvas/CanvasObject.h:
     24        (WebCore::CanvasObject::context):
     25          Need to make the context public as it is needed to ensure we don't
     26          provide a program from one context as an argument to another.
     27        * html/canvas/CanvasRenderingContext3D.cpp:
     28        (WebCore::CanvasRenderingContext3D::getActiveAttrib):
     29        (WebCore::CanvasRenderingContext3D::getActiveUniform):
     30        * html/canvas/CanvasRenderingContext3D.h:
     31        * html/canvas/CanvasRenderingContext3D.idl:
     32        * platform/graphics/GraphicsContext3D.h:
     33        * platform/graphics/mac/GraphicsContext3DMac.cpp:
     34        (WebCore::GraphicsContext3D::getActiveAttrib):
     35        (WebCore::GraphicsContext3D::getActiveUniform):
     36
    1372009-10-10  Pavel Feldman  <pfeldman@chromium.org>
    238
  • trunk/WebCore/DerivedSources.make

    r49400 r49420  
    7171    CSSVariablesRule \
    7272    CSSVariablesDeclaration \
     73    CanvasActiveInfo \
    7374    CanvasArray \
    7475    CanvasArrayBuffer \
  • trunk/WebCore/WebCore.xcodeproj/project.pbxproj

    r49415 r49420  
    23972397                A7CFB3D50B7ED1180070C32D /* DragImageMac.mm in Sources */ = {isa = PBXBuildFile; fileRef = A7CFB3D40B7ED1180070C32D /* DragImageMac.mm */; };
    23982398                A7D0318E0E93540300E24ACD /* JSImageDataCustom.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A7D0318D0E93540300E24ACD /* JSImageDataCustom.cpp */; };
     2399                A7D20F62107F406900A80392 /* JSCanvasActiveInfo.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A7D20F60107F406900A80392 /* JSCanvasActiveInfo.cpp */; };
     2400                A7D20F63107F406900A80392 /* JSCanvasActiveInfo.h in Headers */ = {isa = PBXBuildFile; fileRef = A7D20F61107F406900A80392 /* JSCanvasActiveInfo.h */; };
     2401                A7D20F6D107F438B00A80392 /* CanvasActiveInfo.h in Headers */ = {isa = PBXBuildFile; fileRef = A7D20F6B107F438B00A80392 /* CanvasActiveInfo.h */; };
    23992402                A7D27FC40E0A599F0079AD2B /* SVGFETile.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A7D27FC30E0A599F0079AD2B /* SVGFETile.cpp */; };
    24002403                A7D3C5240B576B4B002CA450 /* PasteboardHelper.h in Headers */ = {isa = PBXBuildFile; fileRef = A7D3C5230B576B4B002CA450 /* PasteboardHelper.h */; settings = {ATTRIBUTES = (Private, ); }; };
     
    76027605                A7CFB3D40B7ED1180070C32D /* DragImageMac.mm */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.objcpp; path = DragImageMac.mm; sourceTree = "<group>"; };
    76037606                A7D0318D0E93540300E24ACD /* JSImageDataCustom.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSImageDataCustom.cpp; sourceTree = "<group>"; };
     7607                A7D20F3B107F373800A80392 /* CanvasActiveInfo.idl */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = CanvasActiveInfo.idl; path = canvas/CanvasActiveInfo.idl; sourceTree = "<group>"; };
     7608                A7D20F60107F406900A80392 /* JSCanvasActiveInfo.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = JSCanvasActiveInfo.cpp; path = /Users/oliver/builds/Debug/DerivedSources/WebCore/JSCanvasActiveInfo.cpp; sourceTree = "<absolute>"; };
     7609                A7D20F61107F406900A80392 /* JSCanvasActiveInfo.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = JSCanvasActiveInfo.h; path = /Users/oliver/builds/Debug/DerivedSources/WebCore/JSCanvasActiveInfo.h; sourceTree = "<absolute>"; };
     7610                A7D20F6B107F438B00A80392 /* CanvasActiveInfo.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = CanvasActiveInfo.h; path = canvas/CanvasActiveInfo.h; sourceTree = "<group>"; };
    76047611                A7D27FC30E0A599F0079AD2B /* SVGFETile.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = SVGFETile.cpp; sourceTree = "<group>"; };
    76057612                A7D3C5230B576B4B002CA450 /* PasteboardHelper.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PasteboardHelper.h; sourceTree = "<group>"; };
     
    1062110628                                49EECDDD10503C2400099FAB /* CanvasUnsignedShortArray.h */,
    1062210629                                49EECDDE10503C2400099FAB /* CanvasUnsignedShortArray.idl */,
     10630                                A7D20F3B107F373800A80392 /* CanvasActiveInfo.idl */,
     10631                                A7D20F6B107F438B00A80392 /* CanvasActiveInfo.h */,
    1062310632                        );
    1062410633                        name = canvas;
     
    1271412723                        isa = PBXGroup;
    1271512724                        children = (
     12725                                A7D20F60107F406900A80392 /* JSCanvasActiveInfo.cpp */,
     12726                                A7D20F61107F406900A80392 /* JSCanvasActiveInfo.h */,
    1271612727                                49EECF19105072F300099FAB /* JSCanvasArray.cpp */,
    1271712728                                49EECF1A105072F300099FAB /* JSCanvasArray.h */,
     
    1801218023                                97DD4D870FDF4D6E00ECF9A4 /* XSSAuditor.h in Headers */,
    1801318024                                97DCE20210807C750057D394 /* HistoryController.h in Headers */,
     18025                                A7D20F63107F406900A80392 /* JSCanvasActiveInfo.h in Headers */,
     18026                                A7D20F6D107F438B00A80392 /* CanvasActiveInfo.h in Headers */,
    1801418027                        );
    1801518028                        runOnlyForDeploymentPostprocessing = 0;
     
    2014020153                                97DD4D860FDF4D6E00ECF9A4 /* XSSAuditor.cpp in Sources */,
    2014120154                                97DCE20110807C750057D394 /* HistoryController.cpp in Sources */,
     20155                                A7D20F62107F406900A80392 /* JSCanvasActiveInfo.cpp in Sources */,
    2014220156                        );
    2014320157                        runOnlyForDeploymentPostprocessing = 0;
  • trunk/WebCore/html/canvas/CanvasActiveInfo.h

    r49419 r49420  
    11/*
    2  * Copyright (C) 2009 Apple Inc. All rights reserved.
     2 * Copyright (C) 2009 Apple Inc. All Rights Reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    1111 *    documentation and/or other materials provided with the distribution.
    1212 *
    13  * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
     13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
    1414 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
    1515 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
    16  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
     16 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
    1717 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
    1818 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
     
    2424 */
    2525
    26 #ifndef CanvasObject_h
    27 #define CanvasObject_h
     26#ifndef CanvasActiveInfo_h
     27#define CanvasActiveInfo_h
    2828
     29#include "PlatformString.h"
    2930#include <wtf/PassRefPtr.h>
    3031#include <wtf/RefCounted.h>
    3132
    32 #include "GraphicsContext3D.h"
    33 
    3433namespace WebCore {
    3534
    36     class CanvasRenderingContext3D;
    37    
    38     class CanvasObject : public RefCounted<CanvasObject> {
    39     public:
    40         virtual ~CanvasObject();
    41        
    42         Platform3DObject object() const { return m_object; }
    43         void setObject(Platform3DObject);
    44         void deleteObject();
    45        
    46         void detachContext()
    47         {
    48             deleteObject();
    49             m_context = 0;
    50         }
    51        
    52     protected:
    53         CanvasObject(CanvasRenderingContext3D*);
    54         virtual void _deleteObject(Platform3DObject) = 0;
    55        
    56         CanvasRenderingContext3D* context() const { return m_context; }
    57    
    58     private:
    59         Platform3DObject m_object;
    60         CanvasRenderingContext3D* m_context;
    61     };
    62    
    63 } // namespace WebCore
     35class CanvasActiveInfo : public RefCounted<CanvasActiveInfo> {
     36public:
     37    static PassRefPtr<CanvasActiveInfo> create(const String& name, unsigned type, int size)
     38    {
     39        return adoptRef(new CanvasActiveInfo(name, type, size));
     40    }
     41    String name() const { return m_name; }
     42    unsigned type() const { return m_type; }
     43    int size() const { return m_size; }
    6444
    65 #endif // CanvasObject_h
     45private:
     46    CanvasActiveInfo(const String& name, unsigned type, int size)
     47        : m_name(name)
     48        , m_type(type)
     49        , m_size(size)
     50    {
     51        ASSERT(name.length());
     52        ASSERT(type);
     53        ASSERT(size);
     54    }
     55    String m_name;
     56    unsigned m_type;
     57    int m_size;
     58};
     59
     60}
     61
     62#endif // CanvasActiveInfo_h
  • trunk/WebCore/html/canvas/CanvasActiveInfo.idl

    r49419 r49420  
    11/*
    2  * Copyright (C) 2009 Apple Inc. All rights reserved.
     2 * Copyright (C) 2009 Apple Inc. All Rights Reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    1111 *    documentation and/or other materials provided with the distribution.
    1212 *
    13  * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
     13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
    1414 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
    1515 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
    16  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
     16 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
    1717 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
    1818 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
     
    2424 */
    2525
    26 #ifndef CanvasObject_h
    27 #define CanvasObject_h
     26module html {
    2827
    29 #include <wtf/PassRefPtr.h>
    30 #include <wtf/RefCounted.h>
     28    interface [
     29        Conditional=3D_CANVAS,
     30    ] CanvasActiveInfo {
     31        readonly attribute int size;
     32        readonly attribute unsigned int type;
     33        readonly attribute DOMString name;
     34    };
    3135
    32 #include "GraphicsContext3D.h"
    33 
    34 namespace WebCore {
    35 
    36     class CanvasRenderingContext3D;
    37    
    38     class CanvasObject : public RefCounted<CanvasObject> {
    39     public:
    40         virtual ~CanvasObject();
    41        
    42         Platform3DObject object() const { return m_object; }
    43         void setObject(Platform3DObject);
    44         void deleteObject();
    45        
    46         void detachContext()
    47         {
    48             deleteObject();
    49             m_context = 0;
    50         }
    51        
    52     protected:
    53         CanvasObject(CanvasRenderingContext3D*);
    54         virtual void _deleteObject(Platform3DObject) = 0;
    55        
    56         CanvasRenderingContext3D* context() const { return m_context; }
    57    
    58     private:
    59         Platform3DObject m_object;
    60         CanvasRenderingContext3D* m_context;
    61     };
    62    
    63 } // namespace WebCore
    64 
    65 #endif // CanvasObject_h
     36}
  • trunk/WebCore/html/canvas/CanvasObject.h

    r47843 r49420  
    4949            m_context = 0;
    5050        }
    51        
     51
     52        CanvasRenderingContext3D* context() const { return m_context; }
     53
    5254    protected:
    5355        CanvasObject(CanvasRenderingContext3D*);
    5456        virtual void _deleteObject(Platform3DObject) = 0;
    55        
    56         CanvasRenderingContext3D* context() const { return m_context; }
    5757   
    5858    private:
  • trunk/WebCore/html/canvas/CanvasRenderingContext3D.cpp

    r48325 r49420  
    2929
    3030#include "CanvasRenderingContext3D.h"
     31
     32#include "CanvasActiveInfo.h"
    3133#include "CanvasBuffer.h"
    3234#include "CanvasFramebuffer.h"
     
    478480}
    479481
     482PassRefPtr<CanvasActiveInfo> CanvasRenderingContext3D::getActiveAttrib(CanvasProgram* program, unsigned long index, ExceptionCode& ec)
     483{
     484    ActiveInfo info;
     485    if (!program || program->context() != this || !m_context.getActiveAttrib(program, index, info)) {
     486        ec = INDEX_SIZE_ERR;
     487        return 0;
     488    }
     489    return CanvasActiveInfo::create(info.name, info.type, info.size);
     490}
     491
     492PassRefPtr<CanvasActiveInfo> CanvasRenderingContext3D::getActiveUniform(CanvasProgram* program, unsigned long index, ExceptionCode& ec)
     493{
     494    ActiveInfo info;
     495    if (!program || program->context() != this || !m_context.getActiveUniform(program, index, info)) {
     496        ec = INDEX_SIZE_ERR;
     497        return 0;
     498    }
     499    return CanvasActiveInfo::create(info.name, info.type, info.size);
     500}
     501
    480502int CanvasRenderingContext3D::getAttribLocation(CanvasProgram* program, const String& name)
    481503{
  • trunk/WebCore/html/canvas/CanvasRenderingContext3D.h

    r48325 r49420  
    3737namespace WebCore {
    3838
     39class CanvasActiveInfo;
    3940class CanvasBuffer;
    4041class CanvasFramebuffer;
     
    124125        void frontFace(unsigned long mode);
    125126        void generateMipmap(unsigned long target);
    126        
     127
     128        PassRefPtr<CanvasActiveInfo> getActiveAttrib(CanvasProgram*, unsigned long index, ExceptionCode&);
     129        PassRefPtr<CanvasActiveInfo> getActiveUniform(CanvasProgram*, unsigned long index, ExceptionCode&);
     130
    127131        int  getAttribLocation(CanvasProgram*, const String& name);
    128132
  • trunk/WebCore/html/canvas/CanvasRenderingContext3D.idl

    r48325 r49420  
    531531       
    532532        // FIXME: these need to be added per the WebGL spec
    533         // CanvasActiveInfo getActiveAttrib(GLuint program, GLuint index);
    534         // CanvasActiveInfo getActiveUniform(GLuint program, GLuint index);
     533        CanvasActiveInfo getActiveAttrib(in CanvasProgram program, in unsigned long index)
     534            raises (DOMException);
     535        CanvasActiveInfo getActiveUniform(in CanvasProgram program, in unsigned long index)
     536            raises (DOMException);
     537
    535538        // CanvasShaderArray glGetAttachedShaders(GLuint program);
    536539
  • trunk/WebCore/platform/graphics/GraphicsContext3D.h

    r49132 r49420  
    4646
    4747namespace WebCore {
     48    class CanvasActiveInfo;
    4849    class CanvasArray;
    4950    class CanvasBuffer;
     
    6263    class ImageData;
    6364    class WebKitCSSMatrix;
    64    
     65
     66    struct ActiveInfo {
     67        String name;
     68        unsigned type;
     69        int size;
     70    };
     71
    6572    // FIXME: ideally this would be used on all platforms.
    6673#if PLATFORM(CHROMIUM)
     
    141148        void frontFace(unsigned long mode);
    142149        void generateMipmap(unsigned long target);
     150
     151        bool getActiveAttrib(CanvasProgram* program, unsigned long index, ActiveInfo&);
     152        bool getActiveUniform(CanvasProgram* program, unsigned long index, ActiveInfo&);
    143153
    144154        int  getAttribLocation(CanvasProgram*, const String& name);
  • trunk/WebCore/platform/graphics/mac/GraphicsContext3DMac.cpp

    r48325 r49420  
    3131
    3232#include "CachedImage.h"
     33#include "CanvasActiveInfo.h"
     34#include "CanvasArray.h"
    3335#include "CanvasBuffer.h"
    3436#include "CanvasFramebuffer.h"
    35 #include "CanvasArray.h"
    3637#include "CanvasFloatArray.h"
    3738#include "CanvasIntArray.h"
     
    441442    ensureContext(m_contextObj);
    442443    ::glGenerateMipmapEXT(target);
     444}
     445
     446bool GraphicsContext3D::getActiveAttrib(CanvasProgram* program, unsigned long index, ActiveInfo& info)
     447{
     448    if (!program->object())
     449        return false;
     450    ensureContext(m_contextObj);
     451    GLint maxAttributeSize = 0;
     452    ::glGetProgramiv(static_cast<GLuint>(program->object()), GL_ACTIVE_ATTRIBUTE_MAX_LENGTH, &maxAttributeSize);
     453    GLchar name[maxAttributeSize]; // GL_ACTIVE_ATTRIBUTE_MAX_LENGTH includes null termination
     454    GLsizei nameLength = 0;
     455    GLint size = 0;
     456    GLenum type = 0;
     457    ::glGetActiveAttrib(static_cast<GLuint>(program->object()), index, maxAttributeSize, &nameLength, &size, &type, name);
     458    if (!nameLength)
     459        return false;
     460    info.name = String(name, nameLength);
     461    info.type = type;
     462    info.size = size;
     463    return true;
     464}
     465   
     466bool GraphicsContext3D::getActiveUniform(CanvasProgram* program, unsigned long index, ActiveInfo& info)
     467{
     468    if (!program->object())
     469        return false;
     470    ensureContext(m_contextObj);
     471    GLint maxUniformSize = 0;
     472    ::glGetProgramiv(static_cast<GLuint>(program->object()), GL_ACTIVE_UNIFORM_MAX_LENGTH, &maxUniformSize);
     473    GLchar name[maxUniformSize]; // GL_ACTIVE_UNIFORM_MAX_LENGTH includes null termination
     474    GLsizei nameLength = 0;
     475    GLint size = 0;
     476    GLenum type = 0;
     477    ::glGetActiveUniform(static_cast<GLuint>(program->object()), index, maxUniformSize, &nameLength, &size, &type, name);
     478    if (!nameLength)
     479        return false;
     480    info.name = String(name, nameLength);
     481    info.type = type;
     482    info.size = size;
     483    return true;
    443484}
    444485
Note: See TracChangeset for help on using the changeset viewer.