OLD | NEW |
(Empty) | |
| 1 // Copyright 2012 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 #include "cc/resources/resource_helper.h" |
| 6 |
| 7 #include "gpu/GLES2/gl2extchromium.h" |
| 8 #include "gpu/command_buffer/client/gles2_interface.h" |
| 9 #include "third_party/khronos/GLES2/gl2.h" |
| 10 #include "third_party/khronos/GLES2/gl2ext.h" |
| 11 #include "third_party/skia/include/gpu/GrContext.h" |
| 12 |
| 13 using gpu::gles2::GLES2Interface; |
| 14 |
| 15 namespace cc { |
| 16 |
| 17 ResourceHelper::ResourceHelper(OutputSurface* output_surface) |
| 18 : output_surface_(output_surface) { |
| 19 } |
| 20 |
| 21 ResourceHelper::~ResourceHelper() { |
| 22 } |
| 23 |
| 24 ResourceHelper::ScopedGpuRaster::ScopedGpuRaster( |
| 25 ResourceHelper* resource_helper) |
| 26 : resource_helper_(resource_helper) { |
| 27 BeginGpuRaster(); |
| 28 } |
| 29 |
| 30 ResourceHelper::ScopedGpuRaster::~ScopedGpuRaster() { |
| 31 EndGpuRaster(); |
| 32 } |
| 33 |
| 34 void ResourceHelper::Flush() { |
| 35 DCHECK(thread_checker_.CalledOnValidThread()); |
| 36 GLES2Interface* gl = this->ContextGL(); |
| 37 if (gl) |
| 38 gl->Flush(); |
| 39 } |
| 40 |
| 41 void ResourceHelper::Finish() { |
| 42 DCHECK(thread_checker_.CalledOnValidThread()); |
| 43 GLES2Interface* gl = this->ContextGL(); |
| 44 if (gl) |
| 45 gl->Finish(); |
| 46 } |
| 47 |
| 48 bool ResourceHelper::ShallowFlushIfSupported() { |
| 49 DCHECK(thread_checker_.CalledOnValidThread()); |
| 50 GLES2Interface* gl = this->ContextGL(); |
| 51 if (!gl) |
| 52 return false; |
| 53 |
| 54 gl->ShallowFlushCHROMIUM(); |
| 55 return true; |
| 56 } |
| 57 |
| 58 GLint ResourceHelper::GetActiveTextureUnit(GLES2Interface* gl) { |
| 59 GLint active_unit = 0; |
| 60 gl->GetIntegerv(GL_ACTIVE_TEXTURE, &active_unit); |
| 61 return active_unit; |
| 62 } |
| 63 |
| 64 GLES2Interface* ResourceHelper::ContextGL() const { |
| 65 ContextProvider* context_provider = output_surface_->context_provider(); |
| 66 return context_provider ? context_provider->ContextGL() : NULL; |
| 67 } |
| 68 |
| 69 class GrContext* ResourceHelper::GrContext() const { |
| 70 ContextProvider* context_provider = output_surface_->context_provider(); |
| 71 return context_provider ? context_provider->GrContext() : NULL; |
| 72 } |
| 73 |
| 74 void ResourceHelper::ScopedGpuRaster::BeginGpuRaster() { |
| 75 GLES2Interface* gl = resource_helper_->ContextGL(); |
| 76 DCHECK(gl); |
| 77 |
| 78 // TODO(alokp): Use a trace macro to push/pop markers. |
| 79 // Using push/pop functions directly incurs cost to evaluate function |
| 80 // arguments even when tracing is disabled. |
| 81 gl->PushGroupMarkerEXT(0, "GpuRasterization"); |
| 82 |
| 83 class GrContext* gr_context = resource_helper_->GrContext(); |
| 84 if (gr_context) |
| 85 gr_context->resetContext(); |
| 86 } |
| 87 |
| 88 void ResourceHelper::ScopedGpuRaster::EndGpuRaster() { |
| 89 GLES2Interface* gl = resource_helper_->ContextGL(); |
| 90 DCHECK(gl); |
| 91 |
| 92 class GrContext* gr_context = resource_helper_->GrContext(); |
| 93 if (gr_context) |
| 94 gr_context->flush(); |
| 95 |
| 96 // TODO(alokp): Use a trace macro to push/pop markers. |
| 97 // Using push/pop functions directly incurs cost to evaluate function |
| 98 // arguments even when tracing is disabled. |
| 99 gl->PopGroupMarkerEXT(); |
| 100 } |
| 101 |
| 102 } // namespace cc |
OLD | NEW |