blob: 870dc352382069dcd56d7380002646ade620ef4b [file] [log] [blame]
tomhudson@google.com168e6342012-04-18 17:49:20 +00001/*
2 * Copyright 2012 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
Mike Kleinc0bd9f92019-04-23 12:05:21 -05008#include "include/private/SkSpinlock.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -05009#include "src/gpu/GrGeometryProcessor.h"
10#include "src/gpu/GrMemoryPool.h"
11#include "src/gpu/GrProcessor.h"
Brian Salomon201cdbb2019-08-14 17:00:30 -040012#include "src/gpu/GrSamplerState.h"
Greg Danielf91aeb22019-06-18 09:58:02 -040013#include "src/gpu/GrTextureProxy.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050014#include "src/gpu/GrXferProcessor.h"
tomhudson@google.com168e6342012-04-18 17:49:20 +000015
joshualitt23ac62c2015-03-30 09:53:47 -070016// We use a global pool protected by a mutex(spinlock). Chrome may use the same GrContext on
17// different threads. The GrContext is not used concurrently on different threads and there is a
18// memory barrier between accesses of a context on different threads. Also, there may be multiple
bsalomon5baedd62015-03-09 12:15:53 -070019// GrContexts and those contexts may be in use concurrently on different threads.
20namespace {
Leon Scroggins III981a31e2017-10-06 11:53:53 -040021#if !defined(SK_BUILD_FOR_ANDROID_FRAMEWORK)
mtklein15923c92016-02-29 10:14:38 -080022static SkSpinlock gProcessorSpinlock;
Leon Scroggins III981a31e2017-10-06 11:53:53 -040023#endif
bsalomon5baedd62015-03-09 12:15:53 -070024class MemoryPoolAccessor {
tomhudson@google.comdcba4c22012-07-24 21:36:16 +000025public:
tomhudson@google.comdcba4c22012-07-24 21:36:16 +000026
msarett68440f82016-08-29 14:52:24 -070027// We know in the Android framework there is only one GrContext.
28#if defined(SK_BUILD_FOR_ANDROID_FRAMEWORK)
29 MemoryPoolAccessor() {}
30 ~MemoryPoolAccessor() {}
31#else
32 MemoryPoolAccessor() { gProcessorSpinlock.acquire(); }
joshualitt23ac62c2015-03-30 09:53:47 -070033 ~MemoryPoolAccessor() { gProcessorSpinlock.release(); }
msarett68440f82016-08-29 14:52:24 -070034#endif
tomhudson@google.comdcba4c22012-07-24 21:36:16 +000035
bsalomon5baedd62015-03-09 12:15:53 -070036 GrMemoryPool* pool() const {
Brian Salomon6986c652019-12-12 10:58:47 -050037 static GrMemoryPool* gPool = GrMemoryPool::Make(4096, 4096).release();
Brian Osmanfce27ad2019-11-13 14:46:53 -050038 return gPool;
tomhudson@google.comdcba4c22012-07-24 21:36:16 +000039 }
40};
John Stilesa6841be2020-08-06 14:11:56 -040041} // namespace
tomhudson@google.comdcba4c22012-07-24 21:36:16 +000042
bsalomon@google.com0ac6af42013-01-16 15:16:18 +000043///////////////////////////////////////////////////////////////////////////////
44
Brian Salomonab015ef2017-04-04 10:15:51 -040045void* GrProcessor::operator new(size_t size) { return MemoryPoolAccessor().pool()->allocate(size); }
tomhudson@google.com168e6342012-04-18 17:49:20 +000046
Brian Salomonab015ef2017-04-04 10:15:51 -040047void GrProcessor::operator delete(void* target) {
48 return MemoryPoolAccessor().pool()->release(target);
49}