Bug 587856 - Part 1: Expose D2D surface VRAM usage from cairo device. r=jrmuizel

This commit is contained in:
Bas Schouten 2010-08-18 05:43:49 +02:00
Родитель cf903af326
Коммит cc3f37176a
3 изменённых файлов: 33 добавлений и 0 удалений

Просмотреть файл

@ -68,6 +68,7 @@ struct _cairo_d2d_device
RefPtr<ID3D10Buffer> mQuadBuffer;
RefPtr<ID3D10RasterizerState> mRasterizerState;
RefPtr<ID3D10BlendState> mBlendStates[MAX_OPERATORS];
int mVRAMUsage;
};
typedef struct _cairo_d2d_device cairo_d2d_device_t;

Просмотреть файл

@ -243,6 +243,7 @@ cairo_d2d_create_device_from_d3d10device(ID3D10Device1 *d3d10device)
goto FAILED;
}
device->base.refcount = 1;
device->mVRAMUsage = 0;
return &device->base;
FAILED:
@ -696,6 +697,14 @@ _cairo_d2d_round_out_to_int_rect(cairo_rectangle_int_t *rect, double x1, double
rect->height = (int)ceil(y2) - rect->y;
}
static int
_cairo_d2d_compute_surface_mem_size(cairo_d2d_surface_t *surface)
{
int size = surface->rt->GetPixelSize().width * surface->rt->GetPixelSize().height;
size *= surface->rt->GetPixelFormat().format == DXGI_FORMAT_A8_UNORM ? 1 : 4;
return size;
}
/**
* Gets the surface buffer texture for window surfaces whose backbuffer
* is not directly usable as a bitmap.
@ -716,6 +725,7 @@ _cairo_d2d_get_buffer_texture(cairo_d2d_surface_t *surface)
softDesc.Usage = D3D10_USAGE_DEFAULT;
softDesc.BindFlags = D3D10_BIND_RENDER_TARGET | D3D10_BIND_SHADER_RESOURCE;
surface->device->mD3D10Device->CreateTexture2D(&softDesc, NULL, &surface->bufferTexture);
surface->device->mVRAMUsage += _cairo_d2d_compute_surface_mem_size(surface);
}
return surface->bufferTexture;
}
@ -2354,6 +2364,7 @@ _cairo_d2d_create_similar(void *surface,
newSurf->device = d2dsurf->device;
cairo_addref_device(&newSurf->device->base);
newSurf->device->mVRAMUsage += _cairo_d2d_compute_surface_mem_size(newSurf);
return reinterpret_cast<cairo_surface_t*>(newSurf);
@ -2369,6 +2380,11 @@ _cairo_d2d_finish(void *surface)
{
cairo_d2d_surface_t *d2dsurf = static_cast<cairo_d2d_surface_t*>(surface);
d2dsurf->device->mVRAMUsage -= _cairo_d2d_compute_surface_mem_size(d2dsurf);
if (d2dsurf->bufferTexture) {
d2dsurf->device->mVRAMUsage -= _cairo_d2d_compute_surface_mem_size(d2dsurf);
}
reset_clip(d2dsurf);
cairo_release_device(&d2dsurf->device->base);
@ -3398,6 +3414,7 @@ cairo_d2d_surface_create_for_hwnd(cairo_device_t *cairo_device,
newSurf->device = d2d_device;
cairo_addref_device(cairo_device);
d2d_device->mVRAMUsage += _cairo_d2d_compute_surface_mem_size(newSurf);
return reinterpret_cast<cairo_surface_t*>(newSurf);
@ -3507,6 +3524,7 @@ cairo_d2d_surface_create(cairo_device_t *device,
newSurf->device = d2d_device;
cairo_addref_device(device);
d2d_device->mVRAMUsage += _cairo_d2d_compute_surface_mem_size(newSurf);
return reinterpret_cast<cairo_surface_t*>(newSurf);
@ -3752,3 +3770,10 @@ cairo_d2d_get_image_surface_cache_usage()
{
return _cairo_atomic_int_get(&cache_usage);
}
int
cairo_d2d_get_surface_vram_usage(cairo_device_t *device)
{
cairo_d2d_device_t *d2d_device = reinterpret_cast<cairo_d2d_device_t*>(device);
return d2d_device->mVRAMUsage;
}

Просмотреть файл

@ -258,6 +258,13 @@ void cairo_d2d_release_dc(cairo_surface_t *surcace, const cairo_rectangle_int_t
* internal image surface cache.
*/
int cairo_d2d_get_image_surface_cache_usage();
/**
* Get an estimate of the amount of VRAM which is currently used by the d2d
* surfaces for a device. This does -not- include the internal image surface
* cache.
*/
int cairo_d2d_get_surface_vram_usage(cairo_device_t *device);
#endif
CAIRO_END_DECLS