This source file includes following definitions.
- Create
- CreateLayerImpl
- DrawsContent
- SetBitmap
- PaintContents
- FillsBoundsCompletely
#include "cc/layers/picture_image_layer.h"
#include "cc/layers/picture_image_layer_impl.h"
#include "third_party/skia/include/core/SkCanvas.h"
namespace cc {
scoped_refptr<PictureImageLayer> PictureImageLayer::Create() {
return make_scoped_refptr(new PictureImageLayer());
}
PictureImageLayer::PictureImageLayer() : PictureLayer(this) {}
PictureImageLayer::~PictureImageLayer() {
ClearClient();
}
scoped_ptr<LayerImpl> PictureImageLayer::CreateLayerImpl(
LayerTreeImpl* tree_impl) {
return PictureImageLayerImpl::Create(tree_impl, id()).PassAs<LayerImpl>();
}
bool PictureImageLayer::DrawsContent() const {
return !bitmap_.isNull() && PictureLayer::DrawsContent();
}
void PictureImageLayer::SetBitmap(const SkBitmap& bitmap) {
if (bitmap.pixelRef() && bitmap.pixelRef() == bitmap_.pixelRef())
return;
bitmap_ = bitmap;
SetNeedsDisplay();
}
void PictureImageLayer::PaintContents(SkCanvas* canvas,
const gfx::Rect& clip,
gfx::RectF* opaque) {
if (!canvas || !bitmap_.width() || !bitmap_.height())
return;
SkScalar content_to_layer_scale_x =
SkFloatToScalar(static_cast<float>(bounds().width()) / bitmap_.width());
SkScalar content_to_layer_scale_y =
SkFloatToScalar(static_cast<float>(bounds().height()) / bitmap_.height());
canvas->scale(content_to_layer_scale_x, content_to_layer_scale_y);
SkPaint paint;
paint.setXfermodeMode(SkXfermode::kSrc_Mode);
canvas->drawBitmap(bitmap_, 0, 0, &paint);
}
bool PictureImageLayer::FillsBoundsCompletely() const {
return true;
}
}