| OLD | NEW |
| 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" |
| (...skipping 16 matching lines...) Expand all Loading... |
| 27 Rasterizer::Rasterizer() : weak_factory_(this) { | 27 Rasterizer::Rasterizer() : weak_factory_(this) { |
| 28 } | 28 } |
| 29 | 29 |
| 30 Rasterizer::~Rasterizer() { | 30 Rasterizer::~Rasterizer() { |
| 31 } | 31 } |
| 32 | 32 |
| 33 base::WeakPtr<Rasterizer> Rasterizer::GetWeakPtr() { | 33 base::WeakPtr<Rasterizer> Rasterizer::GetWeakPtr() { |
| 34 return weak_factory_.GetWeakPtr(); | 34 return weak_factory_.GetWeakPtr(); |
| 35 } | 35 } |
| 36 | 36 |
| 37 void Rasterizer::Init(gfx::AcceleratedWidget widget) { | 37 void Rasterizer::OnAcceleratedWidgetAvailable(gfx::AcceleratedWidget widget) { |
| 38 share_group_ = make_scoped_refptr(new gfx::GLShareGroup()); | 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."; | 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 // TODO(abarth): We should handle losing the GL context. |
| 46 CHECK(context_->MakeCurrent(surface_.get())); | 46 CHECK(context_->MakeCurrent(surface_.get())); |
| 47 EnsureGaneshSurface(GetSize(picture.get())); | 47 EnsureGaneshSurface(GetSize(picture.get())); |
| 48 | 48 |
| 49 SkCanvas* canvas = ganesh_surface_->canvas(); | 49 SkCanvas* canvas = ganesh_surface_->canvas(); |
| 50 canvas->drawPicture(picture.get()); | 50 canvas->drawPicture(picture.get()); |
| 51 canvas->flush(); | 51 canvas->flush(); |
| 52 | 52 |
| 53 surface_->SwapBuffers(); | 53 surface_->SwapBuffers(); |
| 54 } | 54 } |
| 55 | 55 |
| 56 void Rasterizer::OnDestroyed() { |
| 57 } |
| 58 |
| 56 bool Rasterizer::CreateGLContext() { | 59 bool Rasterizer::CreateGLContext() { |
| 57 context_ = gfx::GLContext::CreateGLContext(share_group_.get(), surface_.get(), | 60 context_ = gfx::GLContext::CreateGLContext(share_group_.get(), surface_.get(), |
| 58 gfx::PreferIntegratedGpu); | 61 gfx::PreferIntegratedGpu); |
| 59 if (!context_) | 62 if (!context_) |
| 60 return false; | 63 return false; |
| 61 ganesh_context_.reset(new GaneshContext(context_.get())); | 64 ganesh_context_.reset(new GaneshContext(context_.get())); |
| 62 return true; | 65 return true; |
| 63 } | 66 } |
| 64 | 67 |
| 65 void Rasterizer::EnsureGaneshSurface(const gfx::Size& size) { | 68 void Rasterizer::EnsureGaneshSurface(const gfx::Size& size) { |
| 66 if (!ganesh_surface_ || ganesh_surface_->size() != size) | 69 if (!ganesh_surface_ || ganesh_surface_->size() != size) |
| 67 ganesh_surface_.reset(new GaneshSurface(ganesh_context_.get(), size)); | 70 ganesh_surface_.reset(new GaneshSurface(ganesh_context_.get(), size)); |
| 68 } | 71 } |
| 69 | 72 |
| 70 } // namespace shell | 73 } // namespace shell |
| 71 } // namespace sky | 74 } // namespace sky |
| OLD | NEW |