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

Side by Side Diff: gpu/skia_bindings/grcontext_for_gles2_interface.cc

Issue 2866353002: Add workaround for Mac stencil buffer leak (Closed)
Patch Set: Fix analyze issue Created 3 years, 7 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
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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 "gpu/skia_bindings/grcontext_for_gles2_interface.h" 5 #include "gpu/skia_bindings/grcontext_for_gles2_interface.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <string.h> 8 #include <string.h>
9 #include <utility> 9 #include <utility>
10 10
11 #include "base/lazy_instance.h" 11 #include "base/lazy_instance.h"
12 #include "base/macros.h" 12 #include "base/macros.h"
13 #include "base/sys_info.h" 13 #include "base/sys_info.h"
14 #include "base/trace_event/trace_event.h" 14 #include "base/trace_event/trace_event.h"
15 #include "gpu/command_buffer/client/gles2_interface.h" 15 #include "gpu/command_buffer/client/gles2_interface.h"
16 #include "gpu/command_buffer/common/capabilities.h"
16 #include "gpu/skia_bindings/gl_bindings_skia_cmd_buffer.h" 17 #include "gpu/skia_bindings/gl_bindings_skia_cmd_buffer.h"
17 #include "third_party/skia/include/gpu/GrContext.h" 18 #include "third_party/skia/include/gpu/GrContext.h"
18 #include "third_party/skia/include/gpu/GrContextOptions.h" 19 #include "third_party/skia/include/gpu/GrContextOptions.h"
19 #include "third_party/skia/include/gpu/gl/GrGLInterface.h" 20 #include "third_party/skia/include/gpu/gl/GrGLInterface.h"
20 21
21 namespace skia_bindings { 22 namespace skia_bindings {
22 23
23 GrContextForGLES2Interface::GrContextForGLES2Interface( 24 GrContextForGLES2Interface::GrContextForGLES2Interface(
24 gpu::gles2::GLES2Interface* gl) { 25 gpu::gles2::GLES2Interface* gl,
26 const gpu::Capabilities& capabilities) {
25 // Calculate limits to pass during initialization: 27 // Calculate limits to pass during initialization:
26 // The limit of the number of GPU resources we hold in the GrContext's 28 // The limit of the number of GPU resources we hold in the GrContext's
27 // GPU cache. 29 // GPU cache.
28 static const int kMaxGaneshResourceCacheCount = 16384; 30 static const int kMaxGaneshResourceCacheCount = 16384;
29 // The limit of the bytes allocated toward GPU resources in the GrContext's 31 // The limit of the bytes allocated toward GPU resources in the GrContext's
30 // GPU cache. 32 // GPU cache.
31 static const size_t kMaxLowEndGaneshResourceCacheBytes = 48 * 1024 * 1024; 33 static const size_t kMaxLowEndGaneshResourceCacheBytes = 48 * 1024 * 1024;
32 static const size_t kMaxGaneshResourceCacheBytes = 96 * 1024 * 1024; 34 static const size_t kMaxGaneshResourceCacheBytes = 96 * 1024 * 1024;
33 static const size_t kMaxHighEndGaneshResourceCacheBytes = 256 * 1024 * 1024; 35 static const size_t kMaxHighEndGaneshResourceCacheBytes = 256 * 1024 * 1024;
34 // Limits for glyph cache textures. 36 // Limits for glyph cache textures.
35 static const size_t kMaxDefaultGlyphCacheTextureBytes = 2048 * 1024 * 4; 37 static const size_t kMaxDefaultGlyphCacheTextureBytes = 2048 * 1024 * 4;
36 static const size_t kMaxLowEndGlyphCacheTextureBytes = 1024 * 512 * 4; 38 static const size_t kMaxLowEndGlyphCacheTextureBytes = 1024 * 512 * 4;
37 // High-end / low-end memory cutoffs. 39 // High-end / low-end memory cutoffs.
38 static const int64_t kHighEndMemoryThreshold = (int64_t)4096 * 1024 * 1024; 40 static const int64_t kHighEndMemoryThreshold = (int64_t)4096 * 1024 * 1024;
39 static const int64_t kLowEndMemoryThreshold = (int64_t)512 * 1024 * 1024; 41 static const int64_t kLowEndMemoryThreshold = (int64_t)512 * 1024 * 1024;
40 42
41 size_t max_ganesh_resource_cache_bytes = kMaxGaneshResourceCacheBytes; 43 size_t max_ganesh_resource_cache_bytes = kMaxGaneshResourceCacheBytes;
42 int max_glyph_cache_texture_bytes = kMaxDefaultGlyphCacheTextureBytes; 44 int max_glyph_cache_texture_bytes = kMaxDefaultGlyphCacheTextureBytes;
43 if (base::SysInfo::AmountOfPhysicalMemory() <= kLowEndMemoryThreshold) { 45 if (base::SysInfo::AmountOfPhysicalMemory() <= kLowEndMemoryThreshold) {
44 max_ganesh_resource_cache_bytes = kMaxLowEndGaneshResourceCacheBytes; 46 max_ganesh_resource_cache_bytes = kMaxLowEndGaneshResourceCacheBytes;
45 max_glyph_cache_texture_bytes = kMaxLowEndGlyphCacheTextureBytes; 47 max_glyph_cache_texture_bytes = kMaxLowEndGlyphCacheTextureBytes;
46 } else if (base::SysInfo::AmountOfPhysicalMemory() >= 48 } else if (base::SysInfo::AmountOfPhysicalMemory() >=
47 kHighEndMemoryThreshold) { 49 kHighEndMemoryThreshold) {
48 max_ganesh_resource_cache_bytes = kMaxHighEndGaneshResourceCacheBytes; 50 max_ganesh_resource_cache_bytes = kMaxHighEndGaneshResourceCacheBytes;
49 } 51 }
50 52
51 GrContextOptions options; 53 GrContextOptions options;
52 options.fGlyphCacheTextureMaximumBytes = max_glyph_cache_texture_bytes; 54 options.fGlyphCacheTextureMaximumBytes = max_glyph_cache_texture_bytes;
55 options.fAvoidStencilBuffers = capabilities.avoid_stencil_buffers;
53 sk_sp<GrGLInterface> interface( 56 sk_sp<GrGLInterface> interface(
54 skia_bindings::CreateGLES2InterfaceBindings(gl)); 57 skia_bindings::CreateGLES2InterfaceBindings(gl));
55 gr_context_ = sk_sp<GrContext>(GrContext::Create( 58 gr_context_ = sk_sp<GrContext>(GrContext::Create(
56 kOpenGL_GrBackend, 59 kOpenGL_GrBackend,
57 // GrContext takes ownership of |interface|. 60 // GrContext takes ownership of |interface|.
58 reinterpret_cast<GrBackendContext>(interface.get()), options)); 61 reinterpret_cast<GrBackendContext>(interface.get()), options));
59 if (gr_context_) { 62 if (gr_context_) {
60 gr_context_->setResourceCacheLimits(kMaxGaneshResourceCacheCount, 63 gr_context_->setResourceCacheLimits(kMaxGaneshResourceCacheCount,
61 max_ganesh_resource_cache_bytes); 64 max_ganesh_resource_cache_bytes);
62 } 65 }
(...skipping 18 matching lines...) Expand all
81 84
82 void GrContextForGLES2Interface::FreeGpuResources() { 85 void GrContextForGLES2Interface::FreeGpuResources() {
83 if (gr_context_) { 86 if (gr_context_) {
84 TRACE_EVENT_INSTANT0("gpu", "GrContext::freeGpuResources", 87 TRACE_EVENT_INSTANT0("gpu", "GrContext::freeGpuResources",
85 TRACE_EVENT_SCOPE_THREAD); 88 TRACE_EVENT_SCOPE_THREAD);
86 gr_context_->freeGpuResources(); 89 gr_context_->freeGpuResources();
87 } 90 }
88 } 91 }
89 92
90 } // namespace skia_bindings 93 } // namespace skia_bindings
OLDNEW
« no previous file with comments | « gpu/skia_bindings/grcontext_for_gles2_interface.h ('k') | services/ui/public/cpp/gpu/context_provider_command_buffer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698