| 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 "base/trace_event/trace_event.h" |
| 7 #include "sky/shell/gpu/ganesh_context.h" | 8 #include "sky/shell/gpu/ganesh_context.h" |
| 8 #include "sky/shell/gpu/ganesh_surface.h" | 9 #include "sky/shell/gpu/ganesh_surface.h" |
| 9 #include "third_party/skia/include/core/SkCanvas.h" | 10 #include "third_party/skia/include/core/SkCanvas.h" |
| 10 #include "third_party/skia/include/core/SkPicture.h" | 11 #include "third_party/skia/include/core/SkPicture.h" |
| 11 #include "ui/gl/gl_bindings.h" | 12 #include "ui/gl/gl_bindings.h" |
| 12 #include "ui/gl/gl_context.h" | 13 #include "ui/gl/gl_context.h" |
| 13 #include "ui/gl/gl_share_group.h" | 14 #include "ui/gl/gl_share_group.h" |
| 14 #include "ui/gl/gl_surface.h" | 15 #include "ui/gl/gl_surface.h" |
| 15 | 16 |
| 16 namespace sky { | 17 namespace sky { |
| (...skipping 17 matching lines...) Expand all Loading... |
| 34 base::WeakPtr<Rasterizer> Rasterizer::GetWeakPtr() { | 35 base::WeakPtr<Rasterizer> Rasterizer::GetWeakPtr() { |
| 35 return weak_factory_.GetWeakPtr(); | 36 return weak_factory_.GetWeakPtr(); |
| 36 } | 37 } |
| 37 | 38 |
| 38 void Rasterizer::OnAcceleratedWidgetAvailable(gfx::AcceleratedWidget widget) { | 39 void Rasterizer::OnAcceleratedWidgetAvailable(gfx::AcceleratedWidget widget) { |
| 39 surface_ = gfx::GLSurface::CreateViewGLSurface(widget); | 40 surface_ = gfx::GLSurface::CreateViewGLSurface(widget); |
| 40 CHECK(surface_) << "GLSurface required."; | 41 CHECK(surface_) << "GLSurface required."; |
| 41 } | 42 } |
| 42 | 43 |
| 43 void Rasterizer::Draw(skia::RefPtr<SkPicture> picture) { | 44 void Rasterizer::Draw(skia::RefPtr<SkPicture> picture) { |
| 45 TRACE_EVENT0("sky", "Rasterizer::Draw"); |
| 46 |
| 44 if (!surface_) | 47 if (!surface_) |
| 45 return; | 48 return; |
| 46 | 49 |
| 47 gfx::Size size = GetSize(picture.get()); | 50 gfx::Size size = GetSize(picture.get()); |
| 48 if (size.IsEmpty()) | 51 if (size.IsEmpty()) |
| 49 return; | 52 return; |
| 50 | 53 |
| 51 EnsureGLContext(); | 54 EnsureGLContext(); |
| 52 CHECK(context_->MakeCurrent(surface_.get())); | 55 CHECK(context_->MakeCurrent(surface_.get())); |
| 53 EnsureGaneshSurface(size); | 56 EnsureGaneshSurface(size); |
| 54 | 57 |
| 55 SkCanvas* canvas = ganesh_surface_->canvas(); | 58 DrawPicture(picture.get()); |
| 56 canvas->drawPicture(picture.get()); | |
| 57 canvas->flush(); | |
| 58 | |
| 59 surface_->SwapBuffers(); | 59 surface_->SwapBuffers(); |
| 60 } | 60 } |
| 61 | 61 |
| 62 void Rasterizer::DrawPicture(SkPicture* picture) { |
| 63 TRACE_EVENT0("sky", "Rasterizer::DrawPicture"); |
| 64 SkCanvas* canvas = ganesh_surface_->canvas(); |
| 65 canvas->drawPicture(picture); |
| 66 canvas->flush(); |
| 67 } |
| 68 |
| 62 void Rasterizer::OnOutputSurfaceDestroyed() { | 69 void Rasterizer::OnOutputSurfaceDestroyed() { |
| 63 ganesh_surface_.reset(); | 70 ganesh_surface_.reset(); |
| 64 ganesh_context_.reset(); | 71 ganesh_context_.reset(); |
| 65 context_ = nullptr; | 72 context_ = nullptr; |
| 66 surface_ = nullptr; | 73 surface_ = nullptr; |
| 67 } | 74 } |
| 68 | 75 |
| 69 void Rasterizer::EnsureGLContext() { | 76 void Rasterizer::EnsureGLContext() { |
| 70 if (context_) | 77 if (context_) |
| 71 return; | 78 return; |
| 72 context_ = gfx::GLContext::CreateGLContext(share_group_.get(), surface_.get(), | 79 context_ = gfx::GLContext::CreateGLContext(share_group_.get(), surface_.get(), |
| 73 gfx::PreferIntegratedGpu); | 80 gfx::PreferIntegratedGpu); |
| 74 CHECK(context_) << "GLContext required."; | 81 CHECK(context_) << "GLContext required."; |
| 75 CHECK(context_->MakeCurrent(surface_.get())); | 82 CHECK(context_->MakeCurrent(surface_.get())); |
| 76 ganesh_context_.reset(new GaneshContext(context_.get())); | 83 ganesh_context_.reset(new GaneshContext(context_.get())); |
| 77 } | 84 } |
| 78 | 85 |
| 79 void Rasterizer::EnsureGaneshSurface(const gfx::Size& size) { | 86 void Rasterizer::EnsureGaneshSurface(const gfx::Size& size) { |
| 80 if (!ganesh_surface_ || ganesh_surface_->size() != size) | 87 if (!ganesh_surface_ || ganesh_surface_->size() != size) |
| 81 ganesh_surface_.reset(new GaneshSurface(ganesh_context_.get(), size)); | 88 ganesh_surface_.reset(new GaneshSurface(ganesh_context_.get(), size)); |
| 82 } | 89 } |
| 83 | 90 |
| 84 } // namespace shell | 91 } // namespace shell |
| 85 } // namespace sky | 92 } // namespace sky |
| OLD | NEW |