Home | History | Annotate | Download | only in src
      1 /*
      2  INTEL CONFIDENTIAL
      3  Copyright 2009 Intel Corporation All Rights Reserved.
      4  The source code contained or described herein and all documents related to the source code ("Material") are owned by Intel Corporation or its suppliers or licensors. Title to the Material remains with Intel Corporation or its suppliers and licensors. The Material contains trade secrets and proprietary and confidential information of Intel or its suppliers and licensors. The Material is protected by worldwide copyright and trade secret laws and treaty provisions. No part of the Material may be used, copied, reproduced, modified, published, uploaded, posted, transmitted, distributed, or disclosed in any way without Intels prior express written permission.
      5 
      6  No license under any patent, copyright, trade secret or other intellectual property right is granted to or conferred upon you by disclosure or delivery of the Materials, either expressly, by implication, inducement, estoppel or otherwise. Any license under such intellectual property rights must be express and approved by Intel in writing.
      7  */
      8 
      9 /**
     10  * SECTION:mixdisplayx11
     11  * @short_description: VideoInit parameters
     12  *
     13  * A data object which stores videoinit specific parameters.
     14  */
     15 
     16 #include "mixdisplayx11.h"
     17 
     18 #define SAFE_FREE(p) if(p) { g_free(p); p = NULL; }
     19 
     20 static GType _mix_displayx11_type = 0;
     21 static MixDisplayClass *parent_class = NULL;
     22 
     23 #define _do_init { _mix_displayx11_type = g_define_type_id; }
     24 
     25 gboolean mix_displayx11_copy(MixDisplay * target, const MixDisplay * src);
     26 MixDisplay *mix_displayx11_dup(const MixDisplay * obj);
     27 gboolean mix_displayx11_equal(MixDisplay * first, MixDisplay * second);
     28 static void mix_displayx11_finalize(MixDisplay * obj);
     29 
     30 G_DEFINE_TYPE_WITH_CODE (MixDisplayX11, mix_displayx11,
     31 		MIX_TYPE_DISPLAY, _do_init);
     32 
     33 static void mix_displayx11_init(MixDisplayX11 * self) {
     34 
     35 	/* Initialize member varibles */
     36 	self->display = NULL;
     37 	self->drawable = 0;
     38 }
     39 
     40 static void mix_displayx11_class_init(MixDisplayX11Class * klass) {
     41 	MixDisplayClass *mixdisplay_class = MIX_DISPLAY_CLASS(klass);
     42 
     43 	/* setup static parent class */
     44 	parent_class = (MixDisplayClass *) g_type_class_peek_parent(klass);
     45 
     46 	mixdisplay_class->finalize = mix_displayx11_finalize;
     47 	mixdisplay_class->copy = (MixDisplayCopyFunction) mix_displayx11_copy;
     48 	mixdisplay_class->dup = (MixDisplayDupFunction) mix_displayx11_dup;
     49 	mixdisplay_class->equal = (MixDisplayEqualFunction) mix_displayx11_equal;
     50 }
     51 
     52 MixDisplayX11 *
     53 mix_displayx11_new(void) {
     54 	MixDisplayX11 *ret = (MixDisplayX11 *) g_type_create_instance(
     55 			MIX_TYPE_DISPLAYX11);
     56 
     57 	return ret;
     58 }
     59 
     60 void mix_displayx11_finalize(MixDisplay * obj) {
     61 	/* clean up here. */
     62 	/* MixDisplayX11 *self = MIX_DISPLAYX11 (obj); */
     63 
     64 	/* NOTE: we don't need to do anything
     65 	 * with display and drawable */
     66 
     67 	/* Chain up parent */
     68 	if (parent_class->finalize)
     69 		parent_class->finalize(obj);
     70 }
     71 
     72 MixDisplayX11 *
     73 mix_displayx11_ref(MixDisplayX11 * mix) {
     74 	return (MixDisplayX11 *) mix_display_ref(MIX_DISPLAY(mix));
     75 }
     76 
     77 /**
     78  * mix_mixdisplayx11_dup:
     79  * @obj: a #MixDisplayX11 object
     80  * @returns: a newly allocated duplicate of the object.
     81  *
     82  * Copy duplicate of the object.
     83  */
     84 MixDisplay *
     85 mix_displayx11_dup(const MixDisplay * obj) {
     86 	MixDisplay *ret = NULL;
     87 
     88 	if (MIX_IS_DISPLAYX11(obj)) {
     89 		MixDisplayX11 *duplicate = mix_displayx11_new();
     90 		if (mix_displayx11_copy(MIX_DISPLAY(duplicate), MIX_DISPLAY(obj))) {
     91 			ret = MIX_DISPLAY(duplicate);
     92 		} else {
     93 			mix_displayx11_unref(duplicate);
     94 		}
     95 	}
     96 	return ret;
     97 }
     98 
     99 /**
    100  * mix_mixdisplayx11_copy:
    101  * @target: copy to target
    102  * @src: copy from src
    103  * @returns: boolean indicates if copy is successful.
    104  *
    105  * Copy instance data from @src to @target.
    106  */
    107 gboolean mix_displayx11_copy(MixDisplay * target, const MixDisplay * src) {
    108 	MixDisplayX11 *this_target, *this_src;
    109 
    110 	if (MIX_IS_DISPLAYX11(target) && MIX_IS_DISPLAYX11(src)) {
    111 		// Cast the base object to this child object
    112 		this_target = MIX_DISPLAYX11(target);
    113 		this_src = MIX_DISPLAYX11(src);
    114 
    115 		// Copy properties from source to target.
    116 
    117 		this_target->display = this_src->display;
    118 		this_target->drawable = this_src->drawable;
    119 
    120 		// Now chainup base class
    121 		if (parent_class->copy) {
    122 			return parent_class->copy(MIX_DISPLAY_CAST(target),
    123 					MIX_DISPLAY_CAST(src));
    124 		} else {
    125 			return TRUE;
    126 		}
    127 	}
    128 	return FALSE;
    129 }
    130 
    131 /**
    132  * mix_mixdisplayx11_equal:
    133  * @first: first object to compare
    134  * @second: seond object to compare
    135  * @returns: boolean indicates if instance are equal.
    136  *
    137  * Copy instance data from @src to @target.
    138  */
    139 gboolean mix_displayx11_equal(MixDisplay * first, MixDisplay * second) {
    140 	gboolean ret = FALSE;
    141 
    142 	MixDisplayX11 *this_first, *this_second;
    143 
    144 	this_first = MIX_DISPLAYX11(first);
    145 	this_second = MIX_DISPLAYX11(second);
    146 
    147 	if (MIX_IS_DISPLAYX11(first) && MIX_IS_DISPLAYX11(second)) {
    148 		// Compare member variables
    149 
    150 		// TODO: if in the copy method we just copy the pointer of display, the comparison
    151 		//      below is enough. But we need to decide how to copy!
    152 
    153 		if (this_first->display == this_second->display && this_first->drawable
    154 				== this_second->drawable) {
    155 			// members within this scope equal. chaining up.
    156 			MixDisplayClass *klass = MIX_DISPLAY_CLASS(parent_class);
    157 			if (klass->equal)
    158 				ret = parent_class->equal(first, second);
    159 			else
    160 				ret = TRUE;
    161 		}
    162 	}
    163 	return ret;
    164 }
    165 
    166 #define MIX_DISPLAYX11_SETTER_CHECK_INPUT(obj) \
    167 	if(!obj) return MIX_RESULT_NULL_PTR; \
    168 	if(!MIX_IS_DISPLAYX11(obj)) return MIX_RESULT_FAIL; \
    169 
    170 #define MIX_DISPLAYX11_GETTER_CHECK_INPUT(obj, prop) \
    171 	if(!obj || !prop) return MIX_RESULT_NULL_PTR; \
    172 	if(!MIX_IS_DISPLAYX11(obj)) return MIX_RESULT_FAIL; \
    173 
    174 MIX_RESULT mix_displayx11_set_display(MixDisplayX11 * obj, Display * display) {
    175 	MIX_DISPLAYX11_SETTER_CHECK_INPUT (obj);
    176 
    177 	// TODO: needs to decide to clone or just copy pointer
    178 	obj->display = display;
    179 	return MIX_RESULT_SUCCESS;
    180 }
    181 
    182 MIX_RESULT mix_displayx11_get_display(MixDisplayX11 * obj, Display ** display) {
    183 	MIX_DISPLAYX11_GETTER_CHECK_INPUT (obj, display);
    184 
    185 	// TODO: needs to decide to clone or just copy pointer
    186 	*display = obj->display;
    187 
    188 	return MIX_RESULT_SUCCESS;
    189 }
    190 
    191 MIX_RESULT mix_displayx11_set_drawable(MixDisplayX11 * obj, Drawable drawable) {
    192 	MIX_DISPLAYX11_SETTER_CHECK_INPUT (obj);
    193 
    194 	// TODO: needs to decide to clone or just copy pointer
    195 	obj->drawable = drawable;
    196 	return MIX_RESULT_SUCCESS;
    197 }
    198 
    199 MIX_RESULT mix_displayx11_get_drawable(MixDisplayX11 * obj, Drawable * drawable) {
    200 	MIX_DISPLAYX11_GETTER_CHECK_INPUT (obj, drawable);
    201 
    202 	// TODO: needs to decide to clone or just copy pointer
    203 	*drawable = obj->drawable;
    204 	return MIX_RESULT_SUCCESS;
    205 }
    206