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

Side by Side Diff: gpu/command_buffer/client/gles2_implementation.cc

Issue 2252163003: Update Context Client Visibility to use Scoped Pattern (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: feedback Created 4 years, 4 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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 // A class to emulate GLES2 over command buffers. 5 // A class to emulate GLES2 over command buffers.
6 6
7 #include "gpu/command_buffer/client/gles2_implementation.h" 7 #include "gpu/command_buffer/client/gles2_implementation.h"
8 8
9 #include <GLES2/gl2.h> 9 #include <GLES2/gl2.h>
10 #include <GLES2/gl2ext.h> 10 #include <GLES2/gl2ext.h>
11 #include <GLES2/gl2extchromium.h> 11 #include <GLES2/gl2extchromium.h>
12 #include <GLES3/gl3.h> 12 #include <GLES3/gl3.h>
13 #include <stddef.h> 13 #include <stddef.h>
14 #include <stdint.h> 14 #include <stdint.h>
15 #include <algorithm> 15 #include <algorithm>
16 #include <map> 16 #include <map>
17 #include <set> 17 #include <set>
18 #include <sstream> 18 #include <sstream>
19 #include <string> 19 #include <string>
20 #include "base/atomic_sequence_num.h" 20 #include "base/atomic_sequence_num.h"
21 #include "base/compiler_specific.h" 21 #include "base/compiler_specific.h"
22 #include "base/memory/ptr_util.h"
22 #include "base/strings/string_split.h" 23 #include "base/strings/string_split.h"
23 #include "base/strings/stringprintf.h" 24 #include "base/strings/stringprintf.h"
24 #include "base/sys_info.h" 25 #include "base/sys_info.h"
25 #include "base/threading/thread_task_runner_handle.h" 26 #include "base/threading/thread_task_runner_handle.h"
26 #include "base/trace_event/memory_allocator_dump.h" 27 #include "base/trace_event/memory_allocator_dump.h"
27 #include "base/trace_event/memory_dump_manager.h" 28 #include "base/trace_event/memory_dump_manager.h"
28 #include "base/trace_event/process_memory_dump.h" 29 #include "base/trace_event/process_memory_dump.h"
29 #include "base/trace_event/trace_event.h" 30 #include "base/trace_event/trace_event.h"
30 #include "gpu/command_buffer/client/buffer_tracker.h" 31 #include "gpu/command_buffer/client/buffer_tracker.h"
31 #include "gpu/command_buffer/client/gles2_cmd_helper.h" 32 #include "gpu/command_buffer/client/gles2_cmd_helper.h"
(...skipping 12 matching lines...) Expand all
44 #if defined(GPU_CLIENT_DEBUG) 45 #if defined(GPU_CLIENT_DEBUG)
45 #include "base/command_line.h" 46 #include "base/command_line.h"
46 #include "gpu/command_buffer/client/gpu_switches.h" 47 #include "gpu/command_buffer/client/gpu_switches.h"
47 #endif 48 #endif
48 49
49 namespace gpu { 50 namespace gpu {
50 namespace gles2 { 51 namespace gles2 {
51 52
52 namespace { 53 namespace {
53 54
55 class ScopedVisibilityImpl : public ContextSupport::ScopedVisibility {
56 public:
57 explicit ScopedVisibilityImpl(ContextSupport* context_support)
58 : initial_context_support_(context_support) {}
59 ~ScopedVisibilityImpl() { DCHECK(!initial_context_support_); }
60
61 void Release(ContextSupport* context_support) {
62 DCHECK_EQ(initial_context_support_, context_support);
63 initial_context_support_ = nullptr;
64 }
65
66 private:
67 // |initial_context_support_| is just stored/used for sanity-checking Release.
danakj 2016/08/19 18:29:55 Update comment
ericrk 2016/08/19 18:49:58 Done.
68 const ContextSupport* initial_context_support_;
69 };
70
54 void CopyRectToBuffer(const void* pixels, 71 void CopyRectToBuffer(const void* pixels,
55 uint32_t height, 72 uint32_t height,
56 uint32_t unpadded_row_size, 73 uint32_t unpadded_row_size,
57 uint32_t pixels_padded_row_size, 74 uint32_t pixels_padded_row_size,
58 void* buffer, 75 void* buffer,
59 uint32_t buffer_padded_row_size) { 76 uint32_t buffer_padded_row_size) {
60 if (height == 0) 77 if (height == 0)
61 return; 78 return;
62 const int8_t* source = static_cast<const int8_t*>(pixels); 79 const int8_t* source = static_cast<const int8_t*>(pixels);
63 int8_t* dest = static_cast<int8_t*>(buffer); 80 int8_t* dest = static_cast<int8_t*>(buffer);
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
157 // Do not use more than 5% of extra shared memory, and do not 174 // Do not use more than 5% of extra shared memory, and do not
158 // use any extra for memory contrained devices (<=1GB). 175 // use any extra for memory contrained devices (<=1GB).
159 base::SysInfo::AmountOfPhysicalMemory() > 1024 * 1024 * 1024 176 base::SysInfo::AmountOfPhysicalMemory() > 1024 * 1024 * 1024
160 ? base::saturated_cast<uint32_t>( 177 ? base::saturated_cast<uint32_t>(
161 base::SysInfo::AmountOfPhysicalMemory() / 20) 178 base::SysInfo::AmountOfPhysicalMemory() / 20)
162 : 0), 179 : 0),
163 #endif 180 #endif
164 current_trace_stack_(0), 181 current_trace_stack_(0),
165 gpu_control_(gpu_control), 182 gpu_control_(gpu_control),
166 capabilities_(gpu_control->GetCapabilities()), 183 capabilities_(gpu_control->GetCapabilities()),
167 aggressively_free_resources_(false),
168 cached_extension_string_(nullptr), 184 cached_extension_string_(nullptr),
169 weak_ptr_factory_(this) { 185 weak_ptr_factory_(this) {
170 DCHECK(helper); 186 DCHECK(helper);
171 DCHECK(transfer_buffer); 187 DCHECK(transfer_buffer);
172 DCHECK(gpu_control); 188 DCHECK(gpu_control);
173 189
174 std::stringstream ss; 190 std::stringstream ss;
175 ss << std::hex << this; 191 ss << std::hex << this;
176 this_in_hex_ = ss.str(); 192 this_in_hex_ = ss.str();
177 193
(...skipping 5676 matching lines...) Expand 10 before | Expand all | Expand 10 after
5854 5870
5855 uint64_t GLES2Implementation::ShareGroupTracingGUID() const { 5871 uint64_t GLES2Implementation::ShareGroupTracingGUID() const {
5856 return share_group_->TracingGUID(); 5872 return share_group_->TracingGUID();
5857 } 5873 }
5858 5874
5859 void GLES2Implementation::SetErrorMessageCallback( 5875 void GLES2Implementation::SetErrorMessageCallback(
5860 const base::Callback<void(const char*, int32_t)>& callback) { 5876 const base::Callback<void(const char*, int32_t)>& callback) {
5861 error_message_callback_ = callback; 5877 error_message_callback_ = callback;
5862 } 5878 }
5863 5879
5864 void GLES2Implementation::SetClientVisible(int client_id, bool is_visible) { 5880 std::unique_ptr<ContextSupport::ScopedVisibility>
5865 if (is_visible) { 5881 GLES2Implementation::ClientBecameVisible() {
5866 visible_clients_.insert(client_id); 5882 ++num_visible_clients_;
5867 } else { 5883 return base::MakeUnique<ScopedVisibilityImpl>(this);
5868 auto found = visible_clients_.find(client_id); 5884 }
5869 if (found != visible_clients_.end()) 5885
5870 visible_clients_.erase(found); 5886 void GLES2Implementation::ClientBecameNotVisible(
5871 } 5887 std::unique_ptr<ScopedVisibility> visibility) {
5888 DCHECK_GT(num_visible_clients_, 0u);
danakj 2016/08/19 18:29:55 can you DCHECK(visibility) too? (same for the Test
ericrk 2016/08/19 18:49:58 Done.
5889 --num_visible_clients_;
5890 static_cast<ScopedVisibilityImpl*>(visibility.get())->Release(this);
5872 } 5891 }
5873 5892
5874 bool GLES2Implementation::AnyClientsVisible() const { 5893 bool GLES2Implementation::AnyClientsVisible() const {
5875 return !visible_clients_.empty(); 5894 return num_visible_clients_ > 0;
5876 } 5895 }
5877 5896
5878 void GLES2Implementation::SetLostContextCallback( 5897 void GLES2Implementation::SetLostContextCallback(
5879 const base::Closure& callback) { 5898 const base::Closure& callback) {
5880 lost_context_callback_ = callback; 5899 lost_context_callback_ = callback;
5881 } 5900 }
5882 5901
5883 GLuint64 GLES2Implementation::InsertFenceSyncCHROMIUM() { 5902 GLuint64 GLES2Implementation::InsertFenceSyncCHROMIUM() {
5884 const uint64_t release = gpu_control_->GenerateFenceSyncRelease(); 5903 const uint64_t release = gpu_control_->GenerateFenceSyncRelease();
5885 helper_->InsertFenceSyncCHROMIUM(release); 5904 helper_->InsertFenceSyncCHROMIUM(release);
(...skipping 1023 matching lines...) Expand 10 before | Expand all | Expand 10 after
6909 cached_extensions_.clear(); 6928 cached_extensions_.clear();
6910 } 6929 }
6911 6930
6912 // Include the auto-generated part of this file. We split this because it means 6931 // Include the auto-generated part of this file. We split this because it means
6913 // we can easily edit the non-auto generated parts right here in this file 6932 // we can easily edit the non-auto generated parts right here in this file
6914 // instead of having to edit some template or the code generator. 6933 // instead of having to edit some template or the code generator.
6915 #include "gpu/command_buffer/client/gles2_implementation_impl_autogen.h" 6934 #include "gpu/command_buffer/client/gles2_implementation_impl_autogen.h"
6916 6935
6917 } // namespace gles2 6936 } // namespace gles2
6918 } // namespace gpu 6937 } // namespace gpu
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698