Bug 2765 - How do we identify surface types?
Summary: How do we identify surface types?
Status: RESOLVED FIXED
Alias: None
Product: cairo
Classification: Unclassified
Component: general (show other bugs)
Version: 0.9.3
Hardware: x86 (IA32) Linux (All)
: high normal
Assignee: Carl Worth
QA Contact: cairo-bugs mailing list
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2005-03-18 18:12 UTC by Steve Chaplin
Modified: 2006-04-19 00:12 UTC (History)
2 users (show)

See Also:
i915 platform:
i915 features:


Attachments

Description Steve Chaplin 2005-03-18 18:12:54 UTC
This issue arose on the cairo@cairographics.org mail list.
http://lists.freedesktop.org/archives/cairo/2005-March/003423.html

Some surfaces have functions that are specific to their backend. A language
binding can implement them by creating a Surface base class with surface methods
common to all surfaces, and a Surface subclass (or subclasses) with methods
specific to a particular backend.
This requires there to be some way in cairo to identify the surface type.

Possible solutions suggested by Owen Taylor (copied from the mail list):
How do we identify surface types? 
 
 1. Strings. cairo_surface_get_backend_name()

 2. Boolean predicate. cairo_surface_is_xlib()

 3. Opaque type object
    cairo_type_t *cairo_surface_get_type()
    cairo_type_t *cairo_xlib_surface_type()

 4. Global #defines

    #define CAIRO_TYPE_XLIB_SURFACE 1

Not clear to me what's right.
Comment 1 Carl Worth 2005-08-22 17:14:49 UTC
Move bugs against "cvs" version to "0.9.3" so we can remove the "cvs" version.
Comment 2 Steve Chaplin 2005-09-01 04:32:17 UTC
This is needed by pycairo, and probably other language bindings in a situation
like this:

surface = cairo.ImageSurface()
    # or cairo.PDFSurface(), or cairo.PSSurface(), or cairo.Win32Surface()
...
# later we may no longer have the 'surface' reference, and do:
surface = cairo.Context.get_target(ctx)

# in the get_target() wrapper we need to be able to determine the surface
# type so we can create the correct surface object.

pycairo now implements Patterns in a class hierarchy (as suggested by the
Appendix to the manual) and has the equivalent problem with patterns and the
wrapper cairo.Context.get_source()
Comment 3 Torsten Schönfeld 2005-12-14 05:12:14 UTC
From my point of view (Perl bindings), an enum type

typedef enum {
  CAIRO_SURFACE_TYPE_XLIB,
  CAIRO_SURFACE_TYPE_PDF,
  ...
} CairoSurfaceType

and

CairoSurfaceType cairo_surface_get_type (cairo_surface_t *surface)

would suffice.

(And equivalent stuff for cairo_pattern_t, of course.)
Comment 4 Carl Worth 2005-12-14 05:20:41 UTC
Looks like the email archives got renumbered at some point. Here are links to
the original thread (though there's not much there that's not already quoted
here in this bug):

http://lists.freedesktop.org/archives/cairo/2005-March/003431.html
http://lists.freedesktop.org/archives/cairo/2005-March/003432.html
Comment 5 Carl Worth 2005-12-14 05:26:44 UTC
Looks like the email archives got renumbered at some point. Here are links to
the original thread:

http://lists.freedesktop.org/archives/cairo/2005-March/003431.html

and where it got picked up again a couple months later[*]:

http://lists.freedesktop.org/archives/cairo/2005-May/004112.html

A single get_type function per object and enums for the return value sounds
pretty good to me, (and better than the is_<foo> family of functions I proposed
in the thread above).

-Carl

[*] It is painful beyond annoying that pipermail doesn't do any threading across
month boundaries. I'd really like to switch to an archiver that wasn't so broken.
Comment 6 Carl Worth 2006-04-19 17:12:16 UTC
This is fixed with the addition of cairo_surface_get_type, (and similarly for
patterns with cairo_pattern_get_type, etc.), in cairo 1.1.1 as of 2006-02-28.
The relevant commits are below:

-Carl

PS. It would be a dandy thing to tweak this bugzilla instance so that git commit
IDs would automatically be munged into correct gitweb links.

commit f9534c856a71b0f56a1e5bc58141b7bc192a27e8
Author: Carl Worth <cworth@cworth.org>
Date:   Tue Feb 28 01:30:58 2006 -0800

    test/pattern-get-type: Add new test case for cairo_pattern_get_type.

commit 1dd6e417c10c90894c87565d4f7fa3f63e97f212
Author: Carl Worth <cworth@cworth.org>
Date:   Tue Feb 28 00:55:27 2006 -0800

    Add testing for cairo_surface_get_type.

    All test targets now list an expected cairo_surface_type_t. Add notes
    on current limitations of PDF/PS/meta-surface support that causes
    CAIRO_CONTENT_COLOR similar surfaces of PDF and PS surfaces to be
    returned as image surfaces.

    Add cairo_internal_surface_type_t for the meta, paginated, and various
    test surfaces.

commit cd84e2ab32fe4648f9d172cdefe08798336938d2
Author: Carl Worth <cworth@cworth.org>
Date:   Mon Feb 27 23:15:45 2006 -0800

    Add documentation for cairo_font_face_get_type,
    cairo_scaled_font_get_type, cairo_surface_get_type, and
    cairo_pattern_get_type.

commit 5797f814852bb4f6ef559890640b8cd24ec5fa45
Author: Carl Worth <cworth@cworth.org>
Date:   Mon Feb 27 23:12:43 2006 -0800

    Implement cairo_pattern_get_type

commit 5ae0b9f912b7f5fd1700cbf18763a05493f55b62
Author: Carl Worth <cworth@cworth.org>
Date:   Mon Feb 27 23:11:32 2006 -0800

    Implement cairo_surface_get_type



Use of freedesktop.org services, including Bugzilla, is subject to our Code of Conduct. How we collect and use information is described in our Privacy Policy.