Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(43)

Side by Side Diff: sky/compositor/layer.cc

Issue 797063002: Make reftests work for sky. (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: cleanup Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/layer_host.h" 9 #include "sky/compositor/layer_host.h"
10 #include "third_party/skia/include/core/SkBitmapDevice.h"
10 #include "third_party/skia/include/core/SkCanvas.h" 11 #include "third_party/skia/include/core/SkCanvas.h"
12 #include "ui/gfx/codec/png_codec.h"
11 13
12 namespace sky { 14 namespace sky {
13 15
14 Layer::Layer(LayerClient* client) : client_(client), host_(nullptr) { 16 Layer::Layer(LayerClient* client, bool is_testing)
17 : client_(client),
18 host_(nullptr),
19 is_testing_(is_testing) {
15 } 20 }
16 21
17 Layer::~Layer() { 22 Layer::~Layer() {
18 } 23 }
19 24
20 void Layer::ClearClient() { 25 void Layer::ClearClient() {
21 client_ = nullptr; 26 client_ = nullptr;
22 } 27 }
23 28
24 void Layer::SetSize(const gfx::Size& size) { 29 void Layer::SetSize(const gfx::Size& size) {
25 size_ = size; 30 size_ = size;
26 } 31 }
27 32
33 std::string Layer::GetPixelsForTesting() {
esprehn 2014/12/11 23:18:59 Returning a string is weird, I'd return either a v
ojan 2014/12/13 00:18:33 I made it a std::vector<unsigned char> that you pa
34 DCHECK(is_testing_);
35
36 std::vector<unsigned char> png_data;
37 bool encoding_succeeded = gfx::PNGCodec::EncodeBGRASkBitmap(bitmap_, false, &p ng_data);
38 if (encoding_succeeded)
39 return std::string(reinterpret_cast<const char*>(&png_data[0]), png_data.siz e());
40 return std::string();
41 }
42
28 void Layer::Display() { 43 void Layer::Display() {
29 TRACE_EVENT0("sky", "Layer::Display"); 44 TRACE_EVENT0("sky", "Layer::Display");
30 45
31 DCHECK(host_); 46 DCHECK(host_);
32 47
33 mojo::GaneshSurface surface(host_->ganesh_context(), 48 mojo::GaneshSurface surface(host_->ganesh_context(),
34 host_->resource_manager()->CreateTexture(size_)); 49 host_->resource_manager()->CreateTexture(size_));
35 50
36 SkCanvas* canvas = surface.canvas(); 51 SkCanvas* canvas = surface.canvas();
37 52
38 gfx::Rect rect(size_); 53 if (is_testing_) {
esprehn 2014/12/11 23:18:59 Instead I think you want a LayerDelegate interface
ojan 2014/12/13 00:18:33 Done.
39 client_->PaintContents(canvas, rect); 54 bitmap_.reset();
40 canvas->flush(); 55 bitmap_.allocN32Pixels(size_.width(), size_.height());
56 SkBitmapDevice device(bitmap_);
57 SkCanvas bitmapCanvas(&device);
58
59 gfx::Rect bitmapRect(size_);
60 bitmapCanvas.drawColor(SK_ColorRED);
61 client_->PaintContents(&bitmapCanvas, bitmapRect);
62 bitmapCanvas.flush();
63 } else {
64 gfx::Rect rect(size_);
65 client_->PaintContents(canvas, rect);
66 canvas->flush();
67 }
41 68
42 texture_ = surface.TakeTexture(); 69 texture_ = surface.TakeTexture();
43 } 70 }
44 71
45 scoped_ptr<mojo::GLTexture> Layer::GetTexture() { 72 scoped_ptr<mojo::GLTexture> Layer::GetTexture() {
46 return texture_.Pass(); 73 return texture_.Pass();
47 } 74 }
48 75
49 } // namespace sky 76 } // namespace sky
OLDNEW
« no previous file with comments | « sky/compositor/layer.h ('k') | sky/compositor/layer_host.h » ('j') | sky/tools/tester/tester.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698