flutter_flutter/services/sky/compositor/rasterizer_bitmap.cc
Adam Barth 011ce5d8e7 Clear the frame to black before drawing
We used to do this in the SkPicture, but it's simpler to do it in the
rasterizer now that we're using multiple SkPictures in Dart.
2015-08-14 10:45:14 -07:00

43 lines
1.2 KiB
C++

// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "services/sky/compositor/rasterizer_bitmap.h"
#include "services/sky/compositor/layer_client.h"
#include "services/sky/compositor/layer_host.h"
#include "third_party/skia/include/core/SkBitmapDevice.h"
#include "third_party/skia/include/core/SkCanvas.h"
#include "third_party/skia/include/core/SkPicture.h"
#include "ui/gfx/codec/png_codec.h"
#include "ui/gfx/geometry/rect.h"
namespace sky {
RasterizerBitmap::RasterizerBitmap(LayerHost* host) : host_(host) {
DCHECK(host_);
}
RasterizerBitmap::~RasterizerBitmap() {
}
void RasterizerBitmap::GetPixelsForTesting(std::vector<unsigned char>* pixels) {
gfx::PNGCodec::EncodeBGRASkBitmap(bitmap_, true, pixels);
}
scoped_ptr<mojo::GLTexture> RasterizerBitmap::Rasterize(SkPicture* picture) {
auto size = picture->cullRect();
bitmap_.allocN32Pixels(size.width(), size.height());
SkBitmapDevice device(bitmap_);
SkCanvas canvas(&device);
canvas.clear(SK_ColorBLACK);
canvas.drawPicture(picture);
canvas.flush();
return host_->resource_manager()->CreateTexture(
gfx::Size(size.width(), size.height()));
}
} // namespace sky