Example #1
0
void CProfileGraphDlg::OnPaint() 
{
	if (IsIconic())
	{
		CPaintDC dc(this); // 用于绘制的设备上下文

		SendMessage(WM_ICONERASEBKGND, reinterpret_cast<WPARAM>(dc.GetSafeHdc()), 0);

		// 使图标在工作矩形中居中
		int cxIcon = GetSystemMetrics(SM_CXICON);
		int cyIcon = GetSystemMetrics(SM_CYICON);
		CRect rect;
		GetClientRect(&rect);
		int x = (rect.Width() - cxIcon + 1) / 2;
		int y = (rect.Height() - cyIcon + 1) / 2;

		// 绘制图标
		dc.DrawIcon(x, y, m_hIcon);
	}
	else
	{
		CDialog::OnPaint();


		// get client rect
		CClientDC tempDC( &m_GraphLine );
		CBitmap* tempBitmap;
		CRect    rectTemp;

	
		if ( NULL != m_CompatibleDC.GetSafeHdc() )
		{
			m_GraphLine.GetClientRect(&rectTemp);
			tempBitmap = m_CompatibleDC.SelectObject( &m_CompatibleBitmap );
			tempDC.BitBlt( 0, 0, rectTemp.Width(), rectTemp.Height(), &m_CompatibleDC, 0, 0, SRCCOPY );
			m_CompatibleDC.SelectObject( tempBitmap );
		}

	}

}
void GrConfigConversionEffect::TestForPreservingPMConversions(GrContext* context,
                                                              PMConversion* pmToUPMRule,
                                                              PMConversion* upmToPMRule) {
    *pmToUPMRule = kNone_PMConversion;
    *upmToPMRule = kNone_PMConversion;
    static constexpr int kSize = 256;
    static constexpr GrPixelConfig kConfig = kRGBA_8888_GrPixelConfig;
    SkAutoTMalloc<uint32_t> data(kSize * kSize * 3);
    uint32_t* srcData = data.get();
    uint32_t* firstRead = data.get() + kSize * kSize;
    uint32_t* secondRead = data.get() + 2 * kSize * kSize;

    // Fill with every possible premultiplied A, color channel value. There will be 256-y duplicate
    // values in row y. We set r,g, and b to the same value since they are handled identically.
    for (int y = 0; y < kSize; ++y) {
        for (int x = 0; x < kSize; ++x) {
            uint8_t* color = reinterpret_cast<uint8_t*>(&srcData[kSize*y + x]);
            color[3] = y;
            color[2] = SkTMin(x, y);
            color[1] = SkTMin(x, y);
            color[0] = SkTMin(x, y);
        }
    }

    sk_sp<GrDrawContext> readDC(context->makeDrawContext(SkBackingFit::kExact, kSize, kSize,
                                                         kConfig, nullptr));
    sk_sp<GrDrawContext> tempDC(context->makeDrawContext(SkBackingFit::kExact, kSize, kSize,
                                                         kConfig, nullptr));
    if (!readDC || !tempDC) {
        return;
    }
    GrSurfaceDesc desc;
    desc.fWidth = kSize;
    desc.fHeight = kSize;
    desc.fConfig = kConfig;
    SkAutoTUnref<GrTexture> dataTex(context->textureProvider()->createTexture(
        desc, SkBudgeted::kYes, data, 0));
    if (!dataTex.get()) {
        return;
    }

    static const PMConversion kConversionRules[][2] = {
        {kDivByAlpha_RoundDown_PMConversion, kMulByAlpha_RoundUp_PMConversion},
        {kDivByAlpha_RoundUp_PMConversion, kMulByAlpha_RoundDown_PMConversion},
    };

    bool failed = true;

    for (size_t i = 0; i < SK_ARRAY_COUNT(kConversionRules) && failed; ++i) {
        *pmToUPMRule = kConversionRules[i][0];
        *upmToPMRule = kConversionRules[i][1];

        static const SkRect kDstRect = SkRect::MakeIWH(kSize, kSize);
        static const SkRect kSrcRect = SkRect::MakeIWH(1, 1);
        // We do a PM->UPM draw from dataTex to readTex and read the data. Then we do a UPM->PM draw
        // from readTex to tempTex followed by a PM->UPM draw to readTex and finally read the data.
        // We then verify that two reads produced the same values.

        GrPaint paint1;
        GrPaint paint2;
        GrPaint paint3;
        sk_sp<GrFragmentProcessor> pmToUPM1(new GrConfigConversionEffect(
                dataTex, GrSwizzle::RGBA(), *pmToUPMRule, SkMatrix::I()));
        sk_sp<GrFragmentProcessor> upmToPM(new GrConfigConversionEffect(
                readDC->asTexture().get(), GrSwizzle::RGBA(), *upmToPMRule, SkMatrix::I()));
        sk_sp<GrFragmentProcessor> pmToUPM2(new GrConfigConversionEffect(
                tempDC->asTexture().get(), GrSwizzle::RGBA(), *pmToUPMRule, SkMatrix::I()));

        paint1.addColorFragmentProcessor(std::move(pmToUPM1));
        paint1.setPorterDuffXPFactory(SkXfermode::kSrc_Mode);

        readDC->fillRectToRect(GrNoClip(), paint1, SkMatrix::I(), kDstRect, kSrcRect);

        readDC->asTexture()->readPixels(0, 0, kSize, kSize, kConfig, firstRead);

        paint2.addColorFragmentProcessor(std::move(upmToPM));
        paint2.setPorterDuffXPFactory(SkXfermode::kSrc_Mode);

        tempDC->fillRectToRect(GrNoClip(), paint2, SkMatrix::I(), kDstRect, kSrcRect);

        paint3.addColorFragmentProcessor(std::move(pmToUPM2));
        paint3.setPorterDuffXPFactory(SkXfermode::kSrc_Mode);

        readDC->fillRectToRect(GrNoClip(), paint3, SkMatrix::I(), kDstRect, kSrcRect);

        readDC->asTexture()->readPixels(0, 0, kSize, kSize, kConfig, secondRead);

        failed = false;
        for (int y = 0; y < kSize && !failed; ++y) {
            for (int x = 0; x <= y; ++x) {
                if (firstRead[kSize * y + x] != secondRead[kSize * y + x]) {
                    failed = true;
                    break;
                }
            }
        }
    }
    if (failed) {
        *pmToUPMRule = kNone_PMConversion;
        *upmToPMRule = kNone_PMConversion;
    }
}
Example #3
0
void  CProfileGraphDlg::fillGraphLine( HTREEITEM hTreeSel )
{
	// get client rect
	CRect  rectTemp;

	m_GraphLine.GetClientRect(&rectTemp);


	// create graph line
	CClientDC tempDC( &m_GraphLine );
	CBitmap*  tempBitmap = NULL;

	m_CompatibleDC.DeleteDC();
	m_CompatibleBitmap.DeleteObject();

	m_CompatibleDC.CreateCompatibleDC( &tempDC );
	m_CompatibleBitmap.CreateCompatibleBitmap( &tempDC, rectTemp.Width(), rectTemp.Height() );

	tempBitmap = m_CompatibleDC.SelectObject( &m_CompatibleBitmap );

	m_CompatibleDC.SetBkColor( RGB( 255, 255, 255 ) );
	m_CompatibleDC.SelectStockObject( WHITE_BRUSH );
	m_CompatibleDC.Rectangle( &rectTemp );
	
	m_CompatibleDC.SelectStockObject( BLACK_BRUSH );
	m_CompatibleDC.MoveTo( 0, 0 );
	m_CompatibleDC.LineTo( rectTemp.Width(), 0 );
	m_CompatibleDC.LineTo( rectTemp.Width(), rectTemp.Height() );
	m_CompatibleDC.LineTo( 0, rectTemp.Height() );
	m_CompatibleDC.LineTo( 0, 0 );



	// draw graph line
	DWORD_PTR itemData = m_treeGraphCall.GetItemData( hTreeSel );
	CProfileGraphNode* pNode = m_GraphDoc.GetNodeByIndex( static_cast< UINT >( itemData ) );

	if ( NULL != pNode )
	{
		// insert seg
		static COLORREF colorTable[] = {
			0x0000CC00, 0x00FF0000, 0x00CCCC00, 0x000000FF,
			0x000000CC, 0x0000FF00,	0x00FF00FF, 0x00CC00CC,
            0x00CC0000,	0x0000FFFF, 0x0000CCCC, 0x00FFFF00
		};



		float frameFreq = 1;//rectStatic.Width() / m_GraphDoc.GetFrameNumber();
		float timeFreq = 2;//rectStatic.Height() / 1000;
		int   offLeft = 5;
		int   offTop = -5;

		for ( int frame = 0; frame < m_GraphDoc.GetFrameNumber(); ++ frame )
		{
			// push back
			typedef std::vector< GraphSort_t >	SortVector_t;
			SortVector_t	sortVector;
			int   i = 0;

			for ( CProfileGraphNode* pChild = pNode->GetChildPtr(); 
				NULL != pChild; 
				pChild = pChild->GetSiblingPtr(), ++ i
				)
			{
				float firstTime = m_GraphDoc.GetFrameNodeTime( frame == 0 ? 0 : frame - 1, pChild->GetCounter() );
				float curTime = m_GraphDoc.GetFrameNodeTime( frame, pChild->GetCounter() );

				sortVector.push_back( GraphSort_t( i, curTime - firstTime ) );
			}


			// sort graph
			std::sort( sortVector.begin(), sortVector.end(), SortCompare_Graph );
			for ( SortVector_t::iterator iter  = sortVector.begin();
										 iter != sortVector.end();
										 ++ iter 
										 )
			{
				int x = frame * frameFreq + offLeft;
				int y = rectTemp.Height() - iter->time * timeFreq + offTop;

				//m_CompatibleDC.SetPixel( x, y, colorTable[i] );
				CPen  tempPen( PS_SOLID, 1, colorTable[iter->color] );
				CPen* pOldPen = NULL;

				pOldPen = m_CompatibleDC.SelectObject( &tempPen );
				m_CompatibleDC.MoveTo( x, rectTemp.Height() );
				m_CompatibleDC.LineTo( x, y );
				m_CompatibleDC.SelectObject( pOldPen );
			}

		}

	}


	tempDC.BitBlt( 0, 0, rectTemp.Width(), rectTemp.Height(), &m_CompatibleDC, 0, 0, SRCCOPY );
	m_CompatibleDC.SelectObject( tempBitmap );

}