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

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

Issue 891143002: Teach SkyShell how to draw with Ganesh (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Moar 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_driver.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "sky/shell/gpu/rasterizer.h"
6
7 #include "sky/shell/gpu/ganesh_context.h"
8 #include "sky/shell/gpu/ganesh_surface.h"
9 #include "third_party/skia/include/core/SkCanvas.h"
10 #include "third_party/skia/include/core/SkPicture.h"
11 #include "ui/gl/gl_bindings.h"
12 #include "ui/gl/gl_context.h"
13 #include "ui/gl/gl_share_group.h"
14 #include "ui/gl/gl_surface.h"
15
16 namespace sky {
17 namespace shell {
18 namespace {
19
20 gfx::Size GetSize(SkPicture* picture) {
21 const SkRect& rect = picture->cullRect();
22 return gfx::Size(rect.width(), rect.height());
23 }
24
25 } // namespace
26
27 Rasterizer::Rasterizer() : weak_factory_(this) {
28 }
29
30 Rasterizer::~Rasterizer() {
31 }
32
33 base::WeakPtr<Rasterizer> Rasterizer::GetWeakPtr() {
34 return weak_factory_.GetWeakPtr();
35 }
36
37 void Rasterizer::Init(gfx::AcceleratedWidget widget) {
38 share_group_ = make_scoped_refptr(new gfx::GLShareGroup());
39 surface_ = gfx::GLSurface::CreateViewGLSurface(widget);
40 CHECK(surface_) << "GLSurface required.";
41 CHECK(CreateGLContext()) << "GLContext required.";
42 }
43
44 void Rasterizer::Draw(skia::RefPtr<SkPicture> picture) {
45 // TODO(abarth): We should handle losing the GL context.
46 CHECK(context_->MakeCurrent(surface_.get()));
47 EnsureGaneshSurface(GetSize(picture.get()));
48
49 SkCanvas* canvas = ganesh_surface_->canvas();
50 canvas->drawPicture(picture.get());
51 canvas->flush();
52
53 surface_->SwapBuffers();
54 }
55
56 bool Rasterizer::CreateGLContext() {
57 context_ = gfx::GLContext::CreateGLContext(share_group_.get(), surface_.get(),
58 gfx::PreferIntegratedGpu);
59 if (!context_)
60 return false;
61 ganesh_context_.reset(new GaneshContext(context_.get()));
62 return true;
63 }
64
65 void Rasterizer::EnsureGaneshSurface(const gfx::Size& size) {
66 if (!ganesh_surface_ || ganesh_surface_->size() != size)
67 ganesh_surface_.reset(new GaneshSurface(ganesh_context_.get(), size));
68 }
69
70 } // namespace shell
71 } // namespace sky
OLDNEW
« no previous file with comments | « sky/shell/gpu/rasterizer.h ('k') | sky/shell/gpu_driver.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698