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

Side by Side Diff: sky/shell/gpu/rasterizer.cc

Issue 936883002: Connect Sky and Ganesh in SkyShell (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: sort includes Created 5 years, 10 months 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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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/shell/gpu/rasterizer.h" 5 #include "sky/shell/gpu/rasterizer.h"
6 6
7 #include "sky/shell/gpu/ganesh_context.h" 7 #include "sky/shell/gpu/ganesh_context.h"
8 #include "sky/shell/gpu/ganesh_surface.h" 8 #include "sky/shell/gpu/ganesh_surface.h"
9 #include "third_party/skia/include/core/SkCanvas.h" 9 #include "third_party/skia/include/core/SkCanvas.h"
10 #include "third_party/skia/include/core/SkPicture.h" 10 #include "third_party/skia/include/core/SkPicture.h"
11 #include "ui/gl/gl_bindings.h" 11 #include "ui/gl/gl_bindings.h"
12 #include "ui/gl/gl_context.h" 12 #include "ui/gl/gl_context.h"
13 #include "ui/gl/gl_share_group.h" 13 #include "ui/gl/gl_share_group.h"
14 #include "ui/gl/gl_surface.h" 14 #include "ui/gl/gl_surface.h"
15 15
16 namespace sky { 16 namespace sky {
17 namespace shell { 17 namespace shell {
18 namespace { 18 namespace {
19 19
20 gfx::Size GetSize(SkPicture* picture) { 20 gfx::Size GetSize(SkPicture* picture) {
21 const SkRect& rect = picture->cullRect(); 21 const SkRect& rect = picture->cullRect();
22 return gfx::Size(rect.width(), rect.height()); 22 return gfx::Size(rect.width(), rect.height());
23 } 23 }
24 24
25 } // namespace 25 } // namespace
26 26
27 Rasterizer::Rasterizer() : weak_factory_(this) { 27 Rasterizer::Rasterizer()
28 : share_group_(new gfx::GLShareGroup()),
29 weak_factory_(this) {
28 } 30 }
29 31
30 Rasterizer::~Rasterizer() { 32 Rasterizer::~Rasterizer() {
31 } 33 }
32 34
33 base::WeakPtr<Rasterizer> Rasterizer::GetWeakPtr() { 35 base::WeakPtr<Rasterizer> Rasterizer::GetWeakPtr() {
34 return weak_factory_.GetWeakPtr(); 36 return weak_factory_.GetWeakPtr();
35 } 37 }
36 38
37 void Rasterizer::OnAcceleratedWidgetAvailable(gfx::AcceleratedWidget widget) { 39 void Rasterizer::OnAcceleratedWidgetAvailable(gfx::AcceleratedWidget widget) {
38 share_group_ = make_scoped_refptr(new gfx::GLShareGroup());
39 surface_ = gfx::GLSurface::CreateViewGLSurface(widget); 40 surface_ = gfx::GLSurface::CreateViewGLSurface(widget);
40 CHECK(surface_) << "GLSurface required."; 41 CHECK(surface_) << "GLSurface required.";
41 CHECK(CreateGLContext()) << "GLContext required.";
42 } 42 }
43 43
44 void Rasterizer::Draw(skia::RefPtr<SkPicture> picture) { 44 void Rasterizer::Draw(skia::RefPtr<SkPicture> picture) {
45 // TODO(abarth): We should handle losing the GL context. 45 if (!surface_)
46 return;
47
48 EnsureGLContext();
46 CHECK(context_->MakeCurrent(surface_.get())); 49 CHECK(context_->MakeCurrent(surface_.get()));
47 EnsureGaneshSurface(GetSize(picture.get())); 50 EnsureGaneshSurface(GetSize(picture.get()));
48 51
49 SkCanvas* canvas = ganesh_surface_->canvas(); 52 SkCanvas* canvas = ganesh_surface_->canvas();
50 canvas->drawPicture(picture.get()); 53 canvas->drawPicture(picture.get());
51 canvas->flush(); 54 canvas->flush();
52 55
53 surface_->SwapBuffers(); 56 surface_->SwapBuffers();
54 } 57 }
55 58
56 void Rasterizer::OnOutputSurfaceDestroyed() { 59 void Rasterizer::OnOutputSurfaceDestroyed() {
60 ganesh_surface_.reset();
61 ganesh_context_.reset();
62 context_ = nullptr;
63 surface_ = nullptr;
57 } 64 }
58 65
59 bool Rasterizer::CreateGLContext() { 66 void Rasterizer::EnsureGLContext() {
67 if (context_)
68 return;
60 context_ = gfx::GLContext::CreateGLContext(share_group_.get(), surface_.get(), 69 context_ = gfx::GLContext::CreateGLContext(share_group_.get(), surface_.get(),
61 gfx::PreferIntegratedGpu); 70 gfx::PreferIntegratedGpu);
62 if (!context_) 71 CHECK(context_) << "GLContext required.";
63 return false; 72 CHECK(context_->MakeCurrent(surface_.get()));
64 ganesh_context_.reset(new GaneshContext(context_.get())); 73 ganesh_context_.reset(new GaneshContext(context_.get()));
65 return true;
66 } 74 }
67 75
68 void Rasterizer::EnsureGaneshSurface(const gfx::Size& size) { 76 void Rasterizer::EnsureGaneshSurface(const gfx::Size& size) {
69 if (!ganesh_surface_ || ganesh_surface_->size() != size) 77 if (!ganesh_surface_ || ganesh_surface_->size() != size)
70 ganesh_surface_.reset(new GaneshSurface(ganesh_context_.get(), size)); 78 ganesh_surface_.reset(new GaneshSurface(ganesh_context_.get(), size));
71 } 79 }
72 80
73 } // namespace shell 81 } // namespace shell
74 } // namespace sky 82 } // namespace sky
OLDNEW
« no previous file with comments | « sky/shell/gpu/rasterizer.h ('k') | sky/shell/gpu_delegate.h » ('j') | sky/shell/shell.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698