Index: sky/compositor/layer.cc |
diff --git a/sky/compositor/layer.cc b/sky/compositor/layer.cc |
index 8d2ec8bc811276c8cc19093c7707a95ef7718221..23801c77cc81e475afb5e48e8daf9d9fa9df35ca 100644 |
--- a/sky/compositor/layer.cc |
+++ b/sky/compositor/layer.cc |
@@ -7,11 +7,16 @@ |
#include "base/debug/trace_event.h" |
#include "mojo/skia/ganesh_surface.h" |
#include "sky/compositor/layer_host.h" |
+#include "third_party/skia/include/core/SkBitmapDevice.h" |
#include "third_party/skia/include/core/SkCanvas.h" |
+#include "ui/gfx/codec/png_codec.h" |
namespace sky { |
-Layer::Layer(LayerClient* client) : client_(client), host_(nullptr) { |
+Layer::Layer(LayerClient* client, bool is_testing) |
+ : client_(client), |
+ host_(nullptr), |
+ is_testing_(is_testing) { |
} |
Layer::~Layer() { |
@@ -25,6 +30,14 @@ void Layer::SetSize(const gfx::Size& size) { |
size_ = size; |
} |
+std::string Layer::GetPixels() { |
+ std::vector<unsigned char> png_data; |
+ bool encoding_succeeded = gfx::PNGCodec::EncodeBGRASkBitmap(bitmap_, false, &png_data); |
+ if (encoding_succeeded) |
+ return std::string(reinterpret_cast<const char*>(&png_data[0]), png_data.size()); |
+ return std::string(); |
+} |
+ |
void Layer::Display() { |
TRACE_EVENT0("sky", "Layer::Display"); |
@@ -35,9 +48,21 @@ void Layer::Display() { |
SkCanvas* canvas = surface.canvas(); |
- gfx::Rect rect(size_); |
- client_->PaintContents(canvas, rect); |
- canvas->flush(); |
+ if (is_testing_) { |
+ bitmap_.reset(); |
+ bitmap_.allocN32Pixels(size_.width(), size_.height()); |
+ SkBitmapDevice device(bitmap_); |
+ SkCanvas bitmapCanvas(&device); |
+ |
+ gfx::Rect bitmapRect(size_); |
+ bitmapCanvas.drawColor(SK_ColorRED); |
ojan
2014/12/12 03:48:39
This lets us see if if we don't paint at all. Not
|
+ client_->PaintContents(&bitmapCanvas, bitmapRect); |
+ bitmapCanvas.flush(); |
+ } else { |
+ gfx::Rect rect(size_); |
+ client_->PaintContents(canvas, rect); |
+ canvas->flush(); |
+ } |
texture_ = surface.TakeTexture(); |
} |