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

Side by Side Diff: gpu/skia_runner/in_process_graphics_system.cc

Issue 1149893010: gpu: play skp files through the command buffer (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: latest Created 5 years, 6 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 | « gpu/skia_runner/in_process_graphics_system.h ('k') | gpu/skia_runner/sk_picture_rasterizer.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 (c) 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 "gpu/skia_runner/in_process_graphics_system.h"
6
7 #include <iostream>
8
9 #include "base/lazy_instance.h"
10 #include "base/memory/discardable_memory.h"
11 #include "base/memory/discardable_memory_allocator.h"
12 #include "base/thread_task_runner_handle.h"
13 #include "gpu/command_buffer/client/gles2_implementation.h"
14 #include "gpu/command_buffer/client/gles2_lib.h"
15 #include "gpu/skia_bindings/gl_bindings_skia_cmd_buffer.h"
16 #include "third_party/khronos/GLES2/gl2.h"
17 #include "third_party/skia/include/gpu/gl/GrGLInterface.h"
18
19 namespace {
20
21 // TODO(hendrikw): Replace TestDiscardableMemoryAllocator and move to base?
22 class NonDiscardableMemory : public base::DiscardableMemory {
23 public:
24 NonDiscardableMemory(size_t size) : data_(size) {}
piman 2015/06/12 01:05:30 nit: explicit.
hendrikw 2015/06/12 18:57:49 Done.
25 bool Lock() override { return false; }
26 void Unlock() override {}
27 void* data() const override { return data_.data(); }
28
29 private:
30 mutable std::vector<uint8_t> data_;
piman 2015/06/12 01:05:30 Since you don't resize the data, maybe you can use
hendrikw 2015/06/12 18:57:49 hm, I generally try to stay away from 'new' when a
31 };
32
33 class NonDiscardableMemoryAllocator : public base::DiscardableMemoryAllocator {
34 public:
35 // Overridden from DiscardableMemoryAllocator:
36 scoped_ptr<base::DiscardableMemory> AllocateLockedDiscardableMemory(
37 size_t size) override {
38 return make_scoped_ptr(new NonDiscardableMemory(size));
39 }
40 };
41
42 NonDiscardableMemoryAllocator g_discardable;
piman 2015/06/12 01:05:30 nit: non-POD statics are disallowed by the style g
hendrikw 2015/06/12 18:57:49 Done.
43
44 // Singleton used to initialize and terminate the gles2 library.
45 class GLES2Initializer {
46 public:
47 GLES2Initializer() { gles2::Initialize(); }
48 ~GLES2Initializer() { gles2::Terminate(); }
49
50 private:
51 DISALLOW_COPY_AND_ASSIGN(GLES2Initializer);
52 };
53
54 base::LazyInstance<GLES2Initializer> g_gles2_initializer =
55 LAZY_INSTANCE_INITIALIZER;
56
57 } // namespace anonymous
58
59 namespace skia_runner {
60
61 void BindContext3DGLContextCallback(const GrGLInterface* gl_interface) {
62 gles2::SetGLContext(reinterpret_cast<gpu::GLInProcessContext*>(
63 gl_interface->fCallbackData)->GetImplementation());
64 }
65
66 InProcessGraphicsSystem::InProcessGraphicsSystem() {
67 base::DiscardableMemoryAllocator::SetInstance(&g_discardable);
68 g_gles2_initializer.Get();
69
70 if (!gfx::GLSurface::InitializeOneOff()) {
71 LOG(ERROR) << "Unable to initialize gfx::GLSurface.";
72 return;
73 }
74
75 // Arg, we need to call base::ThreadTaskRunnerHandle::IsSet() to ensure that
76 // its lazy instance is instantiated before we create the GPU thread,
77 // otherwise shutdown order will delete the ThreadTaskRunnerHandle before the
78 // GPU thread's message loop, and when the message loop is shutdown, it will
79 // recreate ThreadTaskRunnerHandle, which will re-add a new task to the,
80 // AtExitManager, which causes a deadlock because it's already locked.
81 base::ThreadTaskRunnerHandle::IsSet();
piman 2015/06/12 01:05:30 This is kinda unfortunate - it sounds like a data
82
83 // Create the in process context.
84 in_process_context_ = CreateInProcessContext();
85 if (!in_process_context_) {
86 LOG(ERROR) << "Unable to create in process context.";
87 return;
88 }
89
90 // Create and set up skia's GL bindings.
91 gles2::SetGLContext(in_process_context_->GetImplementation());
92 GrGLInterface* bindings = skia_bindings::CreateCommandBufferSkiaGLBinding();
93 if (!bindings) {
94 LOG(ERROR) << "Unable to create skia command buffer bindings.";
95 return;
96 }
97
98 bindings->fCallback = BindContext3DGLContextCallback;
99 bindings->fCallbackData =
100 reinterpret_cast<GrGLInterfaceCallbackData>(in_process_context_.get());
101
102 // Create skia's graphics context.
103 gr_context_ = skia::AdoptRef(GrContext::Create(
104 kOpenGL_GrBackend, reinterpret_cast<GrBackendContext>(bindings)));
105
106 if (!gr_context_) {
107 LOG(ERROR) << "Unable to create skia graphics context.";
108 return;
109 }
110
111 // Set skia's graphics context cache size.
112 const int kMaxGaneshResourceCacheCount = 2048;
113 const size_t kMaxGaneshResourceCacheBytes = 96 * 1024 * 1024;
114 gr_context_->setResourceCacheLimits(kMaxGaneshResourceCacheCount,
115 kMaxGaneshResourceCacheBytes);
116 }
117
118 InProcessGraphicsSystem::~InProcessGraphicsSystem() {
119 }
120
121 bool InProcessGraphicsSystem::IsSuccessfullyInitialized() const {
122 return gr_context_;
123 }
124
125 int InProcessGraphicsSystem::GetMaxTextureSize() const {
126 int max_texture_size = 0;
127 in_process_context_->GetImplementation()->GetIntegerv(GL_MAX_TEXTURE_SIZE,
128 &max_texture_size);
129 return max_texture_size;
130 }
131
132 scoped_ptr<gpu::GLInProcessContext>
133 InProcessGraphicsSystem::CreateInProcessContext() const {
134 const bool is_offscreen = true;
135 const bool share_resources = true;
136 gpu::gles2::ContextCreationAttribHelper attribs;
137 attribs.alpha_size = 8;
138 attribs.blue_size = 8;
139 attribs.green_size = 8;
140 attribs.red_size = 8;
141 attribs.depth_size = 24;
142 attribs.stencil_size = 8;
143 attribs.samples = 0;
144 attribs.sample_buffers = 0;
145 attribs.fail_if_major_perf_caveat = false;
146 attribs.bind_generates_resource = false;
147 gfx::GpuPreference gpu_preference = gfx::PreferDiscreteGpu;
148
149 scoped_ptr<gpu::GLInProcessContext> context =
150 make_scoped_ptr(gpu::GLInProcessContext::Create(
151 nullptr, nullptr, is_offscreen, gfx::kNullAcceleratedWidget,
152 gfx::Size(1, 1), nullptr, share_resources, attribs, gpu_preference,
153 gpu::GLInProcessContextSharedMemoryLimits(), nullptr, nullptr));
154
155 DCHECK(context);
156 return context.Pass();
157 }
158
159 } // namespace skia_runner
OLDNEW
« no previous file with comments | « gpu/skia_runner/in_process_graphics_system.h ('k') | gpu/skia_runner/sk_picture_rasterizer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698