OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "sky/compositor/layer.h" | |
6 | |
7 #include "base/trace_event/trace_event.h" | |
8 #include "sky/compositor/layer_host.h" | |
9 #include "sky/compositor/picture_serializer.h" | |
10 #include "sky/compositor/rasterizer.h" | |
11 #include "third_party/skia/include/core/SkCanvas.h" | |
12 #include "third_party/skia/include/core/SkPictureRecorder.h" | |
13 | |
14 namespace sky { | |
15 | |
16 Layer::Layer(LayerClient* client) : client_(client) { | |
17 } | |
18 | |
19 Layer::~Layer() { | |
20 } | |
21 | |
22 void Layer::SetSize(const gfx::Size& size) { | |
23 size_ = size; | |
24 } | |
25 | |
26 void Layer::Display() { | |
27 TRACE_EVENT0("sky", "Layer::Display"); | |
28 DCHECK(rasterizer_); | |
29 auto picture = RecordPicture(); | |
30 | |
31 #if 0 | |
32 SerializePicture( | |
33 "/data/data/org.chromium.mojo.shell/cache/layer0.skp", picture.get()); | |
34 #endif | |
35 | |
36 texture_ = rasterizer_->Rasterize(picture.get()); | |
37 } | |
38 | |
39 skia::RefPtr<SkPicture> Layer::RecordPicture() { | |
40 TRACE_EVENT0("sky", "Layer::RecordPicture"); | |
41 | |
42 SkRTreeFactory factory; | |
43 SkPictureRecorder recorder; | |
44 | |
45 auto canvas = skia::SharePtr(recorder.beginRecording( | |
46 size_.width(), size_.height(), &factory, | |
47 SkPictureRecorder::kComputeSaveLayerInfo_RecordFlag)); | |
48 | |
49 client_->PaintContents(canvas.get(), gfx::Rect(size_)); | |
50 return skia::AdoptRef(recorder.endRecordingAsPicture()); | |
51 } | |
52 | |
53 scoped_ptr<mojo::GLTexture> Layer::GetTexture() { | |
54 return texture_.Pass(); | |
55 } | |
56 | |
57 } // namespace sky | |
OLD | NEW |