| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "sky/compositor/layer.h" | 5 #include "sky/compositor/layer.h" |
| 6 | 6 |
| 7 #include "base/debug/trace_event.h" | 7 #include "base/debug/trace_event.h" |
| 8 #include "mojo/skia/ganesh_surface.h" | |
| 9 #include "sky/compositor/display_delegate.h" | |
| 10 #include "sky/compositor/layer_host.h" | 8 #include "sky/compositor/layer_host.h" |
| 9 #include "sky/compositor/rasterizer.h" |
| 11 #include "third_party/skia/include/core/SkCanvas.h" | 10 #include "third_party/skia/include/core/SkCanvas.h" |
| 11 #include "third_party/skia/include/core/SkPictureRecorder.h" |
| 12 | 12 |
| 13 namespace sky { | 13 namespace sky { |
| 14 | 14 |
| 15 Layer::Layer(LayerClient* client) | 15 Layer::Layer(LayerClient* client) : client_(client) { |
| 16 : client_(client), | |
| 17 host_(nullptr) { | |
| 18 delegate_.reset(DisplayDelegate::create(client)); | |
| 19 } | 16 } |
| 20 | 17 |
| 21 Layer::~Layer() { | 18 Layer::~Layer() { |
| 22 } | 19 } |
| 23 | 20 |
| 24 void Layer::SetSize(const gfx::Size& size) { | 21 void Layer::SetSize(const gfx::Size& size) { |
| 25 size_ = size; | 22 size_ = size; |
| 26 } | 23 } |
| 27 | 24 |
| 28 void Layer::GetPixelsForTesting(std::vector<unsigned char>* pixels) { | |
| 29 delegate_->GetPixelsForTesting(pixels); | |
| 30 } | |
| 31 | |
| 32 void Layer::Display() { | 25 void Layer::Display() { |
| 33 TRACE_EVENT0("sky", "Layer::Display"); | 26 TRACE_EVENT0("sky", "Layer::Display"); |
| 27 DCHECK(rasterizer_); |
| 28 auto picture = RecordPicture(); |
| 29 texture_ = rasterizer_->Rasterize(picture.get()); |
| 30 } |
| 34 | 31 |
| 35 DCHECK(host_); | 32 skia::RefPtr<SkPicture> Layer::RecordPicture() { |
| 33 TRACE_EVENT0("sky", "Layer::RecordPicture"); |
| 36 | 34 |
| 37 mojo::GaneshSurface surface(host_->ganesh_context(), | 35 SkRTreeFactory factory; |
| 38 host_->resource_manager()->CreateTexture(size_)); | 36 SkPictureRecorder recorder; |
| 39 | 37 |
| 40 gfx::Rect rect(size_); | 38 auto canvas = skia::SharePtr(recorder.beginRecording( |
| 41 delegate_->Paint(surface, rect); | 39 size_.width(), size_.height(), &factory, |
| 40 SkPictureRecorder::kComputeSaveLayerInfo_RecordFlag)); |
| 42 | 41 |
| 43 texture_ = surface.TakeTexture(); | 42 client_->PaintContents(canvas.get(), gfx::Rect(size_)); |
| 43 return skia::AdoptRef(recorder.endRecordingAsPicture()); |
| 44 } | 44 } |
| 45 | 45 |
| 46 scoped_ptr<mojo::GLTexture> Layer::GetTexture() { | 46 scoped_ptr<mojo::GLTexture> Layer::GetTexture() { |
| 47 return texture_.Pass(); | 47 return texture_.Pass(); |
| 48 } | 48 } |
| 49 | 49 |
| 50 } // namespace sky | 50 } // namespace sky |
| OLD | NEW |