Firefox
In fact, cairo has a function to get DC from the surface of Cairo. Code example:
VOID OnPaint(HWND hwnd, HDC hdc)
{
RECT rc;
::GetClientRect(hwnd, &rc);
cairo_surface_t* surface = cairo_win32_surface_create(hdc);
cairo_t* cr = cairo_create(surface);
cairo_set_source_rgb(cr, 0xff, 0, 0);
cairo_set_line_width(cr, 1);
cairo_move_to(cr, 0, 0);
cairo_line_to(cr, rc.right, rc.bottom);
cairo_stroke(cr);
cairo_destroy(cr);
HDC hdcNew = cairo_win32_surface_get_dc(surface);
HTHEME hTheme = OpenThemeData(NULL, L"SCROLLBAR");
RECT rcArrow;
SetRect(&rcArrow, 30, 30, 45, 45);
DrawThemeBackground(hTheme, hdcNew, SBP_ARROWBTN, ABS_DOWNDISABLED, &rcArrow, NULL);
cairo_surface_destroy(surface);
}
gfxWindowsNativeDrawing::BeginNativeDrawing() HDC
gfxWindowsSurface::GetDCWithClip(gfxContext *ctx), , cairo win32.
Chrome
Skia skia canvas hdc, skia .
skia/ext/bitmap_platform_device_win.cc:
HDC BitmapPlatformDevice::BitmapPlatformDeviceData::GetBitmapDC() {
}
.
, , DC /skia canvas, .
:
void TestChromeExt(HWND hwnd, HDC hdc)
{
RECT rc;
GetClientRect(hwnd, &rc);
skia::BitmapPlatformDevice* pBmpDevice = skia::BitmapPlatformDevice::Create(rc.right, rc.bottom, true);
skia::PlatformCanvas *pCanvas = new skia::PlatformCanvas(pBmpDevice);
pCanvas->clear(SK_ColorWHITE);
SkPaint paint;
paint.setColor(SK_ColorRED);
paint.setStrokeWidth(3);
paint.setStyle(SkPaint::kStroke_Style);
pCanvas->drawLine(0, 0, rc.right, rc.bottom, paint);
HDC memdc = skia::BeginPlatformPaint(pCanvas);
RECT rcArrow;
SetRect(&rcArrow, 100, 200, 120, 220);
DrawThemeBackground(OpenThemeData(NULL, L"SCROLLBAR"), memdc, SBP_ARROWBTN, ABS_DOWNDISABLED, &rcArrow, NULL);
skia::EndPlatformPaint(pCanvas);
skia::DrawToNativeContext(pCanvas, hdc, 0, 0, &rc);
}
Windows, , , DrawThemeBackground. , ( ), DrawFrameControl .