text:
using Castle.DynamicProxy;
using Xunit;

namespace Autofac.Extras.DynamicProxy.Test
{
    public class InterceptorsChosenByMetadataFixture
    {
        public interface ICustomerService
        {
            int GetVisitCount();
        }

        [Fact]
        public void InterceptsWhenUsingExtendedPropertyAndType()
        {
            var builder = new ContainerBuilder();
            builder.RegisterType<CustomerService>()
                .As<ICustomerService>()
                .EnableInterfaceInterceptors()
                .InterceptedBy(typeof(AddOneInterceptor));
            builder.RegisterType<AddOneInterceptor>();
            var container = builder.Build();
            var cs = container.Resolve<ICustomerService>();
            Assert.Equal(11, cs.GetVisitCount());
        }

        public class CustomerService : ICustomerService
        {
            public CustomerService()
            {
                VisitCount = 10;
            }

            private int VisitCount { get; set; }

            public int GetVisitCount()
            {
                return VisitCount;
            }
        }

        private class AddOneInterceptor : IInterceptor
        {
            public void Intercept(IInvocation invocation)
            {
                invocation.Proceed();
                if (invocation.Method.Name.StartsWith("Get"))
                {
                    invocation.ReturnValue = 1 + (int)invocation.ReturnValue;
                }
            }
        }
    }
}

redpajama_set_name: RedPajamaGithub


text:
// GroupsSearch.cpp : implementation file
//

#include "stdafx.h"
#include "groupscombo.h"
#include "GroupsSearch.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CGroupsSearch dialog

CGroupsSearch::CGroupsSearch(CWnd* pParent /*=NULL*/)
	: CDialog(CGroupsSearch::IDD, pParent)
{
	//{{AFX_DATA_INIT(CGroupsSearch)
	m_Text = _T("");
	//}}AFX_DATA_INIT
}

void CGroupsSearch::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CGroupsSearch)
	DDX_Text(pDX, IDC_EDIT, m_Text);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CGroupsSearch, CDialog)
	//{{AFX_MSG_MAP(CGroupsSearch)
		// NOTE: the ClassWizard will add message map macros here
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CGroupsSearch message handlers


text:
package gemlite.core.internal.support.hotdeploy.scanner;

import gemlite.core.internal.support.hotdeploy.GemliteClassLoader;
import gemlite.core.util.LogUtil;

import java.io.BufferedInputStream;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.net.URLConnection;
import java.util.jar.JarEntry;

import org.apache.commons.io.FileUtils;

public class ScannerIteratorItem
{
  public ScannerIteratorItem(String name, Object item,boolean jarFile)
  {
    this.name = name;
    this.item = item;
    this.jarFile = jarFile;
  }

  private Object item;
  private String name;
  private boolean jarFile;

  public String getName()
  {
    return name;
  }

  public Object getItem()
  {
    return item;
  }

  public byte[] getBytes() throws IOException
  {
    return getBytes(GemliteClassLoader.getInstance());
  }

  public byte[] getBytes(ClassLoader loader) throws IOException
  {
    byte[] bytes = null;
    if (jarFile)
      bytes = readContent(loader, (JarEntry) item);
    else
      bytes = FileUtils.readFileToByteArray((File) item);
    return bytes;
  }

  private byte[] readContent(ClassLoader loader, JarEntry entry) throws IOException
  {
    URL url =  loader.getResource(entry.getName());
    URLConnection ulc =  url.openConnection();
    InputStream in3 = ulc.getInputStream();
    InputStream in2 = url.openStream();

    InputStream in = loader.getResourceAsStream(entry.getName());
    if(in == null)
    {
      LogUtil.getCoreLog().trace("ReadContent inputStream is null entry.name={} , loader={}",entry.getName(),loader);
    }

    BufferedInputStream bi = new BufferedInputStream(in);
    byte[] bt = new byte[in.available()];
    bi.read(bt);
    bi.close();
    in.close();
    return bt;
  }
}


text:
package chessGame;

public class ScoringMode implements GameMode{

	@Override
	public String printResult(ChessPlayer player1, ChessPlayer player2) {
		ChessPlayer winner;
		int score1 = player1.getPlayerScore();
		int score2 = player2.getPlayerScore();
		if (score1 > score2)
			winner = player1;
		else if (score2 > score1)
			winner = player2;
		else
			return "Draw!";
		return winner.toString() + " is the winner!" + "\n" + "winner's score: " + winner.getPlayerScore();
	}

	@Override
	public boolean isEndGame() {
		ChessMonitoringSystem cms = ChessMonitoringSystem.getInstance();
    	if (cms.isKingCaptured()!=null)
    		return true;
    	else
    		return false;
	}

	@Override
	public void addScore(ChessPlayer player, int[] scoreRelated) {
		player.addScore(scoreRelated[0]);
	}

}


text:
package io.github.kosmologist.libtriangulum.util;

/**
 * Created by mqasim on 2/28/2017.
 */

public enum ContentType {

    PLAIN_TEXT,
    TEXT_HTML;

}


text:
<?php

class CPAC_Storage_Model_MS_User extends CPAC_Storage_Model {

	/**
	 * Constructor
	 *
	 * @since 2.0
	 */
	function __construct() {

		$this->key = 'wp-ms_users';
		$this->label = __( 'Network Users' );
		$this->type = 'user';
		$this->meta_type = 'user';
		$this->page = 'users';

		parent::__construct();
	}

	/**
	 * @since 3.7
	 */
	public function init_manage_columns() {
		add_filter( "wpmu_users_columns", array( $this, 'add_headings' ), 100 );
		add_filter( 'manage_users_custom_column', array( $this, 'manage_value_callback' ), 100, 3 );
	}

	/**
	 * @since 3.7.3
	 */
	public function is_current_screen() {
		return is_network_admin() && parent::is_current_screen();
	}

	/**
	 * @since 2.0
	 * @return string Link
	 */
	protected function get_screen_link() {

		return network_admin_url( $this->page . '.php' );
	}

	/**
	 * Get WP default supported admin columns per post type.
	 *
	 * @see CPAC_Type::get_default_columns()
	 * @since 1.0
	 *
	 * @return array
	 */
	public function get_default_columns() {

		if ( ! function_exists( '_get_list_table' ) ) {
			return array();
		}

		// You can use this filter to add third_party columns by hooking into this.
		do_action( "cac/columns/default/storage_key={$this->key}" );

		// get columns
		$table = _get_list_table( 'WP_MS_Users_List_Table', array( 'screen' => 'users' ) );
		$columns = (array) $table->get_columns();

		if ( cac_is_setting_screen() ) {
			$columns = array_merge( get_column_headers( 'users' ), $columns );
		}

		return $columns;
	}

	/**
	 * Get original columns
	 *
	 * @since 2.4.4
	 */
	public function get_default_column_names() {
		return array( 'cb', 'username', 'name', 'email', 'registered', 'blogs', 'posts', 'role' );
	}

	/**
	 * Manage value
	 *
	 * @since 2.0.2
	 *
	 * @param string $column_name
	 * @param int $user_id
	 * @param string $value
	 */
	public function manage_value( $column_name, $user_id, $value = '' ) {

		// get column instance
		$column = $this->get_column_by_name( $column_name );

		if ( ! $column ) {
			return $value;
		}

		// get value
		$custom_value = $column->get_value( $user_id );

		// make sure it absolutely empty and check for (string) 0
		if ( ! empty( $custom_value ) || '0' === $custom_value ) {
			$value = $custom_value;
		}

		// filters
		$value = apply_filters( "cac/column/value", $value, $user_id, $column, $this->key );
		$value = apply_filters( "cac/column/value/{$this->type}", $value, $user_id, $column, $this->key );

		return $value;
	}

	/**
	 * Callback Manage value
	 *
	 * @since 2.0.2
	 *
	 * @param string $value
	 * @param string $column_name
	 * @param int $user_id
	 */
	public function manage_value_callback( $value, $column_name, $user_id ) {

		return $this->manage_value( $column_name, $user_id, $value );
	}

	/**
	 * Get Meta
	 *
	 * @see CPAC_Columns::get_meta_keys()
	 * @since 2.0
	 *
	 * @return array
	 */
	public function get_meta() {
		global $wpdb;

		if ( $cache = wp_cache_get( $this->key, 'cac_columns' ) ) {
			$result = $cache;
		} else {
			$result = $wpdb->get_results( "SELECT DISTINCT meta_key FROM {$wpdb->usermeta} ORDER BY 1", ARRAY_N );
			wp_cache_add( $this->key, $result, 'cac_columns', 10 ); // 10 sec.
		}

		return $result;
	}
}


text:
#import <Foundation/Foundation.h>
#import "PhoneGapCommand.h"

enum DestinationType {
	DestinationTypeDataUrl = 0,
	DestinationTypeFileUri
};
typedef NSUInteger DestinationType;

@interface CameraPicker : UIImagePickerController
{
	NSString* successCallback;
	NSString* errorCallback;
	NSInteger quality;
	NSString* postUrl;
	enum DestinationType returnType;
}

@property (assign) NSInteger quality;
@property (copy)   NSString* successCallback;
@property (copy)   NSString* errorCallback;
@property (copy)   NSString* postUrl;
@property (nonatomic) DestinationType returnType;

- (void) dealloc;

@end

@interface Camera : PhoneGapCommand<UIImagePickerControllerDelegate, UINavigationControllerDelegate>
{
	CameraPicker* pickerController;
}

/*
 * getPicture
 *
 * arguments:
 *	1: this is the javascript function that will be called with the results, the first parameter passed to the
 *		javascript function is the picture as a Base64 encoded string
 *  2: this is the javascript function to be called if there was an error
 * options:
 *	quality: integer between 1 and 100
 */
- (void) getPicture:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options;
- (void) postImage:(UIImage*)anImage withFilename:(NSString*)filename toUrl:(NSURL*)url;

- (void)imagePickerController:(UIImagePickerController*)picker didFinishPickingMediaWithInfo:(NSDictionary*)info;
- (void)imagePickerController:(UIImagePickerController*)picker didFinishPickingImage:(UIImage*)image editingInfo:(NSDictionary*)editingInfo;
- (void)imagePickerControllerDidCancel:(UIImagePickerController*)picker;

- (void) dealloc;

@end


text:
var decode = function () {
    import "./read-format";
    import "./read-token";

    return function (decoder) {
        var type = format.uint8(decoder);
        if (!token[type])
            throw new Error("Invalid type: " + (type ? ("0x" + type.toString(16)) : type));

        return token[type](decoder);
    }
}();


text:
#pragma once
#include <aws/ec2/EC2_EXPORTS.h>
#include <aws/ec2/EC2Request.h>
#include <aws/core/utils/memory/stl/AWSString.h>
#include <utility>

namespace Aws
{
namespace EC2
{
namespace Model
{

  /**
   */
  class AWS_EC2_API WithdrawByoipCidrRequest : public EC2Request
  {
  public:
    WithdrawByoipCidrRequest();

    // Service request name is the Operation name which will send this request out,
    // each operation should has unique request name, so that we can get operation's name from this request.
    // Note: this is not true for response, multiple operations may have the same response name,
    // so we can not get operation's name from response.
    inline virtual const char* GetServiceRequestName() const override { return "WithdrawByoipCidr"; }

    Aws::String SerializePayload() const override;

  protected:
    void DumpBodyToUrl(Aws::Http::URI& uri ) const override;

  public:

    /**
     *
The public IPv4 address range, in CIDR notation.

     */
    inline const Aws::String& GetCidr() const{ return m_cidr; }

    /**
     *
The public IPv4 address range, in CIDR notation.

     */
    inline void SetCidr(const Aws::String& value) { m_cidrHasBeenSet = true; m_cidr = value; }

    /**
     *
The public IPv4 address range, in CIDR notation.

     */
    inline void SetCidr(Aws::String&& value) { m_cidrHasBeenSet = true; m_cidr = std::move(value); }

    /**
     *
The public IPv4 address range, in CIDR notation.

     */
    inline void SetCidr(const char* value) { m_cidrHasBeenSet = true; m_cidr.assign(value); }

    /**
     *
The public IPv4 address range, in CIDR notation.

     */
    inline WithdrawByoipCidrRequest& WithCidr(const Aws::String& value) { SetCidr(value); return *this;}

    /**
     *
The public IPv4 address range, in CIDR notation.

     */
    inline WithdrawByoipCidrRequest& WithCidr(Aws::String&& value) { SetCidr(std::move(value)); return *this;}

    /**
     *
The public IPv4 address range, in CIDR notation.

     */
    inline WithdrawByoipCidrRequest& WithCidr(const char* value) { SetCidr(value); return *this;}

    /**
     *
Checks whether you have the required permissions for the action, without
     * actually making the request, and provides an error response. If you have the
     * required permissions, the error response is DryRunOperation.
     * Otherwise, it is UnauthorizedOperation.

     */
    inline bool GetDryRun() const{ return m_dryRun; }

    /**
     *
Checks whether you have the required permissions for the action, without
     * actually making the request, and provides an error response. If you have the
     * required permissions, the error response is DryRunOperation.
     * Otherwise, it is UnauthorizedOperation.

     */
    inline void SetDryRun(bool value) { m_dryRunHasBeenSet = true; m_dryRun = value; }

    /**
     *
Checks whether you have the required permissions for the action, without
     * actually making the request, and provides an error response. If you have the
     * required permissions, the error response is DryRunOperation.
     * Otherwise, it is UnauthorizedOperation.

     */
    inline WithdrawByoipCidrRequest& WithDryRun(bool value) { SetDryRun(value); return *this;}

  private:

    Aws::String m_cidr;
    bool m_cidrHasBeenSet;

    bool m_dryRun;
    bool m_dryRunHasBeenSet;
  };

} // namespace Model
} // namespace EC2
} // namespace Aws


text:
from ..core import Dummy, Expr, Float, PoleError, Rational, nan, oo, sympify
from ..core.function import UndefinedFunction
from ..functions import cos, sign, sin
from ..sets import Reals
from .gruntz import limitinf
from .order import Order

def limit(expr, z, z0, dir=None):
    """
    Compute the directional limit of ``expr`` at the point ``z0``.

    Examples
    ========

    >>> limit(1/x, x, 0)
    oo
    >>> limit(1/x, x, 0, dir=1)
    -oo
    >>> limit(1/x, x, oo)
    0

    See Also
    ========

    Limit

    """
    return Limit(expr, z, z0, dir).doit(deep=False)

def heuristics(e, z, z0, dir):
    e = e.expand()
    if (e.is_Mul or e.is_Add or e.is_Pow or
            (e.is_Function and not e.is_Piecewise and
             not isinstance(e.func, UndefinedFunction))):
        r = []
        for a in e.args:
            l = limit(a, z, z0, dir)
            if (l.has(oo) and (l.func not in (sin, cos) and
                               l.is_finite is None)) or isinstance(l, Limit):
                return
            r.append(l)

        if (rv := e.func(*r)) is not nan:
            return rv

class Limit(Expr):
    r"""
    Represents an unevaluated directional limit of ``expr`` at the point ``z0``.

    Parameters
    ==========

    expr : Expr
        algebraic expression
    z    : Symbol
        variable of the ``expr``
    z0   : Expr
        limit point, `z_0`
    dir  : Expr or Reals, optional
        selects the direction (as ``sign(dir)``) to approach the limit point
        if the ``dir`` is an Expr.  For instance, the limit from the
        right (`z\to z_0 + 0`) if ``dir=-1`` (default).  For infinite ``z0``,
        the default value is determined from the direction of the infinity
        (e.g., ``dir=1`` for ``oo``).  If ``dir=Reals``, the limit is the
        bidirectional real limit.

    Examples
    ========

    >>> Limit(1/x, x, 0, dir=1)
    Limit(1/x, x, 0, dir=1)
    >>> _.doit()
    -oo

    See Also
    ========

    limit

    """

    def __new__(cls, e, z, z0, dir=None):
        e, z, z0, dir = map(sympify, [e, z, z0, dir])

        if z0.is_infinite:
            dir = sign(z0).simplify()
        elif dir is None:
            dir = Rational(-1)

        if dir == Reals:
            pass
        elif isinstance(dir, Expr) and dir.is_nonzero:
            dir = dir/abs(dir)
        else:
            raise ValueError('direction must be either a nonzero expression '
                             f'or Reals, not {dir}')

        obj = super().__new__(cls)
        obj._args = (e, z, z0, dir)
        return obj

    @property
    def free_symbols(self):
        e, z, z0 = self.args[:3]
        return (e.free_symbols - z.free_symbols) | z0.free_symbols

    def doit(self, **hints):
        """
        Evaluates limit.

        Notes
        =====

        First we handle some trivial cases (i.e. constant), then try
        Gruntz algorithm (see the :py:mod:`~diofant.series.gruntz` module).

        """
        e, z, z0, dir = self.args

        if hints.get('deep', True):
            e = e.doit(**hints)
            z = z.doit(**hints)
            z0 = z0.doit(**hints)

        if dir == Reals:
            right = limit(e, z, z0)
            left = limit(e, z, z0, 1)
            if not left.equals(right):
                raise PoleError(f'left and right limits for the expression {e} '
                                f'at point {z}={z0} seems to be not equal')
            return right

        if (has_Floats := e.has(Float) or z0.has(Float)):
            e = e.subs({k: Rational(k) for k in e.atoms(Float)})
            z0 = z0.subs({k: Rational(k) for k in z0.atoms(Float)})

        if z0.has(z):
            newz = z.as_dummy()
            r = limit(e.subs({z: newz}), newz, z0, dir)
            if isinstance(r, Limit):
                r = r.subs({newz: z})
            return r

        # Use a fresh variable to remove assumptions on the dummy variable.
        newz = Dummy('z')
        e, z = e.subs({z: newz}), newz

        if not e.has(z):
            return e

        if e.has(Order) and (order := e.getO()) and (z, z0) in order.args[1:]:
            order = limit(order.expr, z, z0, dir)
            e = e.removeO() + order

        # Convert to the limit z->oo and use Gruntz algorithm.
        e = e.subs({z: dir*z})
        z0 = z0/dir
        if z0 != oo:
            e = e.subs({z: z0 - 1/z})

        # We need a fresh variable with correct assumptions.
        newz = Dummy(z.name, positive=True, finite=True)
        e, z = e.subs({z: newz}), newz

        if e.is_Boolean or e.is_Relational:
            try:
                has_oo = e.as_set().closure.contains(oo)
            except NotImplementedError:
                return self
            if has_oo.is_Boolean:
                return has_oo
            raise NotImplementedError

        try:
            r = limitinf(e, z)
        except (PoleError, ValueError, NotImplementedError):
            r = None
            if hints.get('heuristics', True):
                r = heuristics(*self.args)
            if r is None:
                return self

        if has_Floats:
            r = r.evalf()

        return r


text:
package OpenXPKI::Server::Workflow::Condition::ValidateRuleset;

use strict;
use warnings;
use English;

use base qw( OpenXPKI::Server::Workflow::Condition );

use OpenXPKI::Debug;
use OpenXPKI::Server::Context qw( CTX );
use OpenXPKI::Server::Workflow::Helpers;
use Workflow::Exception qw( condition_error configuration_error );

sub _evaluate
{
    ##! 64: 'start'
    my ( $self, $wf ) = @_;

    my $input = $self->param('input');
    my $ruleset = $self->param('ruleset');

    if (!$ruleset) {
        my $rules_path = OpenXPKI::Server::Workflow::Helpers::get_service_config_path( $self, $self->param('ruleset_name') );
        ##! 32: 'Loading from path ' . join(".",@{$rules_path})
        $ruleset = CTX('config')->get_hash($rules_path);
    }

    ##! 32: $input
    ##! 32: $ruleset
    configuration_error('Ruleset is not a hashref') unless(ref $ruleset eq 'HASH');
    configuration_error('Input is not a hashref') unless(ref $input eq 'HASH');

    my $result = CTX('api2')->validate_ruleset(
        input => $input,
        ruleset => $ruleset,
    );
    ##! 16: $result

    if (@{$result}) {
        my $err = '';
        map { $err .=  $_.': '.($input->{$_} // '?') } @{$result};
        CTX('log')->application()->debug("Ruleset validation failed: $err");
        condition_error("Invalid parameters used: $err");
    }

    ##! 1: 'Validation succeeded'
    CTX('log')->application()->debug("Ruleset validation succeeded");

    return 1;
}

1;

__END__

=head1 NAME

OpenXPKI::Server::Workflow::Condition::ValidateRuleset

=head1 Description

Validate the given parameters against the given ruleset

=head1 Configuration

  is_param_valid:
      class: OpenXPKI::Server::Workflow::Condition::ValidateRuleset
      param:
       _map_input: $csr_key_params
       _map_ruleset:
            digest_alg: sha2

=head2 Arguments

=over

=item input

The input data to validate.

=item ruleset

The ruleset, as expected by validate_ruleset API method.

=back


text:
using namespace DispSvr;
#define PRESENT_INTERVAL	1
#define D3DUSAGE_RESTRICTED_CONTENT              (0x00000800L)

enum  // From D3DHelper.cpp
{
	BACKBUFFER_COUNT_FLIP_MODE = 3,
	BACKBUFFER_COUNT_DEFAULT = 0
};

enum
{
    PCOM_V0 = 0,
    PCOM_V1 = 1,
    PCOM_V2 = 2,
    PCOM_V3 = 3,
};

static inline bool ClientToScreen(PCOM_RECT &PCOMRect, const HWND hwnd, const RECT &dstClip)
{
	int ret;
	POINT pt = {0};
	RECT Rect, WindowRect = {PCOMRect.left, PCOMRect.top, PCOMRect.right, PCOMRect.bottom};

	ret = ::ClientToScreen(hwnd, &pt); ASSERT(ret != 0);
	ret = ::OffsetRect(&WindowRect, pt.x, pt.y); ASSERT(ret != 0);
	IntersectRect(&Rect, &WindowRect, &dstClip);

	if (!IsRectEmpty(&Rect))
	{
		PCOMRect.left = Rect.left;
		PCOMRect.top = Rect.top;
		PCOMRect.right = Rect.right;
		PCOMRect.bottom = Rect.bottom;
		return true;
	}
	return false;	// invisible
}

static inline void NRectToPCOMRect(PCOM_RECT &PCOMRectClear, const NORMALIZEDRECT &NRectClear)
{
	RECT rcClear = {PCOMRectClear.left, PCOMRectClear.top, PCOMRectClear.right, PCOMRectClear.bottom};
	NRectToRect(rcClear, NRectClear);
	PCOMRectClear.left = rcClear.left;
	PCOMRectClear.top = rcClear.top;
	PCOMRectClear.right = rcClear.right;
	PCOMRectClear.bottom = rcClear.bottom;
}

static inline void SelectDisplayField(PCOM_FIELD_SELECT &Field, const VideoProperty &Property)
{
	if (Property.dwFieldSelect == FIELD_SELECT_FIRST)
	{
		Field = (Property.Format == VIDEO_FORMAT_FIELD_INTERLEAVED_EVEN_FIRST) ? PCOM_InterlaceFieldEven : PCOM_InterlaceFieldOdd;
	}
	else if (Property.dwFieldSelect == FIELD_SELECT_SECOND)
	{
		Field = (Property.Format == VIDEO_FORMAT_FIELD_INTERLEAVED_EVEN_FIRST) ? PCOM_InterlaceFieldOdd : PCOM_InterlaceFieldEven;
	}

	if (Property.Format == VIDEO_FORMAT_PROGRESSIVE)
		Field = PCOM_ProgressiveFrame;
}

static DWORD ToStereoVision(DWORD dwAMDStereoMode)
{
    std::map<const DWORD, DWORD> Map;

    Map[PCOM_STEREOSCOPIC_FORMAT_FRAME_SEQUENTIAL]                        = STEREO_VISION_AMD_FRAME_SEQENTIAL;
    Map[PCOM_STEREOSCOPIC_FORMAT_PIXEL_INTERLEAVED_ROW]                   = STEREO_VISION_ROW_INTERLEAVED;
    Map[PCOM_STEREOSCOPIC_FORMAT_PIXEL_INTERLEAVED_COLUMN]                = STEREO_VISION_COLUMN_INTERLEAVED;
    Map[PCOM_STEREOSCOPIC_FORMAT_PIXEL_INTERLEAVED_CHECKERBOARD]          = STEREO_VISION_CHECHERBOARD;
    Map[PCOM_STEREOSCOPIC_FORMAT_VERTICALLY_STACKED_HALF_RESOLUTION]      = STEREO_VISION_HALF_TOP_BOTTOM_LR;  //?
    Map[PCOM_STEREOSCOPIC_FORMAT_HORIZONTAL_SIDE_BY_SIDE_HALF_RESOLUTION] = STEREO_VISION_SIDE_BY_SIDE;  //?
    Map[PCOM_STEREOSCOPIC_FORMAT_HDMI_14]                                 = STEREO_VISION_HDMI_STEREO;
    Map[PCOM_STEREOSCOPIC_FORMAT_DP_12]                                   = STEREO_VISION_DP_STEREO;
    Map[PCOM_STEREOSCOPIC_FORMAT_ANAGLYPH_REDCYAN]                        = STEREO_VISION_ANAGLYPH;

    std::map<const DWORD, DWORD>::iterator iter = Map.find(dwAMDStereoMode);
    if (iter != Map.end())
        return iter->second;
    else
        return NULL;
}

static PCOM_STEREOSCOPIC_FORMAT ToAMDStereoMode(DWORD dwStereoMode)
{
    std::map<const DWORD, PCOM_STEREOSCOPIC_FORMAT> Map;

    Map[MIXER_STEREO_MODE_DISABLED]            = PCOM_STEREOSCOPIC_FORMAT_INVALID;
    Map[MIXER_STEREO_MODE_ANAGLYPH]            = PCOM_STEREOSCOPIC_FORMAT_ANAGLYPH_REDCYAN;  //?
    Map[MIXER_STEREO_MODE_SIDEBYSIDE]          = PCOM_STEREOSCOPIC_FORMAT_HORIZONTAL_SIDE_BY_SIDE_HALF_RESOLUTION; //?
    Map[MIXER_STEREO_MODE_CHECKERBOARD]        = PCOM_STEREOSCOPIC_FORMAT_PIXEL_INTERLEAVED_CHECKERBOARD;
    Map[MIXER_STEREO_MODE_OPTIMIZED_ANAGLYPH]  = PCOM_STEREOSCOPIC_FORMAT_ANAGLYPH_REDCYAN; //?
    Map[MIXER_STEREO_MODE_HALFCOLOR_ANAGLYPH]  = PCOM_STEREOSCOPIC_FORMAT_ANAGLYPH_REDCYAN; //?
    Map[MIXER_STEREO_MODE_ROW_INTERLEAVED]     = PCOM_STEREOSCOPIC_FORMAT_PIXEL_INTERLEAVED_ROW;
    Map[MIXER_STEREO_MODE_HALFCOLOR2_ANAGLYPH] = PCOM_STEREOSCOPIC_FORMAT_ANAGLYPH_REDCYAN; //?
    Map[MIXER_STEREO_MODE_COLUMN_INTERLEAVED]  = PCOM_STEREOSCOPIC_FORMAT_PIXEL_INTERLEAVED_COLUMN;
    Map[MIXER_STEREO_MODE_COLOR_ANAGLYPH]      = PCOM_STEREOSCOPIC_FORMAT_ANAGLYPH_REDCYAN; //?
    Map[MIXER_STEREO_MODE_AMD_ACTIVE_STEREO]   = PCOM_STEREOSCOPIC_FORMAT_FRAME_SEQUENTIAL;
    Map[MIXER_STEREO_MODE_HALF_SIDEBYSIDE_LR]  = PCOM_STEREOSCOPIC_FORMAT_HORIZONTAL_SIDE_BY_SIDE_HALF_RESOLUTION; //?
    Map[MIXER_STEREO_MODE_HALF_SIDEBYSIDE_RL]  = PCOM_STEREOSCOPIC_FORMAT_HORIZONTAL_SIDE_BY_SIDE_HALF_RESOLUTION; //?
    Map[MIXER_STEREO_MODE_HALF_TOPBOTTOM_LR]   = PCOM_STEREOSCOPIC_FORMAT_VERTICALLY_STACKED_HALF_RESOLUTION; //?
    Map[MIXER_STEREO_MODE_HALF_TOPBOTTOM_RL]   = PCOM_STEREOSCOPIC_FORMAT_VERTICALLY_STACKED_HALF_RESOLUTION; //?
    Map[MIXER_STEREO_MODE_HDMI_STEREO]         = PCOM_STEREOSCOPIC_FORMAT_HDMI_14;
    Map[MIXER_STEREO_MODE_DP_STEREO]           = PCOM_STEREOSCOPIC_FORMAT_DP_12;

    std::map<const DWORD, PCOM_STEREOSCOPIC_FORMAT>::iterator iter = Map.find(dwStereoMode);
    if (iter != Map.end())
        return iter->second;
    else
        return PCOM_STEREOSCOPIC_FORMAT_INVALID;
}

CAMDPCOMMixerPresenter::CAMDPCOMMixerPresenter()
{
	m_GUID = DISPSVR_RESOURCE_AMDPCOMVIDEOMIXERPRESENTER;
	m_dwFlipChainSize = 0;
	m_dwQueuedFrameCount = 0;
	m_bFullScreen = false;
	m_pSession = NULL;
	ZeroMemory(&m_XvYCCGamutMetaData, sizeof(XVYCC_GAMUT_METADATA));
	m_dwPCOMClearRecCount = 0;
	ZeroMemory(&m_PCOMClearRecList, sizeof(m_PCOMClearRecList));

	m_bSpatialDeinterlacing = true;
	m_bTemporalDeinterlacing = false;
	m_bAsyncPresent = true;
	// MIXER_CAP_CAN_CHANGE_DESTINATION, MIXER_CAP_3D_RENDERTARGET, MIXER_CAP_VIRTUALIZE_FROM_ORIGIN are not supported.
	m_MixerCaps.dwFlags = 0;
	m_pSwapChain = NULL;
	m_ePresentMode = D3D9_PRESENT_MODE_WINDOWED;
	m_iRenderTargetIndex = 0;
}

CAMDPCOMMixerPresenter::~CAMDPCOMMixerPresenter()
{
}

STDMETHODIMP CAMDPCOMMixerPresenter::QueryInterface(REFIID riid, void **ppv)
{
	HRESULT hr = E_NOINTERFACE;

	if (riid == __uuidof(IDispSvrVideoPresenter))
	{
		hr = GetInterface((IDispSvrVideoPresenter *)this, ppv);
	}
	else
	{
		hr = CD3D9VideoMixerBase::QueryInterface(riid, ppv);
	}
	return hr;
}

STDMETHODIMP CAMDPCOMMixerPresenter::ProcessMessage(RESOURCE_MESSAGE_TYPE eMessage, LPVOID ulParam)
{
	return CD3D9VideoMixerBase::ProcessMessage(eMessage, ulParam);
}

STDMETHODIMP CAMDPCOMMixerPresenter::_QueryPlaneCaps(PLANE_ID PlaneID, PLANE_FORMAT Format, PlaneCaps *pCap)
{
	// PCOM_NV12, PCOM_YUY2, PCOM_ARGB, PCOM_AYUV
	if(Format != PLANE_FORMAT_ARGB && Format != PLANE_FORMAT_YUY2 && Format != PLANE_FORMAT_NV12 && Format != PLANE_FORMAT_AYUV)
		return E_FAIL;

	return S_OK;
}

STDMETHODIMP CAMDPCOMMixerPresenter::SetDisplayRect(const RECT *rcDst, const RECT *rcSrc)
{
	CAutoLock lock(&m_csLock);

	HRESULT hr = E_FAIL;
	hr = CD3D9VideoPresenterBase::SetDisplayRect(rcDst, rcSrc);
	if (FAILED(hr))
		return hr;

	// PCOM will calculate the window position internally.
	// AP only needs to pass destination window size to PCOM.
	POINT pt = {0};
	::ClientToScreen(m_hwnd, &pt);
	::OffsetRect(&m_rcDst, GetRegistry(REG_DISPLAY_X, 0) - pt.x, GetRegistry(REG_DISPLAY_Y, 0) - pt.y);

	m_bFullScreen = CD3D9VideoPresenterBase::IsWindowFullScreen();
	return hr;
}

STDMETHODIMP CAMDPCOMMixerPresenter::Present(const PresentHints *pHints)
{
	CAutoLock lock(&m_csLock);
	// If PCOM queue is not full yet, keep waiting until queue is full.
	if (m_dwQueuedFrameCount < m_dwFlipChainSize)
	{
		DbgMsg("Fill up the display queue!!");
		return S_FALSE;
	}

	if(m_ePresentMode == D3D9_PRESENT_MODE_FLIPEX)
		return PresentEx();
	else
		return PresentPCOM();
}

STDMETHODIMP CAMDPCOMMixerPresenter::Clear()
{
	CAutoLock lock(&m_csLock);
	return ClearPCOM();
}

STDMETHODIMP CAMDPCOMMixerPresenter::SetColorKey(const DWORD dwColorKey)
{
	CAutoLock lock(&m_csLock);

	DWORD dwOldColorKey = m_dwColorKey;
	HRESULT hr = CD3D9VideoPresenterBase::SetColorKey(dwColorKey);
	if (SUCCEEDED(hr) && m_dwColorKey != dwOldColorKey)
	{
		hr = DestroyPCOM();
		hr = CreatePCOM();
	}

	return hr;
}

STDMETHODIMP CAMDPCOMMixerPresenter::SetGamutMetadata(const DWORD dwFormat, void *pGamutMetadata)
{
	if (m_PresenterCaps.bSupportXvYCC)
	{
		m_dwGamutFormat = dwFormat;
		if (m_dwGamutFormat == GAMUT_METADATA_NONE)
		{
			ZeroMemory(&m_GamutRange, sizeof(GamutMetadataRange));
			ZeroMemory(&m_GamutVertices, sizeof(GamutMetadataVertices));
			DbgMsg("AMDPCOM: XvYcc OFF.");
			return S_OK;
		}

		if (m_dwGamutFormat == GAMUT_METADATA_RANGE && memcmp(&m_GamutRange, pGamutMetadata, sizeof(m_GamutRange)) )
		{
			memcpy(&m_GamutRange, pGamutMetadata, sizeof(GamutMetadataRange));
			m_XvYCCGamutMetaData.size = sizeof(m_XvYCCGamutMetaData);
			m_XvYCCGamutMetaData.Format_Flag = m_GamutRange.Format_Flag;
			m_XvYCCGamutMetaData.GBD_Color_Precision = m_GamutRange.GBD_Color_Precision;
			m_XvYCCGamutMetaData.GBD_Color_Space = m_GamutRange.GBD_Color_Space;
			m_XvYCCGamutMetaData.Max_Red_Data = m_GamutRange.Max_Red_Data;
			m_XvYCCGamutMetaData.Min_Red_Data = m_GamutRange.Min_Red_Data;
			m_XvYCCGamutMetaData.Max_Green_Data = m_GamutRange.Max_Green_Data;
			m_XvYCCGamutMetaData.Min_Green_Data = m_GamutRange.Min_Green_Data;
			m_XvYCCGamutMetaData.Max_Blue_Data = m_GamutRange.Max_Blue_Data;
			m_XvYCCGamutMetaData.Min_Blue_Data = m_GamutRange.Min_Blue_Data;
			DbgMsg("AMDPCOM: XvYcc ON.");
			return S_OK;
		}
	}
    else
    {
        DbgMsg("AMDPCOM: No XvYcc supports.");
    }

	return E_NOTIMPL;
}

STDMETHODIMP CAMDPCOMMixerPresenter::SetScreenCaptureDefense(BOOL bEnable)
{
    CAutoLock lock(&m_csLock);

    if (m_PresenterCaps.bIsOverlay || (m_ePresentMode == D3D9_PRESENT_MODE_FLIPEX))
        return S_OK;
    else
        return E_NOTIMPL;
}

STDMETHODIMP CAMDPCOMMixerPresenter::_SetDevice(IUnknown *pDevice)
{
	CAutoLock lock(&m_csLock);
	HRESULT hr = E_FAIL;

	hr = CD3D9VideoMixerBase::_SetDevice(pDevice);
	if (FAILED(hr))
		return hr;

	hr = CD3D9VideoPresenterBase::_SetDevice(pDevice);

	m_pDevice->GetSwapChain(0, &m_pSwapChain);
	m_ePresentMode = D3D9_PRESENT_MODE_WINDOWED;

	if (m_pSwapChain)
	{
		D3DPRESENT_PARAMETERS sPresentParam;
		hr = m_pSwapChain->GetPresentParameters(&sPresentParam);
		if(SUCCEEDED(hr))
		{
			if (sPresentParam.Windowed == FALSE)
				m_ePresentMode = D3D9_PRESENT_MODE_FULLSCREEN;
			else if (sPresentParam.SwapEffect == D3DSWAPEFFECT_FLIPEX)
				m_ePresentMode = D3D9_PRESENT_MODE_FLIPEX;
			// Get the video hwnd for PCOM
			CD3D9PluginBase::_SetWindow(sPresentParam.hDeviceWindow);
		}
	}

	DbgMsg("PCOM value = %d", m_ePresentMode);

	if (SUCCEEDED(hr))
	{
		DestroyPCOM();
		// Create PCOM related resource with D3D device
		hr = CreatePCOM();
		if (SUCCEEDED(hr))
		{
			hr = InsertPCOMVP();
		}
	}

	return hr;
}

STDMETHODIMP CAMDPCOMMixerPresenter::_ReleaseDevice()
{
	CAutoLock lock(&m_csLock);
	HRESULT hr;

	DestroyPCOM();

	SAFE_RELEASE(m_pSwapChain);
	hr = CD3D9VideoMixerBase::_ReleaseDevice();
	hr |= CD3D9VideoPresenterBase::_ReleaseDevice();
	return hr;
}

HRESULT CAMDPCOMMixerPresenter::_Execute(IDirect3DSurface9 *pDestSurface, const RECT &, const RECT &rcDstClip)
{
	CAutoLock lock(&m_csLock);
	HRESULT hr = E_FAIL;
	RECT rcDst(m_rcDst); // The rect of destination.

    NRectToRect(rcDst, m_pModel->GetDestination());
	if (rcDst.top > rcDst.bottom || rcDst.left > rcDst.right)
		return E_FAIL;

	PCOM_EXECUTE_INPUT ExecuteIn = {0};
	ExecuteIn.size = sizeof(PCOM_EXECUTE_INPUT);
	ExecuteIn.planeCount = 0;

    //Each plane should refer to the their own mixing area's aspect ratio, not whole mixing area(Window)
    // mixing area's aspect ratio = (window(whole mixing area) width * viewport's normalized width) /
    //                                             (window(whole mixing area) height * viewport's normalized height)
    float fMixingAreaAspectRatio[PLANE_MAX];
    for (int i = 0; i < DispSvr::PLANE_MAX; i++)
    {
        fMixingAreaAspectRatio[i] = m_fWindowAspectRatio;
        const D3D9Plane &plane = m_pModel->GetPlane(i);

        if (plane.bValid)
            fMixingAreaAspectRatio[i] = m_fWindowAspectRatio * (plane.nrcDst.right - plane.nrcDst.left) / (plane.nrcDst.bottom - plane.nrcDst.top);
    }

	// PCOM clear rectangle will apply current and below layers except main video & background.
	// So we can only apply clear rectangle to SubVidoe & SPIC layer.
	// We need to check HDi layer in order to pass clear rectangle & coordinates to SubVideo & SPIC layer,
    const ClearRectList &ClearRectList = m_pModel->GetClearRectangles();
	if (ClearRectList.size() > 0 && ClearRectList.size() <= PCOM_MAX_CLEAR_RECTANGLES_COUNT)
	{
        const D3D9Plane &plane = m_pModel->GetPlane(PLANE_INTERACTIVE);
		ASSERT(plane.bValid == true);
		m_dwPCOMClearRecCount = 0;
		PCOM_RECT srcRect, dstRect;
		RECT rcSrc = plane.rcSrc;
		CalculatePCOMRect(0, srcRect, dstRect, plane, rcSrc, rcDst, rcDstClip, fMixingAreaAspectRatio[PLANE_INTERACTIVE]);

		PCOM_CLEAR_RECTANGLE *pCR = m_PCOMClearRecList;
		for (ClearRectList::const_iterator it = ClearRectList.begin(); it != ClearRectList.end(); ++it)
		{
			pCR->type = (it->Target == CLEAR_RECT_TARGET_MAIN) ? PCOM_MainVideo_ClearRect : PCOM_SubVideo_ClearRect;
			pCR->clearRect = dstRect;
			NRectToPCOMRect(pCR->clearRect, it->Rect);
			// The coordinates of PCOM clear rectangle Rect is opposite to desktop, not client window.
			if (ClientToScreen(pCR->clearRect, m_hwnd, rcDstClip))
			{
				++m_dwPCOMClearRecCount;
				++pCR;
			}
		}
	}

	for (int i = 0; i < DispSvr::PLANE_MAX; i++)
	{
		hr = PlaneToPCOMPlane(i, &ExecuteIn, rcDst, rcDstClip, fMixingAreaAspectRatio[i]);
		if (hr == S_OK)
			ExecuteIn.planeCount++;
	}

	if (ExecuteIn.planeCount)
	{
		// rect of destination(rcDst) should be equal to screen size in full screen mode,
		// or unexpected color would shown outside the PCOM planes.
		if(m_bFullScreen)
			SetRect(&rcDst, 0, 0, m_szSrc.cx, m_szSrc.cy);

		hr = BeginFramePCOM(rcDst);
		if (SUCCEEDED(hr))
		{
			hr = ExecutePCOM(&ExecuteIn); ASSERT(SUCCEEDED(hr));
			hr = EndFramePCOM(); ASSERT(SUCCEEDED(hr));
		}
	}

	return hr;
}

HRESULT CAMDPCOMMixerPresenter::SetProperty(const MixerProperty *pProperty)
{
    CAutoLock lock(&m_csLock);
    HRESULT hr = E_FAIL;
    MixerProperty OriProperty;

    hr = CD3D9VideoMixerBase::GetProperty(&OriProperty);
    hr = CD3D9VideoMixerBase::SetProperty(pProperty);
    if((OriProperty.bStereoEnable != pProperty->bStereoEnable) ||
        ((OriProperty.eStereoMode != pProperty->eStereoMode) && pProperty->bStereoEnable))  //Enable Stereo mode or Change Stereo mode
    {
        hr = DestroyPCOM();
        hr = CreatePCOM();
    }
    return hr;
}

HRESULT CAMDPCOMMixerPresenter::CreatePCOM()
{
	PCOM_STATUS ret = PCOM_OK;
	HRESULT hr = E_FAIL;
	PCOM_GET_CAPS_INPUT GetCapsIn = {0};
	PCOM_GET_CAPS_OUTPUT GetCapsOut = {0};

	GetCapsOut.size = sizeof(PCOM_GET_CAPS_OUTPUT);
	GetCapsIn.size = sizeof(PCOM_GET_CAPS_INPUT);
	GetCapsIn.GfxDevice = m_pDevice;

	ret = PCOMGetCaps(&GetCapsIn, &GetCapsOut);

	unsigned int uVersionMajor = GetCapsOut.revision >> 16;
	unsigned int uVersionMinor = GetCapsOut.revision & 0x00000001;

	if((m_ePresentMode == D3D9_PRESENT_MODE_FLIPEX) && (!GetCapsOut.flags.supportAppTargets || !m_pDeviceEx))
	{
		DbgMsg("PCOM Driver does not support PCOM DWM");
		return E_FAIL;
	}

	DWORD dwBBWidth = GetRegistry(REG_BACKBUFFER_WIDTH, 0);
	DWORD dwBBHeight = GetRegistry(REG_BACKBUFFER_HEIGHT, 0);

	PCOM_CREATE_INPUT CreateIn = {0};
	PCOM_CREATE_OUTPUT CreateOut = {0};

	CreateOut.size = sizeof(PCOM_CREATE_OUTPUT);
	CreateIn.size = sizeof(PCOM_CREATE_INPUT);

	CreateIn.flags.value = 0;

	if(m_ePresentMode == D3D9_PRESENT_MODE_FLIPEX)
    {
		CreateIn.flags.useOnlyAppTargets = 1;
    }
	else
	{
		CreateIn.flags.useOverlayPresent = 1;
		CreateIn.flags.useAsyncPresent = (m_bAsyncPresent) ? 1 : 0;
	}

	CreateIn.overlayColorKey = m_dwColorKey;
	CreateIn.mainVideoWidth = dwBBWidth;
	CreateIn.mainVideoHeight = dwBBHeight;
	CreateIn.windowHandle = m_hwnd;
	CreateIn.GfxDevice = m_pDevice;

    // For PCOMv3
    MIXER_STEREO_MODE eStereoMode = (MIXER_STEREO_MODE) GetRegInt(TEXT("StereoMixerMode"), GetMixerStereoMode());
    CreateIn.stereoscopicFormat = ToAMDStereoMode(eStereoMode);
    CreateIn.flags.useStereoscopicMode = (m_Property.bStereoEnable) ? 1 : 0;
    // Could not create PCOM with stereo mode if the stereoscopic format is invalid.
    if(PCOM_STEREOSCOPIC_FORMAT_INVALID == CreateIn.stereoscopicFormat)
        CreateIn.flags.useStereoscopicMode = 0;
    DbgMsg("Enable Stereo mode = %d, Stereo mode is %d,", CreateIn.flags.useStereoscopicMode, CreateIn.stereoscopicFormat);

	ret = PCOMCreate(&CreateIn, &CreateOut);

	if (ret != PCOM_OK)
	{
        ASSERT(0);
        DbgMsg("PCOMCreate return value: 0x%08X", ret);
        return E_FAIL;
	}
    else
    {
        DbgMsg("Creating PCOM OK!");
    }

	m_pSession = CreateOut.PCOMSession;
	// Update presenter caps
	m_PresenterCaps.dwFPS = GetCapsOut.recomFps;
	m_PresenterCaps.dwResPixels = GetCapsOut.recomWindowPixelCnt;
	m_PresenterCaps.dwBandWidth = GetCapsOut.systemToVideoBandwidth;
	m_PresenterCaps.bSupportXvYCC = (GetCapsOut.flags.supportXvYCCWideGamutDisplay) ? TRUE : FALSE;
	m_PresenterCaps.bIsOverlay = (m_ePresentMode == D3D9_PRESENT_MODE_FLIPEX) ? FALSE : TRUE;
	m_bSpatialDeinterlacing = (GetCapsOut.flags.supportSpatialDeinterlacing) ? true : false;
	m_bTemporalDeinterlacing = (GetCapsOut.flags.supportTemporalDeinterlacing) ? true : false;
	//if(uVersionMajor < PCOM_V2 || (uVersionMajor == PCOM_V2 && uVersionMinor == 0))  //Could not use TemporalDeinterlacing if the version of PCOM is under 2.1
    // Turn off PCOMv2 first because bug#111341, we have to report it to AMD.
	m_bTemporalDeinterlacing = false;

	if(m_ePresentMode == D3D9_PRESENT_MODE_FLIPEX)
    {
		m_PresenterCaps.dwPresenterInfo = (PRESENTER_FLIPEX | PRESENTER_D3D);
        m_dwFlipChainSize = BACKBUFFER_COUNT_FLIP_MODE;
    }
    else
    {
		m_PresenterCaps.dwPresenterInfo = PRESENTER_PROPRIETARYOVERLAY;
        m_dwFlipChainSize = static_cast<DWORD>(CreateOut.flipChainSize);
    }

	return S_OK;
}

HRESULT CAMDPCOMMixerPresenter::DestroyPCOM()
{
	if (m_pSession)
	{
		PCOM_STATUS ret = PCOM_OK;
		ret = PCOMDestroy(m_pSession);
		ASSERT(ret == PCOM_OK);
		m_pSession = NULL;
	}

	m_dwFlipChainSize = 0;
	m_dwQueuedFrameCount = 0;
	return S_OK;
}

HRESULT CAMDPCOMMixerPresenter::InsertPCOMVP()
{
	m_PlaneConfigs[PLANE_GRAPHICS].eTextureUsage	= TEXTURE_USAGE_LOCKABLE_BACKSTORE;
	m_PlaneConfigs[PLANE_INTERACTIVE].eTextureUsage = TEXTURE_USAGE_LOCKABLE_BACKSTORE;

	m_pTexturePool->SetPoolUsage(TEXTURE_POOL_USAGE_OFFSCREENPLANESURFACE);
	GenerateDxva2VPList();

	// Bug#83555, remove PCOM from preferred mixer selection because PCOM 1.0 only support BOB deinterlace.
	// 1 possible risk is that if the machine don't support both PCOM v2 and DXVA VP,
	// there will no video processer for de-interlace.
	if(m_bTemporalDeinterlacing)
	{
		VideoProcessorStub vp = {0};
		vp.guidVP = DispSvr_VideoProcPCOM;
		vp.RenderTargetFormat = D3DFMT_X8R8G8B8;
		vp.sCaps.eType = PROCESSOR_TYPE_HARDWARE;
		vp.sCaps.uProcessorCaps = PROCESSOR_CAPS_DEINTERLACE_ADAPTIVE;

		for(VideoProcessorList::iterator vi = m_VideoProcessorList.begin(); vi != m_VideoProcessorList.end(); ++vi)
		{
			if (vi->pfnVBltFactory)
			{
				vp.pDelegateVPStub = &*vi;
				break;
			}
		}

		m_VideoProcessorList.push_back(vp);
		DbgMsg("Creating PCOM VP OK - PCOM temporal");
	}
	else
	{
		DbgMsg("Creating PCOM with DXVA2 VP OK");
	}
	SelectVideoProcessor();
	return S_OK;
}

HRESULT CAMDPCOMMixerPresenter::BeginFramePCOM(const RECT &rcDst)
{
	PCOM_STATUS ret = PCOM_OK;
	PCOM_BEGIN_FRAME_INPUT BeginFrameIn = {0};
	HRESULT hr = E_FAIL;
	BeginFrameIn.size = sizeof(PCOM_BEGIN_FRAME_INPUT);
	BeginFrameIn.flags.enableFullScreenMode = (m_bFullScreen) ? 1 : 0;
	BeginFrameIn.flags.enableXvYCCMetaData = (m_dwGamutFormat == GAMUT_METADATA_RANGE) ? 1 : 0;
	BeginFrameIn.targetRect.left = rcDst.left;
	BeginFrameIn.targetRect.top = rcDst.top;
	BeginFrameIn.targetRect.right = rcDst.right;
	BeginFrameIn.targetRect.bottom = rcDst.bottom;
	BeginFrameIn.xvYCCMetaData = (m_dwGamutFormat == GAMUT_METADATA_RANGE) ? &m_XvYCCGamutMetaData : 0;
    BeginFrameIn.flags.outputLeftView = 1;
    BeginFrameIn.flags.outputRightView = (m_Property.bStereoEnable) ? 1 : 0;

	if (m_ePresentMode == D3D9_PRESENT_MODE_FLIPEX)
	{
		CComPtr<IDirect3DSurface9> pBackBuffer;

		hr = m_pDeviceEx->GetRenderTarget(0, &pBackBuffer);
		BeginFrameIn.targetSurface = pBackBuffer;
        BeginFrameIn.flags.enableFullScreenMode = 0; //Using PCOM for DWM, we have to set this flag as 0.
		if(m_iRenderTargetIndex < (m_dwFlipChainSize-1))
			m_iRenderTargetIndex++;

		while(1)
		{
			if(m_dwQueuedFrameCount == m_dwFlipChainSize)
			{
				hr = PresentEx();
			}
			ret = PCOMBeginFrame(m_pSession, &BeginFrameIn);
			break;
		};
	}
	else
	{
		while(1)
		{
			ret = PCOMBeginFrame(m_pSession, &BeginFrameIn);
			if (ret == PCOM_QUEUE_FULL)
			{
				hr = PresentPCOM();
				if (SUCCEEDED(hr))
					continue;
			}
			break;
		};
	}

	return (ret == PCOM_OK) ? S_OK : E_FAIL;
}

HRESULT CAMDPCOMMixerPresenter::ExecutePCOM(PPCOM_EXECUTE_INPUT pExecuteIn)
{
	HRESULT hr = S_OK;
	if (pExecuteIn->planeCount > 0)
	{
		PCOM_STATUS ret = PCOMExecute(m_pSession, pExecuteIn);
		// QueuedFrameCound should increase by 1 if PCOMExecute successfully.
		if (ret == PCOM_OK)
		{
			m_dwQueuedFrameCount++;
		}
		else
		{
			// If assert happens with DXVA2 enabled, it could causes AP hang.
			ASSERT(0);
			hr = E_FAIL;
		}
	}

	return hr;
}

HRESULT CAMDPCOMMixerPresenter::EndFramePCOM()
{
	PCOM_STATUS ret = PCOM_OK;
	PCOM_END_FRAME_INPUT EndFrameIn = {0};
	EndFrameIn.size = sizeof(PCOM_END_FRAME_INPUT);
	EndFrameIn.flags.value = 0;

	ret = PCOMEndFrame(m_pSession, &EndFrameIn);
	return (ret == PCOM_OK) ? S_OK : E_FAIL;
}

HRESULT CAMDPCOMMixerPresenter::PresentPCOM()
{
	HRESULT hr = E_FAIL;
	PCOM_STATUS ret = PCOM_OK;
	PCOM_PRESENT_OUTPUT PresentOut = {0};
	PresentOut.size = sizeof(PCOM_PRESENT_OUTPUT);

	while(1)
	{
		ret = PCOMPresent(m_pSession, &PresentOut);
		if (ret != PCOM_OK)
		{
			DbgMsg("PCOMPresent is failed due to error: 0x%08X", ret);
			if (m_bAsyncPresent && (ret==PCOM_FLIP_PENDING || ret==PCOM_COMP_NOT_READY))
			{
				Sleep(PRESENT_INTERVAL);
				continue;
			}
		}
		break;
	}

	// m_dwQueuedFrameCount should be decreased by 1 after PCOMPresent.
	if (ret == PCOM_OK)
	{
		m_dwQueuedFrameCount = PresentOut.numOfQueuedUpFrames;
		hr = S_OK;
	}

	return hr;
}

HRESULT CAMDPCOMMixerPresenter::PresentEx()
{
	HRESULT hr = E_FAIL;

	if(0)
	{
#ifndef _NO_USE_D3DXDLL
		CComPtr<IDirect3DSwapChain9> pSwapChain;
		CComPtr<IDirect3DSurface9> pBackBuffer2;

		hr = m_pDeviceEx->GetSwapChain(0, &pSwapChain);
		hr = m_pDeviceEx->GetBackBuffer(0, m_iRenderTargetIndex, D3DBACKBUFFER_TYPE_MONO, &pBackBuffer2);
		hr = D3DXSaveSurfaceToFile(_T("C:\\doSurface.bmp"), D3DXIFF_BMP, pBackBuffer2, NULL, NULL);
#endif
	}

	while ((hr = m_pSwapChain->Present(NULL, NULL, NULL, NULL, D3DPRESENT_DONOTWAIT)) == D3DERR_WASSTILLDRAWING)
		Sleep(PRESENT_INTERVAL);

	m_dwQueuedFrameCount--;

	return hr;
}

HRESULT CAMDPCOMMixerPresenter::ClearPCOM()
{
	HRESULT hr = E_FAIL;
	PCOM_STATUS ret = PCOM_OK;

	if(m_ePresentMode == D3D9_PRESENT_MODE_WINDOWED)
	{
		ret = PCOMResetQueue(m_pSession);
		if (ret == PCOM_OK)
		{
			m_dwQueuedFrameCount = 0;
		}
	}
	else
	{
		m_dwQueuedFrameCount = 0;
		m_iRenderTargetIndex = 0;
	}
	return hr;
}

HRESULT CAMDPCOMMixerPresenter::CalculatePCOMRect(UINT uViewID, PCOM_RECT &pcomrcSrc, PCOM_RECT &pcomrcDst, const D3D9Plane &plane, RECT &rcSrc, const RECT &rcMixingDst, const RECT &rcDstClip, float fWindowAspectRatio)
{
    NORMALIZEDRECT nrcOutput = plane.nrcDst;
    RECT rcDst = rcMixingDst;

    CorrectAspectRatio(nrcOutput, plane.fAspectRatio / fWindowAspectRatio);
    // cropping applies to both source and destination.
    CropRect(nrcOutput, plane.nrcCrop);
    CropRect(rcSrc, plane.nrcCrop);
    // Calculate the offset of Base view and depend view.
    INT iOffset = GetStereoOffset(plane);
    if (iOffset != 0 && plane.uWidth != 0)
    {
        float fNormalizedOffset = float(iOffset) / plane.uWidth;
        if (uViewID == 0)	// base view shifts right if offset is positive.
        {
            nrcOutput.left += fNormalizedOffset;
            nrcOutput.right += fNormalizedOffset;
        }
        else if (uViewID == 1)	// depend view shifts left if offset is positive.
        {
            nrcOutput.left -= fNormalizedOffset;
            nrcOutput.right -= fNormalizedOffset;
        }
    }
    // map normailzed destination rectangle to actual rectangle in pixel.
    NRectToRect(rcDst, nrcOutput);
    // check and clip source/destination rectangles when rcDst is outside of rcDstClip.
    ClipRect(rcDst, rcSrc, rcDstClip);

    pcomrcSrc.left = rcSrc.left;
    pcomrcSrc.top = rcSrc.top;
    pcomrcSrc.right = rcSrc.right;
    pcomrcSrc.bottom = rcSrc.bottom;

    pcomrcDst.left = rcDst.left;
    pcomrcDst.top  = rcDst.top;
    pcomrcDst.right = rcDst.right;
    pcomrcDst.bottom = rcDst.bottom;

    return S_OK;
}

HRESULT CAMDPCOMMixerPresenter::PlaneToPCOMPlane(PLANE_ID id, PPCOM_EXECUTE_INPUT pExecuteIn, RECT &rcDst, const RECT &rcDstClip, const float fWindowAspectRatio)
{
	D3D9Plane &plane = m_pModel->GetPlane(id);
	CComPtr<IDirect3DSurface9> pSurface;

	HRESULT hr = E_FAIL;

	// According to AMD's suggestion, PCOM must set background color if there's null plane or only 1 graphic plane.
	// So we bypass the background plane even it's not a used.
    if (!plane.IsValid() && id != PLANE_BACKGROUND)
		return S_FALSE;

    UINT uView = 0;
    hr = m_pTexturePool->GetRepresentation(plane.GetViewTextureHandle(uView), __uuidof(IDirect3DSurface9), (void **)&pSurface);
	if (0)
	{
#ifndef _NO_USE_D3DXDLL
		hr = D3DXSaveSurfaceToFile(_T("C:\\do.bmp"), D3DXIFF_BMP, pSurface, NULL, NULL);

		CComPtr<IDirect3DTexture9> pTexturePriv;
		CComPtr<IDirect3DSurface9> pTexturePrivSurf;
		hr = m_pDevice->CreateTexture(1920, 1080, 1, D3DUSAGE_RENDERTARGET, D3DFMT_X8R8G8B8, D3DPOOL_DEFAULT, &pTexturePriv, NULL);
		hr = pTexturePriv->GetSurfaceLevel(0, &pTexturePrivSurf);
		hr = m_pDevice->StretchRect(pSurface, NULL, pTexturePrivSurf, NULL, D3DTEXF_POINT);
		hr = D3DXSaveSurfaceToFile(_T("C:\\reRT.bmp"), D3DXIFF_BMP, pTexturePrivSurf, NULL, NULL);
#endif
	}

	if ((!pSurface || id > 5) && id != PLANE_BACKGROUND)
		return E_FAIL;

	RECT rcSrc = plane.rcSrc;
	PCOM_VALID_PLANE_FIELDS ValidPlaneFields = {0};
	//If there don't have Surface, set ValidPlaneFields.hasPlanarAlpha = 0. Because there is nothing to render.
	ValidPlaneFields.hasPlanarAlpha = (pSurface && plane.fAlpha != 1.0f) ? 1 : 0;
	ValidPlaneFields.hasLumaKey = 0;
	ValidPlaneFields.hasBackgroundColor = 0;
	ValidPlaneFields.hasClearRectangles = 0;
	ValidPlaneFields.hasDirtyRect = 0;
	ValidPlaneFields.hasFps = 1;
	ValidPlaneFields.hasCsc = 0;

    PCOM_PLANE PCOMPlane = {0};
	PCOMPlane.size = sizeof(PCOM_PLANE);
	PCOMPlane.planeType = PCOM_Generic_Plane;
	PCOMPlane.fieldSelect = PCOM_ProgressiveFrame;
	PCOMPlane.flags.value = 0;
	PCOMPlane.alpha = (unsigned int)(plane.fAlpha * 255.0f);
	PCOMPlane.clearRectCount = 0;

	// It's dangerous to use main video frame rate as reference always.
	PCOMPlane.fps = (float)m_pModel->GetPlane(PLANE_MAINVIDEO).VideoProperty.dwFrameRate1000 / 1000;
	PCOMPlane.plane = pSurface;

	if (id == PLANE_BACKGROUND)
	{
		//If there has nothing to render, set ValidPlaneFields.hasBackgroundColor = 1. Default of value is 0.
		if(!pSurface || !IsBackgroundVisible())
		{
			// Set default value to normalized RECT before CalculatePCOMRect()
            plane.nrcDst = plane.nrcCrop = m_pModel->GetDestination();

			ValidPlaneFields.hasBackgroundColor = 1;
            COLORREF bkgColor = 0;
            m_pModel->GetBackgroundColor(&bkgColor);

            PCOMPlane.backgroundColor = bkgColor;
			PCOMPlane.plane = 0;
		}
		else
		{
			PCOMPlane.fps = 1.0f;
		}
	}
	else if (id == PLANE_MAINVIDEO)
	{
        CComPtr<IDirect3DTexture9> pTexture;
        CComPtr<IUnknown> pUnk;

        if (ProcessVideoEffect(PLANE_MAINVIDEO, NULL, rcSrc,rcDst, plane.Format, &pUnk) != S_FALSE)
        {
            if (pUnk)
            {
                pSurface.Release();
                hr = pUnk->QueryInterface(IID_IDirect3DTexture9, (void **)&pTexture);
                if (SUCCEEDED(hr))
                {
                    hr = pTexture->GetSurfaceLevel(0, &pSurface);	ASSERT(SUCCEEDED(hr));
#ifndef _NO_USE_D3DXDLL
                    if (0)
                    {
                        hr = D3DXSaveTextureToFile(_T("C:\\doTexture.bmp"), D3DXIFF_BMP, pTexture, NULL);
                    }
#endif
                }
                else
                {
                    hr = pUnk->QueryInterface(IID_IDirect3DSurface9, (void **)&pSurface);
#ifndef _NO_USE_D3DXDLL
                    if (0)
                    {
                        hr = D3DXSaveSurfaceToFile(_T("C:\\doSurface.bmp"), D3DXIFF_BMP, pSurface, NULL, NULL);
                    }
#endif
                }
                PCOMPlane.plane = pSurface;
            }
        }
        else if (m_pVideoEffect3DBlt && m_pVideoEffect3DBlt->IsEffectEnabled())
        {
            hr = m_pTexturePool->GetRepresentation(plane.hTexture, __uuidof(IDirect3DTexture9), (void **)&pTexture);

            if (FAILED(hr))
            {
                hr = plane.pVBlt->IntermediateTextureVBlt(pSurface, rcSrc, &pTexture);
            }

            if (SUCCEEDED(hr))
            {
                CComPtr<IUnknown> pOutputSurface;
                ProcessEffectRequest Request = {0};
                Request.lpSourceRect = &rcSrc;
                Request.lpTargetRect = &rcDst;
                Request.pVideoProperty = &plane.VideoProperty;
                Request.pInput = pTexture;
                Request.ppOutput = &pOutputSurface;
                hr = m_pVideoEffect3DBlt->ProcessEffect(&Request);
                if (SUCCEEDED(hr))
                {
                    pTexture.Release();
                    hr = pOutputSurface->QueryInterface(IID_IDirect3DTexture9, (void **)&pTexture);
                    if (SUCCEEDED(hr))
                    {
                        pSurface.Release();
                        hr = pTexture->GetSurfaceLevel(0, &pSurface);	ASSERT(SUCCEEDED(hr));
                        PCOMPlane.plane = pSurface;
                    }
                }
            }
        }
    	else if (plane.Format != PLANE_FORMAT_ARGB)
		{
			PCOMPlane.planeType = PCOM_MainVideo_Plane;
			ValidPlaneFields.hasCsc = 1;
			ValidPlaneFields.hasStreamID = 1;
			PCOMPlane.streamID = PLANE_MAINVIDEO;

			PCOMPlane.csc.cscRange = PCOM_CSC_Nominal_Range_0_255;
			PCOMPlane.csc.cscMatrix = plane.bHDVideo ? PCOM_CSC_Matrix_BT709 : PCOM_CSC_Matrix_BT601;

			// if temporally de-interlaced, PCOMPlane.fieldSelect sets to PCOM_ProgressiveFrame.
			if (!m_bTemporalDeinterlacing && !m_bSpatialDeinterlacing && plane.pVBlt && plane.VideoProperty.Format != VIDEO_FORMAT_PROGRESSIVE)
			{
				CComPtr<IDirect3DSurface9> pIntermediateSurface;
				const RECT rcSrc = {0, 0, plane.uWidth, plane.uHeight};

                // we should remove this once GPI can set correct flags.
                if(GetRegistry(REG_OS_VERSION, 0) >= OS_WIN7) // We have to creating this surface with D3DUSAGE_RESTRICTED_CONTENT when using PreventRead on GPUCP
                    plane.VideoProperty.bRestrictedContent = TRUE;
				if (SUCCEEDED(plane.pVBlt->IntermediateVBlt(pSurface, rcSrc, plane.Format, &pIntermediateSurface)))
					PCOMPlane.plane = pIntermediateSurface;	// use the intermediate result for PCOM input.
			}
			else
			{
				// use PCOM de-interlacer
				SelectDisplayField(PCOMPlane.fieldSelect, plane.VideoProperty);
				if(m_bTemporalDeinterlacing)
				{
					ValidPlaneFields.hasTimestamp = 1;
                    PCOMPlane.startTimestamp = plane.VideoProperty.rtStart;
                    PCOMPlane.endTimestamp = plane.VideoProperty.rtEnd;
				}
			}
		}
	}
	else if (id == PLANE_SUBVIDEO)
	{
		PCOMPlane.planeType = PCOM_SubVideo_Plane;
		SelectDisplayField(PCOMPlane.fieldSelect, plane.VideoProperty);

        LumaKey lumaKey = {0};
        m_pModel->GetLumaKey(&lumaKey);
		if (lumaKey.bEnable)
		{
			ValidPlaneFields.hasLumaKey = 1;
			PCOMPlane.minLumaKey = lumaKey.uLower;
			PCOMPlane.maxLumaKey = lumaKey.uUpper;
		}

		PCOMPlane.fps = (float)m_pModel->GetPlane(PLANE_SUBVIDEO).VideoProperty.dwFrameRate1000 / 1000;

		ValidPlaneFields.hasCsc = 1;
		PCOMPlane.csc.cscRange = PCOM_CSC_Nominal_Range_0_255;
		PCOMPlane.csc.cscMatrix = plane.bHDVideo ? PCOM_CSC_Matrix_BT709 : PCOM_CSC_Matrix_BT601;
		ValidPlaneFields.hasStreamID = 1;
		PCOMPlane.streamID = PLANE_SUBVIDEO;

		if(m_bTemporalDeinterlacing)
		{
			ValidPlaneFields.hasTimestamp = 1;
			PCOMPlane.startTimestamp = plane.VideoProperty.rtStart;
			PCOMPlane.endTimestamp = plane.VideoProperty.rtEnd;
		}
	}

    if (!m_pModel->GetClearRectangles().empty())
	{
		if (id == PLANE_SUBVIDEO || id == PLANE_GRAPHICS)
		{
			// Maybe it's needed to clear the array here.
			//ZeroMemory(&PCOMPlane.clearRectList, sizeof(PCOM_CLEAR_RECTANGLE)*PCOM_MAX_CLEAR_RECTANGLES_COUNT);
			PCOMPlane.clearRectCount = m_dwPCOMClearRecCount;
			memcpy(&PCOMPlane.clearRectList, m_PCOMClearRecList, sizeof(PCOM_CLEAR_RECTANGLE)*m_dwPCOMClearRecCount);
			ValidPlaneFields.hasClearRectangles = PCOMPlane.clearRectCount > 0;
		}
	}

    PCOMPlane.validFields = ValidPlaneFields;

    for(uView = 0; uView < 2; uView++)
    {
        // If the plane is created for XGUI, the rect of destination should be equal to screen size(m_rcDst) in full screen mode.
        if (plane.bFullScreenMixing && m_bFullScreen)
            CalculatePCOMRect(uView, PCOMPlane.srcRect, PCOMPlane.dstRect, plane, rcSrc, m_rcDst, rcDstClip, fWindowAspectRatio);
        else if(m_bFullScreen || m_ePresentMode != D3D9_PRESENT_MODE_FLIPEX)
            CalculatePCOMRect(uView, PCOMPlane.srcRect, PCOMPlane.dstRect, plane, rcSrc, rcDst, rcDstClip, fWindowAspectRatio);
        else
        {
            rcDst.top = rcDstClip.top;
            rcDst.left = rcDstClip.left;
            rcDst.right = rcDstClip.right;
            rcDst.bottom = rcDstClip.bottom;

            CalculatePCOMRect(uView, PCOMPlane.srcRect, PCOMPlane.dstRect, plane, rcSrc, rcDst, rcDstClip, fWindowAspectRatio);
        }

        if(uView == 0)
        {
            pExecuteIn->planeList[pExecuteIn->planeCount] = PCOMPlane;
        }
        else  //if(uView == 1); if(m_Property.bStereoEnable), Enable Stereo Video playback
        {
            CComPtr<IDirect3DSurface9> pDependSurface;
            if(SUCCEEDED(m_pTexturePool->GetRepresentation(plane.GetViewTextureHandle(uView), __uuidof(IDirect3DSurface9), (void **)&pDependSurface)))
                PCOMPlane.plane = pDependSurface;

            pExecuteIn->planeListRightView[pExecuteIn->planeCount] = PCOMPlane;
        }
    }

	return S_OK;
}

CAMDDeviceExtensionAdapter::CAMDDeviceExtensionAdapter()
{
	m_pDevice9 = NULL;
	m_pMcomSession = NULL;
    m_hWnd = NULL;
    m_hMonitor = NULL;
	ZeroMemory(&m_pMcomSession, sizeof(MCOM_DECODE_STREAM_CAPS));
	ZeroMemory(&m_PCOMCapsOutput,sizeof(PCOM_GET_CAPS_OUTPUT));
	ZeroMemory(&m_AdapterInfo,sizeof(DrvExtAdapterInfo));
	m_DecodeStreamCaps.CAP_2HD_OTHER = m_DecodeStreamCaps.CAP_2HD_PROGRESSIVE = m_DecodeStreamCaps.CAP_1HD_1SD = 0x80000000;
}

CAMDDeviceExtensionAdapter::CAMDDeviceExtensionAdapter(IDirect3DDevice9 *pDevice)
{
	m_pDevice9 = pDevice;
	m_pDevice9->AddRef();
    m_pMcomSession = NULL;
    m_hWnd = NULL;
    m_hMonitor = NULL;
    ZeroMemory(&m_pMcomSession, sizeof(MCOM_DECODE_STREAM_CAPS));
    ZeroMemory(&m_PCOMCapsOutput,sizeof(PCOM_GET_CAPS_OUTPUT));
    ZeroMemory(&m_AdapterInfo,sizeof(DrvExtAdapterInfo));
    m_DecodeStreamCaps.CAP_2HD_OTHER = m_DecodeStreamCaps.CAP_2HD_PROGRESSIVE = m_DecodeStreamCaps.CAP_1HD_1SD = 0x80000000;
}

CAMDDeviceExtensionAdapter::~CAMDDeviceExtensionAdapter()
{
	DestroyMCOM();
	SAFE_RELEASE(m_pDevice9);
}

HRESULT CAMDDeviceExtensionAdapter::SetDevice(IDirect3DDevice9 *pDevice9)
{
	if (m_pDevice9 != pDevice9)
	{
		SAFE_RELEASE(m_pDevice9);

		m_pDevice9 = pDevice9;

		if (m_pDevice9)
			m_pDevice9->AddRef();
	}
	return S_OK;
}

HRESULT CAMDDeviceExtensionAdapter::CreateMCOM(HWND hwnd)
{
	HRESULT hr = E_FAIL;
	MCOM_STATUS ret = MCOM_FAIL;
	MCOM_CREATE_INPUT CreateIn = {0};
	MCOM_CREATE_OUTPUT CreateOut = {0};

	CreateIn.size = sizeof(MCOM_CREATE_INPUT);
	CreateOut.size = sizeof(MCOM_CREATE_OUTPUT);

	CreateIn.flags = 0;
	CreateIn.windowHandle = hwnd;
	CreateIn.GfxDevice = m_pDevice9;

	ret = MCOMCreate(&CreateIn, &CreateOut);
	if (ret != MCOM_OK)
	{
		DbgMsg("MCOMCreate return value: 0x%08X", ret);
		return hr;
	}
    else
        hr = S_OK;
	m_pMcomSession = CreateOut.MCOMSession;
	hr = QueryDecodeStreamCaps();

	return hr;
}

HRESULT CAMDDeviceExtensionAdapter::DestroyMCOM()
{
	if (m_pMcomSession)
	{
		MCOM_STATUS ret = MCOM_FAIL;
		ret = MCOMDestroy(m_pMcomSession);
		m_pMcomSession = NULL;
	}
	return S_OK;
}

HRESULT CAMDDeviceExtensionAdapter::QueryDecodeStreamCaps()
{
	MCOM_STATUS ret = MCOM_FAIL;
	MCOM_GET_BLURAY_DECODE_STREAM_INPUT DecodeStreamIn = {0};
	MCOM_GET_BLURAY_DECODE_STREAM_OUTPUT DecodeStreamOut = {0};

	DecodeStreamIn.size = sizeof(MCOM_GET_BLURAY_DECODE_STREAM_INPUT);
	DecodeStreamOut.size = sizeof(MCOM_GET_BLURAY_DECODE_STREAM_OUTPUT);

	DecodeStreamIn.MCOMSession = m_pMcomSession;

	ret = MCOMBluRayDecodeStreamCaps(&DecodeStreamIn, &DecodeStreamOut);
	if (ret != MCOM_OK)
	{
		DbgMsg("MCOMBluRayDecodeStreamCaps return value: 0x%08X", ret);
		return E_FAIL;
	}

	memcpy(&m_DecodeStreamCaps, &DecodeStreamOut.DecodeStreamCaps, sizeof(MCOM_DECODE_STREAM_CAPS));

	return S_OK;
}

HRESULT CAMDDeviceExtensionAdapter::GetAdapter(IDriverExtensionAdapter **ppAdapter)
{
	*ppAdapter = 0;
	*ppAdapter = new CAMDDeviceExtensionAdapter();

	return S_OK;
}

HRESULT CAMDDeviceExtensionAdapter::QueryPresenterCaps(DWORD VideoDecodeCaps, PresenterCaps* pCaps)
{
    HRESULT hr = E_FAIL;
	if(!m_pMcomSession && m_pDevice9)
	{
		CComPtr<IDirect3DSwapChain9> pSwapChain;
		D3DPRESENT_PARAMETERS sPresentParam;

		m_pDevice9->GetSwapChain(0, &pSwapChain);
		if (SUCCEEDED(pSwapChain->GetPresentParameters(&sPresentParam)))
		{
			hr = CreateMCOM(sPresentParam.hDeviceWindow);
		}
	}

	if(VideoDecodeCaps > 0 && m_pMcomSession)
	{
		if(m_DecodeStreamCaps.CAP_2HD_OTHER == 0) // no restriction
		{
			pCaps->bHwDecode = TRUE;
		}
		else if(m_DecodeStreamCaps.CAP_2HD_PROGRESSIVE == 0) //both HD streams in progressive format only
		{
			if((VideoDecodeCaps & VIDEO_CAP_STREAM_SUB) &&
				(VideoDecodeCaps & VIDEO_CAP_INTERLACE) &&
				(VideoDecodeCaps & (VIDEO_CAP_FORMAT_1080|VIDEO_CAP_FORMAT_720)))
				pCaps->bHwDecode = FALSE;
			else
				pCaps->bHwDecode = TRUE;
		}
		else if(m_DecodeStreamCaps.CAP_1HD_1SD == 0) //1 SD + 1 HD streams in both interlaced and progressive format
		{
			if((VideoDecodeCaps & VIDEO_CAP_STREAM_SUB) &&
				(VideoDecodeCaps & (VIDEO_CAP_FORMAT_1080|VIDEO_CAP_FORMAT_720)))
				pCaps->bHwDecode = FALSE;
			else
				pCaps->bHwDecode = TRUE;
		}
		else if(m_DecodeStreamCaps.CAP_1HD_OTHER == 0) //one HD stream in either interlaced or progressive format
		{
			pCaps->bHwDecode = (VideoDecodeCaps & VIDEO_CAP_STREAM_SUB) ? FALSE : TRUE;
		}
		else if(m_DecodeStreamCaps.CAP_1HD_PROGRESSIVE == 0) //one HD in progressive format (for instance, some RV610 only supports this)
		{
			if(!(VideoDecodeCaps & VIDEO_CAP_STREAM_SUB) &&
				!(VideoDecodeCaps & VIDEO_CAP_INTERLACE))
				pCaps->bHwDecode = TRUE;
			else
				pCaps->bHwDecode = FALSE;
		}
		else //this ASIC don't support DXVA.
		{
			pCaps->bHwDecode = FALSE;
		}
	}

	return hr;
}

HRESULT CAMDDeviceExtensionAdapter::QueryHDMIStereoModeCaps(HWND hWnd, DriverExtHDMIStereoModeCap **ppCaps, UINT *puCount)
{
	CHECK_POINTER(ppCaps);
	CHECK_POINTER(puCount);

	HRESULT hr = E_FAIL;

	hr = GetPCOMCaps(hWnd);

    //Query all display mode of HDMI1.4
    int iNumHDMI14 = 0;
    for(unsigned int i = 0; i < m_PCOMCapsOutput.supportedStereoscopicDisplayModeCount; i++)
    {
        if(m_PCOMCapsOutput.supportedStereoscopicDisplayModes[i].stereoscopicFormat == PCOM_STEREOSCOPIC_FORMAT_HDMI_14)
            iNumHDMI14++;
    }

    if(iNumHDMI14 > 0)
    {
        (*ppCaps) = new DriverExtHDMIStereoModeCap[iNumHDMI14];
        ZeroMemory((*ppCaps), sizeof(DriverExtHDMIStereoModeCap) * iNumHDMI14);
        (*puCount) = iNumHDMI14;

        int j = 0;
        for(unsigned int i = 0; i < m_PCOMCapsOutput.supportedStereoscopicDisplayModeCount; i++)
        {
            if(m_PCOMCapsOutput.supportedStereoscopicDisplayModes[i].stereoscopicFormat == PCOM_STEREOSCOPIC_FORMAT_HDMI_14)
            {
                (*ppCaps)[j].uWidth = m_PCOMCapsOutput.supportedStereoscopicDisplayModes[i].width;
                (*ppCaps)[j].uHeight = m_PCOMCapsOutput.supportedStereoscopicDisplayModes[i].height;
                (*ppCaps)[j].uRefreshRate = m_PCOMCapsOutput.supportedStereoscopicDisplayModes[i].refreshRate;
                (*ppCaps)[j].dwStereoMode = HDMI_STEREO_FRAME_PACKING;
                j++;
            }
        }
    }

	return S_OK;
}

HRESULT CAMDDeviceExtensionAdapter::EnableHDMIStereoMode(BOOL bEnable, DriverExtHDMIStereoModeCap *pCap, BOOL *pbReCreateDevice)
{
	CHECK_POINTER(pCap);
	CHECK_POINTER(pbReCreateDevice);

	HRESULT hr = E_FAIL;
	MixerProperty MixerProp;

	(*pbReCreateDevice) = TRUE;

	CComPtr<IDispSvrVideoMixer> pDispSvrVideoMixer;
	if(SUCCEEDED(CResourceManager::GetInstance()->GetInterface(DISPSVR_RESOURCE_VIDEOMIXER, __uuidof(IDispSvrVideoMixer), (void **)&pDispSvrVideoMixer)))
	{
		pDispSvrVideoMixer->GetProperty(&MixerProp);
		MixerProp.eStereoMode = (bEnable) ? MIXER_STEREO_MODE_HDMI_STEREO : MIXER_STEREO_MODE_DISABLED;

		//Need to change display setting
		DEVMODE devMode;
		DWORD dwFlag = CDS_RESET;
		memset(&devMode, 0, sizeof(devMode));
		devMode.dmSize = sizeof(devMode);
		devMode.dmPelsWidth = pCap->uWidth;
		devMode.dmPelsHeight = pCap->uHeight;
		devMode.dmDisplayFrequency = pCap->uRefreshRate;
		devMode.dmBitsPerPel = 32;   // exclusive mode only supports 32 bits color depth.
		devMode.dmFields = DM_PELSWIDTH | DM_PELSHEIGHT | DM_DISPLAYFREQUENCY | DM_BITSPERPEL;
		ChangeDisplaySettings(&devMode, dwFlag);

		//Re-creating PCOM
		if(SUCCEEDED(pDispSvrVideoMixer->SetProperty(&MixerProp)))
		{
			DbgMsg ("CAMDDeviceExtensionAdapter::EnableHDMIStereoMode - Success.\n");
		}
		else
		{
			DbgMsg ("CAMDDeviceExtensionAdapter::EnableHDMIStereoMode - Fail.\n");
		}
	}

	return S_OK;
}

HRESULT CAMDDeviceExtensionAdapter::QueryAdapterInfo(HWND hWnd, HMONITOR hMonitor, DispSvr::DrvExtAdapterInfo *pInfo)
{
	CHECK_POINTER(pInfo);
	HRESULT hr = E_FAIL;

	hr = GetPCOMCaps(hWnd);
	memcpy(pInfo, &m_AdapterInfo, sizeof(DrvExtAdapterInfo));

	return hr;
}

HRESULT CAMDDeviceExtensionAdapter::GetPCOMCaps(HWND hwnd)
{
    HRESULT hr = E_FAIL;
	IDirect3DDevice9 *pDevice = NULL;
	PCOM_STATUS ret = PCOM_OK;
	PCOM_GET_CAPS_INPUT GetCapsIn = {0};

    HMONITOR hMonitor = MonitorFromWindow(hwnd, (hwnd) ? MONITOR_DEFAULTTONEAREST : MONITOR_DEFAULTTOPRIMARY);
	if(m_hMonitor == hMonitor && m_hWnd == hwnd)  // Don't query PCOMcaps again if video window handler and monitor hanlder are the same.
		return S_FALSE;

	ZeroMemory(&m_PCOMCapsOutput,sizeof(PCOM_GET_CAPS_OUTPUT));
	m_PCOMCapsOutput.size = sizeof(PCOM_GET_CAPS_OUTPUT);
	GetCapsIn.size = sizeof(PCOM_GET_CAPS_INPUT);

	if(!m_pDevice9)
	{
		if(FAILED(CreateFakeD3DDevice(hwnd, &pDevice)))
			return hr;

        GetCapsIn.GfxDevice = pDevice;
	}
	else
	{
		GetCapsIn.GfxDevice = m_pDevice9;
	}

	ret = PCOMGetCaps(&GetCapsIn, &m_PCOMCapsOutput);
	if (ret != PCOM_OK)
		return hr;
    else
        hr = S_OK;

	m_AdapterInfo.bIsXVYCCSupported = m_PCOMCapsOutput.flags.supportXvYCCWideGamutDisplay;

    if((m_PCOMCapsOutput.revision>>16) >= PCOM_V3)  //PCOMv3 Caps
    {
        //Query all supported format and save them.
        for(unsigned int i = 0; i < m_PCOMCapsOutput.supportedStereoscopicFormatCount; i++)
        {
            m_AdapterInfo.dwSupportStereoFormats |= ToStereoVision(m_PCOMCapsOutput.supportedStereoscopicFormats[i]);
        }
        //Query all display mode of HDMI1.4
        int iNumHDMI14 = 0;
        int iNumDP12 = 0;
        int iNumFrameSequential = 0;
        for(unsigned int i = 0; i < m_PCOMCapsOutput.supportedStereoscopicDisplayModeCount; i++)
        {
            switch (m_PCOMCapsOutput.supportedStereoscopicDisplayModes[i].stereoscopicFormat)
            {
            case PCOM_STEREOSCOPIC_FORMAT_HDMI_14:
                iNumHDMI14++;
                break;
            case PCOM_STEREOSCOPIC_FORMAT_FRAME_SEQUENTIAL:
                iNumFrameSequential++;
                break;
            case PCOM_STEREOSCOPIC_FORMAT_DP_12:
                iNumDP12++;
                break;
            default:
                break;
            }
        }

        if(iNumHDMI14 == 0) // There is no display mode about HDMI1.4
        {
            m_AdapterInfo.dwSupportStereoFormats &= ~STEREO_VISION_HDMI_STEREO;
            DbgMsg("PCOMv3 does not support HDMI1.4, no HDMI1.4 display format");
        }
        if(iNumFrameSequential == 0) // There is no display mode about frame sequential
        {
            m_AdapterInfo.dwSupportStereoFormats &= ~STEREO_VISION_AMD_FRAME_SEQENTIAL;
            DbgMsg("PCOMv3 does not support frame seqential, no frame seqential display format");
        }
        if(iNumDP12 == 0) // There is no display mode about DP1.2
        {
            m_AdapterInfo.dwSupportStereoFormats &= ~STEREO_VISION_DP_STEREO;
            DbgMsg("PCOMv3 does not support DP1.2, no DP1.2 display format");
        }
    }

	m_hWnd = hwnd;
    m_hMonitor = hMonitor;
    SAFE_RELEASE(pDevice);

	return hr;
}

HRESULT CAMDDeviceExtensionAdapter::CreateFakeD3DDevice(HWND hwnd, IDirect3DDevice9 **pDevice)
{
	HRESULT hr = E_FAIL;

	// Creating a temp d3d device. That is a workaround solution due to we don't have current device when calling this function.
	CComPtr<IDirect3D9> pD3D9;

	pD3D9 = Direct3DCreate9(D3D_SDK_VERSION);

	if (!pD3D9)
	{
		DbgMsg("CAMDDeviceExtensionAdapter::CreateFakeD3DDevice: failed to create Direct3D9 object");
		return hr;
	}

	D3DPRESENT_PARAMETERS pp = {0};
	pp.Windowed = TRUE;
	pp.hDeviceWindow = hwnd;
	pp.SwapEffect = D3DSWAPEFFECT_DISCARD;
	pp.BackBufferCount = 0;
	pp.Flags = D3DPRESENTFLAG_DEVICECLIP;
	pp.BackBufferFormat = D3DFMT_X8R8G8B8;

	hr = pD3D9->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hwnd, D3DCREATE_DISABLE_DRIVER_MANAGEMENT_EX|D3DCREATE_SOFTWARE_VERTEXPROCESSING, &pp, pDevice);
	if (FAILED(hr))
	{
		DbgMsg("CAMDDeviceExtensionAdapter::CreateD3DDevice9Ex: failed to create Direct3D9Ex Device, version = %d", D3D_SDK_VERSION);
		return hr;
	}

	return hr;
}


text:
package org.dotwebstack.framework.core;

import graphql.language.ScalarTypeDefinition;
import graphql.schema.idl.RuntimeWiring.Builder;
import graphql.schema.idl.TypeDefinitionRegistry;
import lombok.NonNull;
import org.dotwebstack.framework.core.scalars.CoreScalars;
import org.springframework.context.annotation.Conditional;
import org.springframework.stereotype.Component;

@Component
@Conditional(OnLocalSchema.class)
public class CoreConfigurer implements GraphqlConfigurer {

  @Override
  public void configureTypeDefinitionRegistry(@NonNull TypeDefinitionRegistry typeDefinitionRegistry) {
    typeDefinitionRegistry.add(new ScalarTypeDefinition(CoreScalars.OBJECT.getName()));
    typeDefinitionRegistry.add(new ScalarTypeDefinition(CoreScalars.DATE.getName()));
    typeDefinitionRegistry.add(new ScalarTypeDefinition(CoreScalars.DATETIME.getName()));
  }

  @Override
  public void configureRuntimeWiring(@NonNull Builder builder) {
    builder.scalar(CoreScalars.OBJECT)
        .scalar(CoreScalars.DATE)
        .scalar(CoreScalars.DATETIME);
  }
}


text:
package com.plusonelabs.dashclock.gerrit;

import static android.content.Intent.*;
import static com.plusonelabs.dashclock.gerrit.prefs.GerritPreferences.*;
import static com.plusonelabs.dashclock.gerrit.util.StringUtil.*;
import static com.plusonelabs.dashclock.gerrit.util.UrlUtil.*;

import java.util.List;

import android.content.Intent;
import android.content.SharedPreferences;
import android.content.res.Resources;
import android.net.Uri;
import android.util.Log;

import com.google.android.apps.dashclock.api.DashClockExtension;
import com.google.android.apps.dashclock.api.ExtensionData;
import com.plusonelabs.dashclock.gerrit.auth.AnonymousAuthenticationProvider;
import com.plusonelabs.dashclock.gerrit.auth.AuthenticationProvider;
import com.plusonelabs.dashclock.gerrit.auth.BasicAuthWithCookieAuthenticationProvider;
import com.plusonelabs.dashclock.gerrit.prefs.GerritPreferences;

public class GerritDashClockExtension extends DashClockExtension {

	private Gerrit gerrit;
	private GerritEndpoint endpoint;

	@Override
	protected void onInitialize(boolean isReconnect) {
		endpoint = new GerritEndpoint(getSecurePreferences(getApplicationContext()));
		gerrit = new Gerrit(endpoint);
		setUpdateWhenScreenOn(true);
	}

	@Override
	protected void onUpdateData(int reason) {
		try {
			publishGerritState();
		} catch (Exception e) {
			if (BuildConfig.DEBUG) {
				Log.e(GerritDashClockExtension.class.getSimpleName(),
						"A problem occured while populating the gerrit dashclock extension.", e);
			}
		}
	}

	private void publishGerritState() {
		ExtensionData extensionData = new ExtensionData();
		extensionData.visible(false);
		if (endpoint.getUrl() != null) {
			fetchFromGerrit();
			updateStatus(extensionData);
		}
		publishUpdate(extensionData);
	}

	private void fetchFromGerrit() {
		SharedPreferences prefs = GerritPreferences.getSharedPreferences(getApplicationContext());
		String project = prefs.getString(GerritPreferences.DISPLAY_FILTER_PROJECT, null);
		String branch = prefs.getString(GerritPreferences.DISPLAY_FILTER_BRANCH, null);
		String reviewer = prefs.getString(GerritPreferences.DISPLAY_REVIEWER, null);
		gerrit.fetchChanges(createAuthenticationProvider(), project, branch, reviewer);
	}

	private AuthenticationProvider createAuthenticationProvider() {
		if (hasContent(endpoint.getUsername())) {
			return new BasicAuthWithCookieAuthenticationProvider();
		}
		return new AnonymousAuthenticationProvider();
	}

	private void updateStatus(ExtensionData extensionData) {
		SharedPreferences prefs = GerritPreferences.getSharedPreferences(getApplicationContext());
		String total = createQuantitiy(gerrit.getAllChanges(), R.plurals.changes);
		String assigned = createQuantitiy(gerrit.getAssignedChanges(), R.plurals.assignedChanges);
		String changesScope = prefs.getString(DISPLAY_CHANGES_SCOPE, DISPLAY_CHANGES_SCOPE_ALL);
		if (changesScope.equals(DISPLAY_CHANGES_SCOPE_ALL) && !gerrit.getAllChanges().isEmpty()) {
			setAllChangesDetails(extensionData, total, assigned);
		} else if (changesScope.equals(DISPLAY_CHANGES_SCOPE_ASSIGNED)
				&& !gerrit.getAssignedChanges().isEmpty()) {
			setAssignedChangesDetails(extensionData, total, assigned);
		}
	}

	private void setAllChangesDetails(ExtensionData extensionData, String numberOfChanges,
			String numberOfAssignedChanges) {
		extensionData.visible(true).icon(R.drawable.ic_extension_icon)
				.status(String.valueOf(gerrit.getAllChanges().size()))
				.expandedTitle(numberOfChanges).expandedBody(numberOfAssignedChanges);
		setClickIntent(gerrit.getAllChanges(), extensionData);
	}

	private void setAssignedChangesDetails(ExtensionData extensionData, String numberOfChanges,
			String numberOfAssignedChanges) {
		extensionData.visible(true).icon(R.drawable.ic_extension_icon)
				.status(String.valueOf(gerrit.getAssignedChanges().size()))
				.expandedTitle(numberOfAssignedChanges).expandedBody(numberOfChanges);
		setClickIntent(gerrit.getAllChanges(), extensionData);
	}

	private String createQuantitiy(List<Change> changes, int plural) {
		Resources res = getResources();
		int changesCount = changes.size();
		return res.getQuantityString(plural, changesCount, changesCount);
	}

	private void setClickIntent(List<Change> changes, ExtensionData extensionData) {
		String changeUrl = endpoint.getUrl();
		if (changes.size() == 1) {
			changeUrl = appendPath(changeUrl, "/#/c/" + changes.get(0).getChangeId() + "/");
		} else {
			changeUrl = appendPath(changeUrl, "/#/q/status:open,n,z");
		}
		extensionData.clickIntent(new Intent(ACTION_VIEW, Uri.parse(changeUrl)));
	}
}


text:
var Backhoe = require('backhoe');
Backhoe.noCache();


text:
//
// SGRadar.h
// SGLocatorServices
//
// Created by Derek Smith on 8/24/09.
// Copyright 2010 SimpleGeo. All rights reserved.
//

#import <UIKit/UIKit.h>

#import "SGAnnotationView.h"

/*!
* @enum SGCardinalDirection
* @abstract The four cardinal directions.
* @constant kSGCardinalDirection_North The north direction.
* @constant kSGCardinalDirection_East The east direction.
* @constant kSGCardinalDirection_South The south direction.
* @constant kSGCardinalDirection_West The west direction.
*/
enum SGCardinalDirection {

    kSGCardinalDirection_North = 0,
    kSGCardinalDirection_East,
    kSGCardinalDirection_South,
 	kSGCardinalDirection_West

};

typedef NSInteger SGCardinalDirection;

/*!
* @class SGRadar
* @abstract A radar shows the current heading of the device based on the true north value gathered from
* CoreLocation. It is also the job of the radar to display the @link //simplegeo/ooc/cl/SGRecordAnnotation SGRecordAnnotations @/link in
* the proper position based on their geographic coordinate and the current location of the device.
* @discussion For every @link //simplegeo/ooc/cl/SGAnnotationView annotation view @/link that is registered with the @link //simplegeo/ooc/cl/SGARView SGARView @/link,
* the @link //simplegeo/ooc/instp/SGAnnotationView/radarTargetButton radarTargetButton @/link is added as a subview of this view.
*
* Both the heading and the radar can be represented by separate images. The default representation calls upon CoreGraphics to render the simple shapes.
* You can change the colors of the default representation by calling @link radarBorderColor radarBorderColor @/link, @link radarCircleColor radarCircleColor @/link
* and @link headingColor headingColor @/link. If no image is present in either 3 image views, the default representation will persist.
*/
@interface SGRadar : UIView {

    UIImageView* currentLocationImageView;
 	UIImageView* headingImageView;
 	UIImageView* radarBackgroundImageView;

 	BOOL rotatable;
 	BOOL shouldShowCardinalDirections;

    CGFloat cardinalDirectionOffset;

    UIColor* radarBorderColor;
    UIColor* radarCircleColor;

    UIColor* headingColor;

}

/*!
* @property
* @abstract The image view that represents the the devices current location.
* @discussion The default image is a white plus sign.
*/
@property (nonatomic, readonly) UIImageView* currentLocationImageView;

/*!
* @property
* @abstract The background image view of the radar.
*/
@property (nonatomic, readonly) UIImageView* radarBackgroundImageView;

/*!
* @property
* @abstract The image view that contains the image used for the heading.
*/
@property (nonatomic, readonly) UIImageView* headingImageView;

/*!
* @property
* @abstract Determines whether the radar rotates with the device. This is determined by the roll parameter in
* @link drawRadarWithHeading:roll: drawRadarWithHeading:roll: @/link.
*/
@property (nonatomic, assign) BOOL rotatable;

/*!
* @property
* @abstract Set this to YES to show all of the cardinal direction labels. Otherwise; NO. The default
* is YES.
* @discussion To hide individual labels, use @link labelForCardinalDirection: labelForCardinalDirection @/link.
*/
@property (nonatomic, assign) BOOL shouldShowCardinalDirections;

/*!
* @property
* @abstract The amount of pixel separation between a cardinal direction label and the radar image. A negative value will
* decrease the distance while a postivie value with increase the distance.
*/
@property (nonatomic, assign) CGFloat cardinalDirectionOffset;

/*!
* @property
* @abstract The border color of the circular radar. The default RGBA value is 0.6, 0.6, 0.6, 0,7.
*/
@property (nonatomic, retain) UIColor* radarBorderColor;

/*!
* @property
* @abstract The color of the radar. The default RGBA value is 0.0, 0.0, 0.0, 0.7.
*/
@property (nonatomic, retain) UIColor* radarCircleColor;

/*!
* @property
* @abstract The color of the header circular segment. The default RGBA value is 1.0, 1.0, 1.0, 0.7.
*/
@property (nonatomic, retain) UIColor* headingColor;

/*!
* @method labelForCardinalDirection:
* @abstract Returns the label associated with the @link SGCardinalDirection SGCardinalDirection @/link.
* @param direction The direction of the desired label.
* @result The label.
*/
- (UILabel*) labelForCardinalDirection:(SGCardinalDirection)direction;

/*!
* @method drawRadarWithHeading:roll:
* @abstract This method is called whenever the radar needs to redisplayed.
* @discussion Since the radar's orientation depends upon the heading and z axis orientation of the device,
* the view must be updated constantly.
* @param heading
* @param roll
*/
- (void) drawRadarWithHeading:(double)heading roll:(double)roll;

@end


text:
if ENV["COVERAGE"]
  require "simplecov"
  SimpleCov.start do
    add_filter "/test/"
  end
end

require "combustion"
Combustion.path = "test/internal"
Combustion.initialize! :active_record

require "rails/test_help"
require "minitest/autorun"
require "capybara/rails"

# Load fixtures from the engine
if ActiveSupport::TestCase.respond_to?(:fixture_path=)
  ActiveSupport::TestCase.fixture_path = File.expand_path("fixtures", __dir__)
  ActionDispatch::IntegrationTest.fixture_path = ActiveSupport::TestCase.fixture_path
  ActiveSupport::TestCase.fixtures :all
end


text:
import markedMan from "marked-man";

markedMan.setOptions({
  format: "html",
  name: "",
  date: new Date(),
  section: "",
  version: "",
  manual: "",
  gfm: true,
  breaks: true,
  sanitize: true,
  ronn: true
});

// $ExpectError
markedMan.setOptions(["yoloism", true]);

markedMan("", (err, content) => {
  if (err) throw err;
});

// $ExpectError
markedMan(24, function(err, content) {
  if (err) throw err;
  console.log(content);
});

const x: string = markedMan("");
// $ExpectError
markedMan("", { tables: false });

// $ExpectError
markedMan("up", "top");
// $ExpectError
const y: string = markedMan(23);


text:
using Prism.Regions.Behaviors;
using System.Composition;
namespace Prism.SysComposition.Regions.Behaviors
{
    /// <summary>
    /// Exports the SelectorItemsSourceSyncBehavior using the Managed Extensibility Framework (MEF).
    /// </summary>
    /// <remarks>
    /// This allows the SysCompBootstrapper to provide this class as a default implementation.
    /// If another implementation is found, this export will not be used.
    /// </remarks>
    [Export(typeof(SelectorItemsSourceSyncBehavior))]

    public class SysCompSelectorItemsSourceSyncBehavior : SelectorItemsSourceSyncBehavior
    {
    }
}


text:
<!doctype html>

  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="description" content="">
  <meta name="author" content="">

  <title>TODO</title>

  <link rel="stylesheet" href="Css/Layout6.css">

#Menu

#FirstColumn

#SecondColumn

#Footer


text:
package org.sakuli.aop;

import net.sf.sahi.rhino.RhinoScriptRunner;
import net.sf.sahi.session.Session;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.sakuli.actions.ModifySahiTimer;
import org.sakuli.datamodel.properties.SahiProxyProperties;
import org.sakuli.loader.BaseActionLoader;
import org.sakuli.loader.BeanLoader;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

/**
 * Aspect for the External Sahi Libary {@link net.sf.sahi}
 *
 * @author tschneck
 *         Date: 17.10.13
 */
@Aspect
@Component
public class ModifySahiTimerAspect extends BaseSakuliAspect {

    protected final static Logger logger = LoggerFactory.getLogger(ModifySahiTimerAspect.class);

    /**
     * Before Pointcut for the {@link org.sakuli.actions.environment} class
     * to do an {@link #modifySahiTimer(JoinPoint, boolean)}.
     */
    @Before("execution(* org.sakuli.actions.environment.*.*(..)) &&" +
            "@annotation(modifySahiTimer)")
    public void doEnvironmentBefore(JoinPoint joinPoint, ModifySahiTimer modifySahiTimer) {
        modifySahiTimer(joinPoint, true);
    }

    /**
     * Before Pointcut for the {@link org.sakuli.actions.screenbased} class
     * to do an {@link #modifySahiTimer(JoinPoint, boolean)}.
     */
    @Before("execution(* org.sakuli.actions.screenbased.*.*(..)) &&" +
            "@annotation(modifySahiTimer)")
    public void doScreenbasedBefore(JoinPoint joinPoint, ModifySahiTimer modifySahiTimer) {
        modifySahiTimer(joinPoint, true);
    }

    /**
     * After Pointcut for the {@link org.sakuli.actions.environment} class
     * to do an {@link #modifySahiTimer(JoinPoint, boolean)}.
     */
    @After("execution(* org.sakuli.actions.environment.*.*(..)) &&" +
            "@annotation(modifySahiTimer)")
    public void doEnvironmentAfter(JoinPoint joinPoint, ModifySahiTimer modifySahiTimer) {
        modifySahiTimer(joinPoint, false);
    }

    /**
     * After for the {@link org.sakuli.actions.screenbased} class
     * to do an {@link #modifySahiTimer(JoinPoint, boolean)}.
     */
    @After("execution(* org.sakuli.actions.screenbased.*.*(..)) &&" +
            "@annotation(modifySahiTimer)")
    public void doScreenbasedAfter(JoinPoint joinPoint, ModifySahiTimer modifySahiTimer) {
        modifySahiTimer(joinPoint, false);
    }

    void modifySahiTimer(JoinPoint joinPoint, boolean beforeMethod) {
        BaseActionLoader loader = BeanLoader.loadBaseActionLoader();
        SahiProxyProperties sahiProxyProperties = loader.getSahiProxyProperties();
        if (sahiProxyProperties != null
                && sahiProxyProperties.isRequestDelayActive()) {
            RhinoScriptRunner rhinoScriptRunner = loader.getRhinoScriptRunner();

            if (rhinoScriptRunner != null && rhinoScriptRunner.getSession() != null) {
                getLogger(joinPoint).debug("MODIFY SAHI-TIMER for {}", getClassAndMethodAsString(joinPoint));
                Session session = rhinoScriptRunner.getSession();
                if (beforeMethod) {
                    Integer delay = determineDelay(joinPoint, loader);
                    session.setVariable(SahiProxyProperties.SAHI_REQUEST_DELAY_TIME_VAR, delay.toString());

                    //short sleep to ensure that browser context can read out the value
                    try {
                        logger.info("wait {}ms for sahi refresh", sahiProxyProperties.getRequestDelayRefreshMs());
                        Thread.sleep(sahiProxyProperties.getRequestDelayRefreshMs());
                    } catch (InterruptedException e) {
                        BeanLoader.loadBaseActionLoader().getExceptionHandler().handleException(e, true);
                    }
                    logger.info("sahi-proxy-timer modified to {} ms", delay.toString());

                } else {
                    logger.info("reset sahi-proxy-timer");
                    session.setVariable(SahiProxyProperties.SAHI_REQUEST_DELAY_TIME_VAR, null);
                }
            }
        }
    }

    protected Integer determineDelay(JoinPoint joinPoint, BaseActionLoader loader) {
        Integer deleay = loader.getSahiProxyProperties().getRequestDelayMs();
        if (joinPoint.getSignature().getName().startsWith("type")) {
            Object[] args = joinPoint.getArgs();
            if (args != null && args.length > 0) {
                Object text = args[0];
                if (text instanceof String) {
                    int length = ((String) text).length();
                    int typeDelayMs = loader.getActionProperties().getTypeDelayMs();

                    return length * (typeDelayMs + deleay);
                }
            }
        }
        return deleay;
    }

}


text:
package com.mk.portal.framework.page.html.tags;

import java.util.List;

import com.mk.portal.framework.html.objects.FormattingUtil;
import com.mk.portal.framework.html.objects.PageComponent;
import com.mk.portal.framework.html.objects.TagComponent;
import com.mk.portal.framework.model.PortalPage;

public class Text implements PageComponent {
    private String value;
    private boolean bold;
    private boolean italics;
    private boolean underLined;
    private FontTag font;
    private PortalPage page;
    @Override
	public PortalPage getPage() {
		return page;
	}
    @Override
	public void setPage(PortalPage page) {
		this.page = page;
	}

	public Text(String string) {
		this.value=string;
	}

	public String getValue() {
		return value;
	}

	public void setValue(String value) {
		this.value = value;
	}
    @Override
    public String toString(){
    	StringBuffer sb = new StringBuffer();
    	if(isBold()){
    		sb.append("");
    	}
    	if(isItalics()){
    		sb.append("");
    	}
    	if(isUnderLined()){
    		sb.append("");
    	}
    	if(font!=null){
    		font.addChild(new Text(this.value));
    		sb.append(getFontString(0));
    	}
    	else{
    		sb.append(this.value);
    	}

    	if(isUnderLined()){
    		sb.append("");
    	}
    	if(isItalics()){
    		sb.append("");
    	}
    	if(isBold()){
    		sb.append("");
    	}
    	return sb.toString();
    }

	private String getFontString(int tabCount) {
		if(tabCount>0){
			return font.toFormattedString(tabCount);
		}
		return font.toString();
	}

	@Override
	public TagComponent clone() {
		try {
			return (TagComponent) super.clone();
		} catch (CloneNotSupportedException e) {
			e.printStackTrace();
			throw new AssertionError();
		}
	}

	@Override
	public boolean hasChildren() {
		return false;
	}

	@Override
	public List<PageComponent> getChildren() {
		return null;
	}

	@Override
	public String toFormattedString(int tabcount) {
		return FormattingUtil.getFormattingTabs(tabcount)+this.toString();
	}

	@Override
	public void addChild(PageComponent child) {

	}

	public boolean isBold() {
		return bold;
	}

	public void setBold(boolean bold) {
		this.bold = bold;
	}

	public boolean isItalics() {
		return italics;
	}

	public void setItalics(boolean italics) {
		this.italics = italics;
	}

	public boolean isUnderLined() {
		return underLined;
	}

	public void setUnderLined(boolean underLined) {
		this.underLined = underLined;
	}

	public FontTag getFont() {
		return font;
	}

	public void setFont(FontTag font) {
		this.font = font;
	}
}


text:
package jsonV1

import (
	"encoding/json"
	"fmt"
	"strconv"
	"time"

	"github.com/influxdata/telegraf/plugins/inputs/zipkin/codec"
	"github.com/openzipkin/zipkin-go-opentracing/_thrift/gen-go/zipkincore"
)

// JSON decodes spans from  bodies `POST`ed to the spans endpoint
type JSON struct{}

// Decode unmarshals and validates the JSON body
func (j *JSON) Decode(octets []byte) ([]codec.Span, error) {
	var spans []span
	err := json.Unmarshal(octets, &spans)
	if err != nil {
		return nil, err
	}

	res := make([]codec.Span, len(spans))
	for i := range spans {
		if err := spans[i].Validate(); err != nil {
			return nil, err
		}
		res[i] = &spans[i]
	}
	return res, nil
}

type span struct {
	TraceID  string             `json:"traceId"`
	SpanName string             `json:"name"`
	ParentID string             `json:"parentId,omitempty"`
	ID       string             `json:"id"`
	Time     *int64             `json:"timestamp,omitempty"`
	Dur      *int64             `json:"duration,omitempty"`
	Debug    bool               `json:"debug,omitempty"`
	Anno     []annotation       `json:"annotations"`
	BAnno    []binaryAnnotation `json:"binaryAnnotations"`
}

func (s *span) Validate() error {
	var err error
	check := func(f func() (string, error)) {
		if err != nil {
			return
		}
		_, err = f()
	}

	check(s.Trace)
	check(s.SpanID)
	check(s.Parent)
	if err != nil {
		return err
	}

	_, err = s.BinaryAnnotations()
	return err
}

func (s *span) Trace() (string, error) {
	if s.TraceID == "" {
		return "", fmt.Errorf("Trace ID cannot be null")
	}
	return TraceIDFromString(s.TraceID)
}

func (s *span) SpanID() (string, error) {
	if s.ID == "" {
		return "", fmt.Errorf("Span ID cannot be null")
	}
	return IDFromString(s.ID)
}

func (s *span) Parent() (string, error) {
	if s.ParentID == "" {
		return "", nil
	}
	return IDFromString(s.ParentID)
}

func (s *span) Name() string {
	return s.SpanName
}

func (s *span) Annotations() []codec.Annotation {
	res := make([]codec.Annotation, len(s.Anno))
	for i := range s.Anno {
		res[i] = &s.Anno[i]
	}
	return res
}

func (s *span) BinaryAnnotations() ([]codec.BinaryAnnotation, error) {
	res := make([]codec.BinaryAnnotation, len(s.BAnno))
	for i, a := range s.BAnno {
		if a.Key() != "" && a.Value() == "" {
			return nil, fmt.Errorf("No value for key %s at binaryAnnotations[%d]", a.K, i)
		}
		if a.Value() != "" && a.Key() == "" {
			return nil, fmt.Errorf("No key at binaryAnnotations[%d]", i)
		}
		res[i] = &s.BAnno[i]
	}
	return res, nil
}

func (s *span) Timestamp() time.Time {
	if s.Time == nil {
		return time.Time{}
	}
	return codec.MicroToTime(*s.Time)
}

func (s *span) Duration() time.Duration {
	if s.Dur == nil {
		return 0
	}
	return time.Duration(*s.Dur) * time.Microsecond
}

type annotation struct {
	Endpoint *endpoint `json:"endpoint,omitempty"`
	Time     int64     `json:"timestamp"`
	Val      string    `json:"value,omitempty"`
}

func (a *annotation) Timestamp() time.Time {
	return codec.MicroToTime(a.Time)
}

func (a *annotation) Value() string {
	return a.Val
}

func (a *annotation) Host() codec.Endpoint {
	return a.Endpoint
}

type binaryAnnotation struct {
	K        string          `json:"key"`
	V        json.RawMessage `json:"value"`
	Type     string          `json:"type"`
	Endpoint *endpoint       `json:"endpoint,omitempty"`
}

func (b *binaryAnnotation) Key() string {
	return b.K
}

func (b *binaryAnnotation) Value() string {
	t, err := zipkincore.AnnotationTypeFromString(b.Type)
	// Assume this is a string if we cannot tell the type
	if err != nil {
		t = zipkincore.AnnotationType_STRING
	}

	switch t {
	case zipkincore.AnnotationType_BOOL:
		var v bool
		err := json.Unmarshal(b.V, &v)
		if err == nil {
			return strconv.FormatBool(v)
		}
	case zipkincore.AnnotationType_BYTES:
		return string(b.V)
	case zipkincore.AnnotationType_I16, zipkincore.AnnotationType_I32, zipkincore.AnnotationType_I64:
		var v int64
		err := json.Unmarshal(b.V, &v)
		if err == nil {
			return strconv.FormatInt(v, 10)
		}
	case zipkincore.AnnotationType_DOUBLE:
		var v float64
		err := json.Unmarshal(b.V, &v)
		if err == nil {
			return strconv.FormatFloat(v, 'f', -1, 64)
		}
	case zipkincore.AnnotationType_STRING:
		var v string
		err := json.Unmarshal(b.V, &v)
		if err == nil {
			return v
		}
	}

	return ""
}

func (b *binaryAnnotation) Host() codec.Endpoint {
	return b.Endpoint
}

type endpoint struct {
	ServiceName string `json:"serviceName"`
	Ipv4        string `json:"ipv4"`
	Ipv6        string `json:"ipv6,omitempty"`
	Port        int    `json:"port"`
}

func (e *endpoint) Host() string {
	if e.Port != 0 {
		return fmt.Sprintf("%s:%d", e.Ipv4, e.Port)
	}
	return e.Ipv4
}

func (e *endpoint) Name() string {
	return e.ServiceName
}

// TraceIDFromString creates a TraceID from a hexadecimal string
func TraceIDFromString(s string) (string, error) {
	var hi, lo uint64
	var err error
	if len(s) > 32 {
		return "", fmt.Errorf("TraceID cannot be longer than 32 hex characters: %s", s)
	} else if len(s) > 16 {
		hiLen := len(s) - 16
		if hi, err = strconv.ParseUint(s[0:hiLen], 16, 64); err != nil {
			return "", err
		}
		if lo, err = strconv.ParseUint(s[hiLen:], 16, 64); err != nil {
			return "", err
		}
	} else {
		if lo, err = strconv.ParseUint(s, 16, 64); err != nil {
			return "", err
		}
	}
	if hi == 0 {
		return fmt.Sprintf("%x", lo), nil
	}
	return fmt.Sprintf("%x%016x", hi, lo), nil
}

// IDFromString creates a decimal id from a hexadecimal string
func IDFromString(s string) (string, error) {
	if len(s) > 16 {
		return "", fmt.Errorf("ID cannot be longer than 16 hex characters: %s", s)
	}
	id, err := strconv.ParseUint(s, 16, 64)
	if err != nil {
		return "", err
	}
	return strconv.FormatUint(id, 10), nil
}


text:
<link href="/assets/css/bootstrap.min.css" rel="stylesheet">
<link href="/assets/css/admin/styles.css" rel="stylesheet">
<!--[if lt IE 9]>
    <script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
    <script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
<![endif]-->


text:
namespace Furrovine { namespace Graphics {

	enum class ShaderVersion {
		ShaderModel20,
		ShaderModel30,
		ShaderModel40,
		ShaderModel40_d3d91,
		ShaderModel40_d3d93,
		ShaderModel41,
		ShaderModel50,
		Default = ShaderModel50
	};

}}