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

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: 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::GetPixels() {
34 std::vector<unsigned char> png_data;
35 bool encoding_succeeded = gfx::PNGCodec::EncodeBGRASkBitmap(bitmap_, false, &p ng_data);
36 if (encoding_succeeded)
37 return std::string(reinterpret_cast<const char*>(&png_data[0]), png_data.siz e());
38 return std::string();
39 }
40
28 void Layer::Display() { 41 void Layer::Display() {
29 TRACE_EVENT0("sky", "Layer::Display"); 42 TRACE_EVENT0("sky", "Layer::Display");
30 43
31 DCHECK(host_); 44 DCHECK(host_);
32 45
33 mojo::GaneshSurface surface(host_->ganesh_context(), 46 mojo::GaneshSurface surface(host_->ganesh_context(),
34 host_->resource_manager()->CreateTexture(size_)); 47 host_->resource_manager()->CreateTexture(size_));
35 48
36 SkCanvas* canvas = surface.canvas(); 49 SkCanvas* canvas = surface.canvas();
37 50
38 gfx::Rect rect(size_); 51 if (is_testing_) {
39 client_->PaintContents(canvas, rect); 52 bitmap_.reset();
40 canvas->flush(); 53 bitmap_.allocN32Pixels(size_.width(), size_.height());
54 SkBitmapDevice device(bitmap_);
55 SkCanvas bitmapCanvas(&device);
56
57 gfx::Rect bitmapRect(size_);
58 bitmapCanvas.drawColor(SK_ColorRED);
ojan 2014/12/12 03:48:39 This lets us see if if we don't paint at all. Not
59 client_->PaintContents(&bitmapCanvas, bitmapRect);
60 bitmapCanvas.flush();
61 } else {
62 gfx::Rect rect(size_);
63 client_->PaintContents(canvas, rect);
64 canvas->flush();
65 }
41 66
42 texture_ = surface.TakeTexture(); 67 texture_ = surface.TakeTexture();
43 } 68 }
44 69
45 scoped_ptr<mojo::GLTexture> Layer::GetTexture() { 70 scoped_ptr<mojo::GLTexture> Layer::GetTexture() {
46 return texture_.Pass(); 71 return texture_.Pass();
47 } 72 }
48 73
49 } // namespace sky 74 } // 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