PlatformCALayer.cpp [plain text]
#include "config.h"
#include "LayerPool.h"
#include "PlatformCALayer.h"
#include <wtf/StringExtras.h>
#if USE(CA)
namespace WebCore {
static GraphicsLayer::PlatformLayerID generateLayerID()
{
static GraphicsLayer::PlatformLayerID layerID;
return ++layerID;
}
#if COMPILER(MSVC)
const float PlatformCALayer::webLayerWastedSpaceThreshold = 0.75f;
#endif
PlatformCALayer::PlatformCALayer(LayerType layerType, PlatformCALayerClient* owner)
: m_layerType(layerType)
, m_layerID(generateLayerID())
, m_owner(owner)
{
}
PlatformCALayer::~PlatformCALayer()
{
setOwner(nullptr);
}
void PlatformCALayer::drawRepaintIndicator(CGContextRef context, PlatformCALayer* platformCALayer, int repaintCount, CGColorRef customBackgroundColor)
{
char text[16]; snprintf(text, sizeof(text), "%d", repaintCount);
CGRect indicatorBox = platformCALayer->bounds();
indicatorBox.size.width = 12 + 10 * strlen(text);
indicatorBox.size.height = 27;
CGContextSaveGState(context);
CGContextSetAlpha(context, 0.5f);
CGContextBeginTransparencyLayerWithRect(context, indicatorBox, 0);
if (customBackgroundColor)
CGContextSetFillColorWithColor(context, customBackgroundColor);
else
CGContextSetRGBFillColor(context, 0, 0.5f, 0.25f, 1);
CGContextFillRect(context, indicatorBox);
if (platformCALayer->acceleratesDrawing())
CGContextSetRGBFillColor(context, 1, 0, 0, 1);
else
CGContextSetRGBFillColor(context, 1, 1, 1, 1);
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
CGContextSetTextMatrix(context, CGAffineTransformMakeScale(1, -1));
CGContextSelectFont(context, "Helvetica", 22, kCGEncodingMacRoman);
CGContextShowTextAtPoint(context, indicatorBox.origin.x + 5, indicatorBox.origin.y + 22, text, strlen(text));
#pragma clang diagnostic pop
CGContextEndTransparencyLayer(context);
CGContextRestoreGState(context);
}
PassRefPtr<PlatformCALayer> PlatformCALayer::createCompatibleLayerOrTakeFromPool(PlatformCALayer::LayerType layerType, PlatformCALayerClient* client, IntSize size)
{
RefPtr<PlatformCALayer> layer;
if ((layer = layerPool().takeLayerWithSize(size))) {
layer->setOwner(client);
return layer.release();
}
layer = createCompatibleLayer(layerType, client);
layer->setBounds(FloatRect(FloatPoint(), size));
return layer.release();
}
void PlatformCALayer::moveToLayerPool()
{
ASSERT(!superlayer());
layerPool().addLayer(this);
}
LayerPool& PlatformCALayer::layerPool()
{
static LayerPool* sharedPool = new LayerPool;
return *sharedPool;
}
}
#endif // USE(CA)