提交 5607ac31 编写于 作者: C Chinmay Garde

Allow images rasterized by the picture rasterizer to be highlighted for debugging purposes

上级 f9eadec6
......@@ -12,6 +12,9 @@ source_set("compositor") {
"clip_rrect_layer.h",
"color_filter_layer.cc",
"color_filter_layer.h",
"compositor_config.h",
"compositor_tools.cc",
"compositor_tools.h",
"container_layer.cc",
"container_layer.h",
"layer.cc",
......
// 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.
#ifndef SKY_COMPOSITOR_COMPOSITOR_CONFIG_H_
#define SKY_COMPOSITOR_COMPOSITOR_CONFIG_H_
// SkPictures that dont mutate from frame to frame are rasterized by the picture
// rasterizer. This guard enables highlighting the rasterized images. Useful
// when debugging caching
#define COMPOSITOR_HIGHLIGHT_RASTERIZED_PICTURES 0
#endif // SKY_COMPOSITOR_COMPOSITOR_CONFIG_H_
// 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 "sky/compositor/compositor_tools.h"
#include "third_party/skia/include/core/SkShader.h"
namespace sky {
namespace compositor {
static SkShader* CreateCheckerboardShader(SkColor c1, SkColor c2, int size) {
SkBitmap bm;
bm.allocN32Pixels(2 * size, 2 * size);
bm.eraseColor(c1);
bm.eraseArea(SkIRect::MakeLTRB(0, 0, size, size), c2);
bm.eraseArea(SkIRect::MakeLTRB(size, size, 2 * size, 2 * size), c2);
return SkShader::CreateBitmapShader(bm, SkShader::kRepeat_TileMode,
SkShader::kRepeat_TileMode);
}
static void DrawCheckerboard(SkCanvas* canvas,
SkColor c1,
SkColor c2,
int size) {
SkPaint paint;
paint.setShader(CreateCheckerboardShader(c1, c2, size))->unref();
canvas->drawPaint(paint);
}
void DrawCheckerboard(SkCanvas* canvas, int width, int height) {
SkRect rect = SkRect::MakeIWH(width, height);
// Draw a checkerboard
canvas->clipRect(rect);
DrawCheckerboard(canvas, 0x9900FF00, 0x00000000, 12);
// Stroke the drawn area
SkPaint debugPaint;
debugPaint.setStrokeWidth(3);
debugPaint.setColor(SK_ColorRED);
debugPaint.setStyle(SkPaint::kStroke_Style);
canvas->drawRect(rect, debugPaint);
}
} // namespace compositor
} // namespace sky
// 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.
#ifndef SKY_COMPOSITOR_COMPOSITOR_TOOLS_H_
#define SKY_COMPOSITOR_COMPOSITOR_TOOLS_H_
#include "third_party/skia/include/core/SkCanvas.h"
namespace sky {
namespace compositor {
void DrawCheckerboard(SkCanvas* canvas, int width, int height);
} // namespace compositor
} // namespace sky
#endif // SKY_COMPOSITOR_COMPOSITOR_TOOLS_H_
......@@ -2,6 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "sky/compositor/compositor_config.h"
#include "sky/compositor/compositor_tools.h"
#include "sky/compositor/picture_rasterizer.h"
#include "base/logging.h"
#include "third_party/skia/include/core/SkPicture.h"
......@@ -80,6 +82,10 @@ static RefPtr<SkImage> ImageFromPicture(GrContext* context,
canvas->drawPicture(picture);
#if COMPOSITOR_HIGHLIGHT_RASTERIZED_PICTURES
DrawCheckerboard(canvas, desc.fWidth, desc.fHeight);
#endif
// Step 4: Create an image representation from the texture
RefPtr<SkImage> image = adoptRef(SkImage::NewFromTexture(
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册