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

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: Address review comments 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
« no previous file with comments | « sky/shell/gpu/rasterizer.h ('k') | sky/shell/gpu_delegate.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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()), weak_factory_(this) {
28 } 29 }
29 30
30 Rasterizer::~Rasterizer() { 31 Rasterizer::~Rasterizer() {
31 } 32 }
32 33
33 base::WeakPtr<Rasterizer> Rasterizer::GetWeakPtr() { 34 base::WeakPtr<Rasterizer> Rasterizer::GetWeakPtr() {
34 return weak_factory_.GetWeakPtr(); 35 return weak_factory_.GetWeakPtr();
35 } 36 }
36 37
37 void Rasterizer::OnAcceleratedWidgetAvailable(gfx::AcceleratedWidget widget) { 38 void Rasterizer::OnAcceleratedWidgetAvailable(gfx::AcceleratedWidget widget) {
38 share_group_ = make_scoped_refptr(new gfx::GLShareGroup());
39 surface_ = gfx::GLSurface::CreateViewGLSurface(widget); 39 surface_ = gfx::GLSurface::CreateViewGLSurface(widget);
40 CHECK(surface_) << "GLSurface required."; 40 CHECK(surface_) << "GLSurface required.";
41 CHECK(CreateGLContext()) << "GLContext required.";
42 } 41 }
43 42
44 void Rasterizer::Draw(skia::RefPtr<SkPicture> picture) { 43 void Rasterizer::Draw(skia::RefPtr<SkPicture> picture) {
45 // TODO(abarth): We should handle losing the GL context. 44 if (!surface_)
45 return;
46
47 EnsureGLContext();
46 CHECK(context_->MakeCurrent(surface_.get())); 48 CHECK(context_->MakeCurrent(surface_.get()));
47 EnsureGaneshSurface(GetSize(picture.get())); 49 EnsureGaneshSurface(GetSize(picture.get()));
48 50
49 SkCanvas* canvas = ganesh_surface_->canvas(); 51 SkCanvas* canvas = ganesh_surface_->canvas();
50 canvas->drawPicture(picture.get()); 52 canvas->drawPicture(picture.get());
51 canvas->flush(); 53 canvas->flush();
52 54
53 surface_->SwapBuffers(); 55 surface_->SwapBuffers();
54 } 56 }
55 57
56 void Rasterizer::OnOutputSurfaceDestroyed() { 58 void Rasterizer::OnOutputSurfaceDestroyed() {
59 ganesh_surface_.reset();
60 ganesh_context_.reset();
61 context_ = nullptr;
62 surface_ = nullptr;
57 } 63 }
58 64
59 bool Rasterizer::CreateGLContext() { 65 void Rasterizer::EnsureGLContext() {
66 if (context_)
67 return;
60 context_ = gfx::GLContext::CreateGLContext(share_group_.get(), surface_.get(), 68 context_ = gfx::GLContext::CreateGLContext(share_group_.get(), surface_.get(),
61 gfx::PreferIntegratedGpu); 69 gfx::PreferIntegratedGpu);
62 if (!context_) 70 CHECK(context_) << "GLContext required.";
63 return false; 71 CHECK(context_->MakeCurrent(surface_.get()));
64 ganesh_context_.reset(new GaneshContext(context_.get())); 72 ganesh_context_.reset(new GaneshContext(context_.get()));
65 return true;
66 } 73 }
67 74
68 void Rasterizer::EnsureGaneshSurface(const gfx::Size& size) { 75 void Rasterizer::EnsureGaneshSurface(const gfx::Size& size) {
69 if (!ganesh_surface_ || ganesh_surface_->size() != size) 76 if (!ganesh_surface_ || ganesh_surface_->size() != size)
70 ganesh_surface_.reset(new GaneshSurface(ganesh_context_.get(), size)); 77 ganesh_surface_.reset(new GaneshSurface(ganesh_context_.get(), size));
71 } 78 }
72 79
73 } // namespace shell 80 } // namespace shell
74 } // namespace sky 81 } // namespace sky
OLDNEW
« no previous file with comments | « sky/shell/gpu/rasterizer.h ('k') | sky/shell/gpu_delegate.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698