1 // Copyright 2018 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef MEDIA_GPU_TEST_FAKE_COMMAND_BUFFER_HELPER_H_ 6 #define MEDIA_GPU_TEST_FAKE_COMMAND_BUFFER_HELPER_H_ 7 8 #include <map> 9 #include <set> 10 11 #include "base/macros.h" 12 #include "base/memory/scoped_refptr.h" 13 #include "base/single_thread_task_runner.h" 14 #include "media/gpu/command_buffer_helper.h" 15 16 namespace media { 17 18 class FakeCommandBufferHelper : public CommandBufferHelper { 19 public: 20 explicit FakeCommandBufferHelper( 21 scoped_refptr<base::SingleThreadTaskRunner> task_runner); 22 23 // Signal stub destruction. All textures will be deleted. Listeners will 24 // be notified that we have a current context unless one calls ContextLost 25 // before this. 26 void StubLost(); 27 28 // Signal context loss. MakeContextCurrent() fails after this. 29 void ContextLost(); 30 31 // Signal that the context is no longer current. 32 void CurrentContextLost(); 33 34 // Complete a pending SyncToken wait. 35 void ReleaseSyncToken(gpu::SyncToken sync_token); 36 37 // Test whether a texture exists (has not been destroyed). 38 bool HasTexture(GLuint service_id); 39 40 // CommandBufferHelper implementation. 41 gl::GLContext* GetGLContext() override; 42 gpu::SharedImageStub* GetSharedImageStub() override; 43 bool HasStub() override; 44 bool MakeContextCurrent() override; 45 std::unique_ptr<gpu::SharedImageRepresentationFactoryRef> Register( 46 std::unique_ptr<gpu::SharedImageBacking> backing) override; 47 gpu::TextureBase* GetTexture(GLuint service_id) const override; 48 GLuint CreateTexture(GLenum target, 49 GLenum internal_format, 50 GLsizei width, 51 GLsizei height, 52 GLenum format, 53 GLenum type) override; 54 void DestroyTexture(GLuint service_id) override; 55 void SetCleared(GLuint service_id) override; 56 bool BindImage(GLuint service_id, 57 gl::GLImage* image, 58 bool client_managed) override; 59 gpu::Mailbox CreateMailbox(GLuint service_id) override; 60 void ProduceTexture(const gpu::Mailbox& mailbox, GLuint service_id) override; 61 void WaitForSyncToken(gpu::SyncToken sync_token, 62 base::OnceClosure done_cb) override; 63 void SetWillDestroyStubCB(WillDestroyStubCB will_destroy_stub_cb) override; 64 bool IsPassthrough() const override; 65 bool SupportsTextureRectangle() const override; 66 67 private: 68 ~FakeCommandBufferHelper() override; 69 70 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; 71 72 bool has_stub_ = true; 73 bool is_context_lost_ = false; 74 bool is_context_current_ = false; 75 76 GLuint next_service_id_ = 1; 77 std::set<GLuint> service_ids_; 78 std::map<gpu::SyncToken, base::OnceClosure> waits_; 79 80 WillDestroyStubCB will_destroy_stub_cb_; 81 82 DISALLOW_COPY_AND_ASSIGN(FakeCommandBufferHelper); 83 }; 84 85 } // namespace media 86 87 #endif // MEDIA_GPU_TEST_FAKE_COMMAND_BUFFER_HELPER_H_ 88