// Copyright © 2010-2017 The CefSharp Authors. All rights reserved.
//
// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
using System;
using System.Drawing;
using System.Drawing.Imaging;
using CefSharp.Internals;
namespace CefSharp.OffScreen
{
///
/// Uses GdiBitmap to render the backbuffer.
///
///
public class GdiBitmapInfo : BitmapInfo
{
///
/// The bitmap
///
private Bitmap bitmap;
///
/// The create new bitmap
///
private bool createNewBitmap;
///
/// Initializes a new instance of the class.
///
public GdiBitmapInfo()
{
BytesPerPixel = 4;
}
///
/// Gets a value indicating whether [create new bitmap].
///
/// true if [create new bitmap]; otherwise, false.
public override bool CreateNewBitmap
{
get { return createNewBitmap; }
}
///
/// Clears the bitmap.
///
public override void ClearBitmap()
{
createNewBitmap = true;
}
///
/// Creates the bitmap.
///
/// Bitmap.
public virtual Bitmap CreateBitmap()
{
if(BackBufferHandle == IntPtr.Zero)
{
return null;
}
var stride = Width * BytesPerPixel;
bitmap = new Bitmap(Width, Height, stride, PixelFormat.Format32bppPArgb, BackBufferHandle);
createNewBitmap = false;
return bitmap;
}
}
}