Remove shared_ptr<GpuBuffer> member from GlTextureView
This only exists to support GlTexture's GetFrame API. It can be moved into GlTexture. PiperOrigin-RevId: 488812896
This commit is contained in:
		
							parent
							
								
									767cc2ee3c
								
							
						
					
					
						commit
						1c0a1d0aab
					
				| 
						 | 
					@ -201,9 +201,13 @@ class GlTexture {
 | 
				
			||||||
  void Release() { view_ = std::make_shared<GlTextureView>(); }
 | 
					  void Release() { view_ = std::make_shared<GlTextureView>(); }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 private:
 | 
					 private:
 | 
				
			||||||
  explicit GlTexture(GlTextureView view)
 | 
					  explicit GlTexture(GlTextureView view, GpuBuffer gpu_buffer)
 | 
				
			||||||
      : view_(std::make_shared<GlTextureView>(std::move(view))) {}
 | 
					      : gpu_buffer_(std::move(gpu_buffer)),
 | 
				
			||||||
 | 
					        view_(std::make_shared<GlTextureView>(std::move(view))) {}
 | 
				
			||||||
  friend class GlCalculatorHelperImpl;
 | 
					  friend class GlCalculatorHelperImpl;
 | 
				
			||||||
 | 
					  // We store the GpuBuffer to support GetFrame, and to ensure that the storage
 | 
				
			||||||
 | 
					  // outlives the view.
 | 
				
			||||||
 | 
					  GpuBuffer gpu_buffer_;
 | 
				
			||||||
  std::shared_ptr<GlTextureView> view_;
 | 
					  std::shared_ptr<GlTextureView> view_;
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -101,7 +101,7 @@ GlTexture GlCalculatorHelperImpl::MapGpuBuffer(const GpuBuffer& gpu_buffer,
 | 
				
			||||||
    glBindTexture(view.target(), 0);
 | 
					    glBindTexture(view.target(), 0);
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  return GlTexture(std::move(view));
 | 
					  return GlTexture(std::move(view), gpu_buffer);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
GlTexture GlCalculatorHelperImpl::CreateSourceTexture(
 | 
					GlTexture GlCalculatorHelperImpl::CreateSourceTexture(
 | 
				
			||||||
| 
						 | 
					@ -143,7 +143,7 @@ template <>
 | 
				
			||||||
std::unique_ptr<ImageFrame> GlTexture::GetFrame<ImageFrame>() const {
 | 
					std::unique_ptr<ImageFrame> GlTexture::GetFrame<ImageFrame>() const {
 | 
				
			||||||
  view_->DoneWriting();
 | 
					  view_->DoneWriting();
 | 
				
			||||||
  std::shared_ptr<const ImageFrame> view =
 | 
					  std::shared_ptr<const ImageFrame> view =
 | 
				
			||||||
      view_->gpu_buffer().GetReadView<ImageFrame>();
 | 
					      gpu_buffer_.GetReadView<ImageFrame>();
 | 
				
			||||||
  auto copy = absl::make_unique<ImageFrame>();
 | 
					  auto copy = absl::make_unique<ImageFrame>();
 | 
				
			||||||
  copy->CopyFrom(*view, ImageFrame::kDefaultAlignmentBoundary);
 | 
					  copy->CopyFrom(*view, ImageFrame::kDefaultAlignmentBoundary);
 | 
				
			||||||
  return copy;
 | 
					  return copy;
 | 
				
			||||||
| 
						 | 
					@ -151,17 +151,8 @@ std::unique_ptr<ImageFrame> GlTexture::GetFrame<ImageFrame>() const {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
template <>
 | 
					template <>
 | 
				
			||||||
std::unique_ptr<GpuBuffer> GlTexture::GetFrame<GpuBuffer>() const {
 | 
					std::unique_ptr<GpuBuffer> GlTexture::GetFrame<GpuBuffer>() const {
 | 
				
			||||||
  auto gpu_buffer = view_->gpu_buffer();
 | 
					 | 
				
			||||||
#ifdef __EMSCRIPTEN__
 | 
					 | 
				
			||||||
  // When WebGL is used, the GL context may be spontaneously lost which can
 | 
					 | 
				
			||||||
  // cause GpuBuffer allocations to fail. In that case, return a dummy buffer
 | 
					 | 
				
			||||||
  // to allow processing of the current frame complete.
 | 
					 | 
				
			||||||
  if (!gpu_buffer) {
 | 
					 | 
				
			||||||
    return std::make_unique<GpuBuffer>();
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
#endif  // __EMSCRIPTEN__
 | 
					 | 
				
			||||||
  view_->DoneWriting();
 | 
					  view_->DoneWriting();
 | 
				
			||||||
  return absl::make_unique<GpuBuffer>(gpu_buffer);
 | 
					  return absl::make_unique<GpuBuffer>(gpu_buffer_);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
GlTexture GlCalculatorHelperImpl::CreateDestinationTexture(
 | 
					GlTexture GlCalculatorHelperImpl::CreateDestinationTexture(
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -7,7 +7,6 @@ void GlTextureView::Release() {
 | 
				
			||||||
  if (detach_) detach_(*this);
 | 
					  if (detach_) detach_(*this);
 | 
				
			||||||
  detach_ = nullptr;
 | 
					  detach_ = nullptr;
 | 
				
			||||||
  gl_context_ = nullptr;
 | 
					  gl_context_ = nullptr;
 | 
				
			||||||
  gpu_buffer_ = nullptr;
 | 
					 | 
				
			||||||
  plane_ = 0;
 | 
					  plane_ = 0;
 | 
				
			||||||
  name_ = 0;
 | 
					  name_ = 0;
 | 
				
			||||||
  width_ = 0;
 | 
					  width_ = 0;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -43,7 +43,6 @@ class GlTextureView {
 | 
				
			||||||
    name_ = other.name_;
 | 
					    name_ = other.name_;
 | 
				
			||||||
    width_ = other.width_;
 | 
					    width_ = other.width_;
 | 
				
			||||||
    height_ = other.height_;
 | 
					    height_ = other.height_;
 | 
				
			||||||
    gpu_buffer_ = std::move(other.gpu_buffer_);
 | 
					 | 
				
			||||||
    plane_ = other.plane_;
 | 
					    plane_ = other.plane_;
 | 
				
			||||||
    detach_ = std::exchange(other.detach_, nullptr);
 | 
					    detach_ = std::exchange(other.detach_, nullptr);
 | 
				
			||||||
    done_writing_ = std::exchange(other.done_writing_, nullptr);
 | 
					    done_writing_ = std::exchange(other.done_writing_, nullptr);
 | 
				
			||||||
| 
						 | 
					@ -55,7 +54,6 @@ class GlTextureView {
 | 
				
			||||||
  int height() const { return height_; }
 | 
					  int height() const { return height_; }
 | 
				
			||||||
  GLenum target() const { return target_; }
 | 
					  GLenum target() const { return target_; }
 | 
				
			||||||
  GLuint name() const { return name_; }
 | 
					  GLuint name() const { return name_; }
 | 
				
			||||||
  const GpuBuffer& gpu_buffer() const { return *gpu_buffer_; }
 | 
					 | 
				
			||||||
  int plane() const { return plane_; }
 | 
					  int plane() const { return plane_; }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  using DetachFn = std::function<void(GlTextureView&)>;
 | 
					  using DetachFn = std::function<void(GlTextureView&)>;
 | 
				
			||||||
| 
						 | 
					@ -74,7 +72,6 @@ class GlTextureView {
 | 
				
			||||||
        name_(name),
 | 
					        name_(name),
 | 
				
			||||||
        width_(width),
 | 
					        width_(width),
 | 
				
			||||||
        height_(height),
 | 
					        height_(height),
 | 
				
			||||||
        gpu_buffer_(std::move(gpu_buffer)),
 | 
					 | 
				
			||||||
        plane_(plane),
 | 
					        plane_(plane),
 | 
				
			||||||
        detach_(std::move(detach)),
 | 
					        detach_(std::move(detach)),
 | 
				
			||||||
        done_writing_(std::move(done_writing)) {}
 | 
					        done_writing_(std::move(done_writing)) {}
 | 
				
			||||||
| 
						 | 
					@ -93,7 +90,6 @@ class GlTextureView {
 | 
				
			||||||
  // Note: when scale is not 1, we still give the nominal size of the image.
 | 
					  // Note: when scale is not 1, we still give the nominal size of the image.
 | 
				
			||||||
  int width_ = 0;
 | 
					  int width_ = 0;
 | 
				
			||||||
  int height_ = 0;
 | 
					  int height_ = 0;
 | 
				
			||||||
  std::shared_ptr<GpuBuffer> gpu_buffer_;  // using shared_ptr temporarily
 | 
					 | 
				
			||||||
  int plane_ = 0;
 | 
					  int plane_ = 0;
 | 
				
			||||||
  DetachFn detach_;
 | 
					  DetachFn detach_;
 | 
				
			||||||
  mutable DoneWritingFn done_writing_;
 | 
					  mutable DoneWritingFn done_writing_;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue
	
	Block a user