1 /*
2  * Copyright 2017 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 
8 #include "GrContext.h"
9 #include "GrContextPriv.h"
10 #include "GrGpu.h"
11 #include "GrResourceProvider.h"
12 #include "GrSemaphore.h"
13 #include "gl/GrGLTypes.h"
14 
GrGLExternalTextureData(const GrGLTextureInfo & info,sk_sp<GrSemaphore> semaphore,GrContext * context)15 GrGLExternalTextureData::GrGLExternalTextureData(const GrGLTextureInfo& info,
16                                                  sk_sp<GrSemaphore> semaphore,
17                                                  GrContext* context)
18         : fInfo(info)
19         , fSemaphore(std::move(semaphore)) {
20     SkASSERT(fSemaphore->unique());
21     context->resourceProvider()->releaseOwnershipOfSemaphore(fSemaphore);
22 }
23 
attachToContext(GrContext * context)24 void GrGLExternalTextureData::attachToContext(GrContext* context) {
25     context->resourceProvider()->takeOwnershipOfSemaphore(fSemaphore);
26     // Ideally we don't want to get the Gpu off of the context here. However, eventually this
27     // semaphore will live on a GrTexture object and the wait will be called from there. At that
28     // point we can use the GrGpu already stored directly on the GrTexture.
29     context->getGpu()->waitSemaphore(fSemaphore);
30 }
31