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