Error Stream::createConsumerGLTextureExternal(const AttributeMap &attributes, gl::Context *context) { ASSERT(mState == EGL_STREAM_STATE_CREATED_KHR); ASSERT(mConsumerType == ConsumerType::NoConsumer); ASSERT(mProducerType == ProducerType::NoProducer); ASSERT(context != nullptr); const auto &glState = context->getState(); EGLenum bufferType = attributes.getAsInt(EGL_COLOR_BUFFER_TYPE, EGL_RGB_BUFFER); if (bufferType == EGL_RGB_BUFFER) { mPlanes[0].texture = glState.getTargetTexture(gl::TextureType::External); ASSERT(mPlanes[0].texture != nullptr); mPlanes[0].texture->bindStream(this); mConsumerType = ConsumerType::GLTextureRGB; mPlaneCount = 1; } else { mPlaneCount = attributes.getAsInt(EGL_YUV_NUMBER_OF_PLANES_EXT, 2); ASSERT(mPlaneCount <= 3); for (EGLint i = 0; i < mPlaneCount; i++) { // Fetch all the textures mPlanes[i].textureUnit = attributes.getAsInt(EGL_YUV_PLANE0_TEXTURE_UNIT_NV + i, -1); if (mPlanes[i].textureUnit != EGL_NONE) { mPlanes[i].texture = glState.getSamplerTexture(mPlanes[i].textureUnit, gl::TextureType::External); ASSERT(mPlanes[i].texture != nullptr); } } // Bind them to the stream for (EGLint i = 0; i < mPlaneCount; i++) { if (mPlanes[i].textureUnit != EGL_NONE) { mPlanes[i].texture->bindStream(this); } } mConsumerType = ConsumerType::GLTextureYUV; } mContext = context; mState = EGL_STREAM_STATE_CONNECTING_KHR; return NoError(); }
Stream::Stream(Display *display, const AttributeMap &attribs) : mDisplay(display), mProducerImplementation(nullptr), mState(EGL_STREAM_STATE_CREATED_KHR), mProducerFrame(0), mConsumerFrame(0), mConsumerLatency(attribs.getAsInt(EGL_CONSUMER_LATENCY_USEC_KHR, 0)), mConsumerAcquireTimeout(attribs.getAsInt(EGL_CONSUMER_ACQUIRE_TIMEOUT_USEC_KHR, 0)), mPlaneCount(0), mConsumerType(ConsumerType::NoConsumer), mProducerType(ProducerType::NoProducer) { for (auto &plane : mPlanes) { plane.textureUnit = -1; plane.texture = nullptr; } }