Chromium Code Reviews| OLD | NEW |
|---|---|
| 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/trace_event/trace_event.h" | 14 #include "base/trace_event/trace_event.h" |
| 14 #include "gpu/command_buffer/client/gles2_interface.h" | 15 #include "gpu/command_buffer/client/gles2_interface.h" |
| 15 #include "gpu/skia_bindings/gl_bindings_skia_cmd_buffer.h" | 16 #include "gpu/skia_bindings/gl_bindings_skia_cmd_buffer.h" |
| 16 #include "third_party/skia/include/gpu/GrContext.h" | 17 #include "third_party/skia/include/gpu/GrContext.h" |
| 17 #include "third_party/skia/include/gpu/gl/GrGLInterface.h" | 18 #include "third_party/skia/include/gpu/gl/GrGLInterface.h" |
| 18 | 19 |
| 19 namespace skia_bindings { | 20 namespace skia_bindings { |
| 20 | 21 |
| 21 GrContextForGLES2Interface::GrContextForGLES2Interface( | 22 GrContextForGLES2Interface::GrContextForGLES2Interface( |
| 22 gpu::gles2::GLES2Interface* gl) { | 23 gpu::gles2::GLES2Interface* gl) { |
| 23 sk_sp<GrGLInterface> interface( | 24 sk_sp<GrGLInterface> interface( |
| 24 skia_bindings::CreateGLES2InterfaceBindings(gl)); | 25 skia_bindings::CreateGLES2InterfaceBindings(gl)); |
| 25 gr_context_ = sk_sp<GrContext>( | 26 gr_context_ = sk_sp<GrContext>( |
| 26 GrContext::Create(kOpenGL_GrBackend, | 27 GrContext::Create(kOpenGL_GrBackend, |
| 27 // GrContext takes ownership of |interface|. | 28 // GrContext takes ownership of |interface|. |
| 28 reinterpret_cast<GrBackendContext>(interface.get()))); | 29 reinterpret_cast<GrBackendContext>(interface.get()))); |
| 29 if (gr_context_) { | 30 if (gr_context_) { |
| 30 // The limit of the number of GPU resources we hold in the GrContext's | 31 // The limit of the number of GPU resources we hold in the GrContext's |
| 31 // GPU cache. | 32 // GPU cache. |
| 32 static const int kMaxGaneshResourceCacheCount = 16384; | 33 static const int kMaxGaneshResourceCacheCount = 16384; |
| 33 // The limit of the bytes allocated toward GPU resources in the GrContext's | 34 // The limit of the bytes allocated toward GPU resources in the GrContext's |
| 34 // GPU cache. | 35 // GPU cache. |
| 36 static const size_t kMaxLowEndGaneshResourceCacheBytes = 48 * 1024 * 1024; | |
| 35 static const size_t kMaxGaneshResourceCacheBytes = 96 * 1024 * 1024; | 37 static const size_t kMaxGaneshResourceCacheBytes = 96 * 1024 * 1024; |
| 38 static const size_t kMaxHighEndGaneshResourceCacheBytes = 256 * 1024 * 1024; | |
| 39 static const int64_t kHighEndMemoryThreshold = (int64_t)4096 * 1024 * 1024; | |
| 40 | |
| 41 size_t max_ganesh_resource_cache_bytes = kMaxGaneshResourceCacheBytes; | |
| 42 if (base::SysInfo::IsLowEndDevice()) { | |
|
ericrk
2017/04/26 00:49:31
Note that on Android O IsLowEndDevice applies to 1
| |
| 43 max_ganesh_resource_cache_bytes = kMaxLowEndGaneshResourceCacheBytes; | |
| 44 } else if (base::SysInfo::AmountOfPhysicalMemory() >= | |
| 45 kHighEndMemoryThreshold) { | |
| 46 max_ganesh_resource_cache_bytes = kMaxHighEndGaneshResourceCacheBytes; | |
| 47 } | |
| 36 | 48 |
| 37 gr_context_->setResourceCacheLimits(kMaxGaneshResourceCacheCount, | 49 gr_context_->setResourceCacheLimits(kMaxGaneshResourceCacheCount, |
| 38 kMaxGaneshResourceCacheBytes); | 50 max_ganesh_resource_cache_bytes); |
| 39 } | 51 } |
| 40 } | 52 } |
| 41 | 53 |
| 42 GrContextForGLES2Interface::~GrContextForGLES2Interface() { | 54 GrContextForGLES2Interface::~GrContextForGLES2Interface() { |
| 43 // At this point the GLES2Interface is going to be destroyed, so have | 55 // At this point the GLES2Interface is going to be destroyed, so have |
| 44 // the GrContext clean up and not try to use it anymore. | 56 // the GrContext clean up and not try to use it anymore. |
| 45 if (gr_context_) | 57 if (gr_context_) |
| 46 gr_context_->releaseResourcesAndAbandonContext(); | 58 gr_context_->releaseResourcesAndAbandonContext(); |
| 47 } | 59 } |
| 48 | 60 |
| 49 void GrContextForGLES2Interface::OnLostContext() { | 61 void GrContextForGLES2Interface::OnLostContext() { |
| 50 if (gr_context_) | 62 if (gr_context_) |
| 51 gr_context_->abandonContext(); | 63 gr_context_->abandonContext(); |
| 52 } | 64 } |
| 53 | 65 |
| 54 void GrContextForGLES2Interface::ResetContext(uint32_t state) { | 66 void GrContextForGLES2Interface::ResetContext(uint32_t state) { |
| 55 if (gr_context_) | 67 if (gr_context_) |
| 56 gr_context_->resetContext(state); | 68 gr_context_->resetContext(state); |
| 57 } | 69 } |
| 58 | 70 |
| 59 void GrContextForGLES2Interface::FreeGpuResources() { | 71 void GrContextForGLES2Interface::FreeGpuResources() { |
| 60 if (gr_context_) { | 72 if (gr_context_) { |
| 61 TRACE_EVENT_INSTANT0("gpu", "GrContext::freeGpuResources", | 73 TRACE_EVENT_INSTANT0("gpu", "GrContext::freeGpuResources", |
| 62 TRACE_EVENT_SCOPE_THREAD); | 74 TRACE_EVENT_SCOPE_THREAD); |
| 63 gr_context_->freeGpuResources(); | 75 gr_context_->freeGpuResources(); |
| 64 } | 76 } |
| 65 } | 77 } |
| 66 | 78 |
| 67 } // namespace skia_bindings | 79 } // namespace skia_bindings |
| OLD | NEW |