| 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" | 8 #include "mojo/skia/ganesh_surface.h" |
| 9 #include "sky/compositor/display_delegate.h" |
| 9 #include "sky/compositor/layer_host.h" | 10 #include "sky/compositor/layer_host.h" |
| 10 #include "third_party/skia/include/core/SkCanvas.h" | 11 #include "third_party/skia/include/core/SkCanvas.h" |
| 11 | 12 |
| 12 namespace sky { | 13 namespace sky { |
| 13 | 14 |
| 14 Layer::Layer(LayerClient* client) : client_(client), host_(nullptr) { | 15 Layer::Layer(LayerClient* client) |
| 16 : client_(client), |
| 17 host_(nullptr) { |
| 18 delegate_.reset(DisplayDelegate::create(client)); |
| 15 } | 19 } |
| 16 | 20 |
| 17 Layer::~Layer() { | 21 Layer::~Layer() { |
| 18 } | 22 } |
| 19 | 23 |
| 20 void Layer::ClearClient() { | |
| 21 client_ = nullptr; | |
| 22 } | |
| 23 | |
| 24 void Layer::SetSize(const gfx::Size& size) { | 24 void Layer::SetSize(const gfx::Size& size) { |
| 25 size_ = size; | 25 size_ = size; |
| 26 } | 26 } |
| 27 | 27 |
| 28 void Layer::GetPixelsForTesting(std::vector<unsigned char>* pixels) { |
| 29 delegate_->GetPixelsForTesting(pixels); |
| 30 } |
| 31 |
| 28 void Layer::Display() { | 32 void Layer::Display() { |
| 29 TRACE_EVENT0("sky", "Layer::Display"); | 33 TRACE_EVENT0("sky", "Layer::Display"); |
| 30 | 34 |
| 31 DCHECK(host_); | 35 DCHECK(host_); |
| 32 | 36 |
| 33 mojo::GaneshSurface surface(host_->ganesh_context(), | 37 mojo::GaneshSurface surface(host_->ganesh_context(), |
| 34 host_->resource_manager()->CreateTexture(size_)); | 38 host_->resource_manager()->CreateTexture(size_)); |
| 35 | 39 |
| 36 SkCanvas* canvas = surface.canvas(); | |
| 37 | |
| 38 gfx::Rect rect(size_); | 40 gfx::Rect rect(size_); |
| 39 client_->PaintContents(canvas, rect); | 41 delegate_->Paint(surface, rect); |
| 40 canvas->flush(); | |
| 41 | 42 |
| 42 texture_ = surface.TakeTexture(); | 43 texture_ = surface.TakeTexture(); |
| 43 } | 44 } |
| 44 | 45 |
| 45 scoped_ptr<mojo::GLTexture> Layer::GetTexture() { | 46 scoped_ptr<mojo::GLTexture> Layer::GetTexture() { |
| 46 return texture_.Pass(); | 47 return texture_.Pass(); |
| 47 } | 48 } |
| 48 | 49 |
| 49 } // namespace sky | 50 } // namespace sky |
| OLD | NEW |